Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
I am new to teaching the particular syllabus I have been asked to teach and I am confused by the approach given for several of the algorithms. For example the stack implementation based on the course materials given below seems very convoluted. I'm curious to hear if others would share my concerns if they had to teach about stacks in this way, or if they can offer any insight into the advantages of this approach.
The concerns I have which I'm curious to hear your opinion about are:
Using the call by reference approach makes the push and pop calls very unwieldy
It looks like new items are added to the end of the list, making the algorithm O(n) rather than O(1)
The algorithm is hard to follow (IMO)
It is possible to implement a stack in a much simpler fashion, which would allow student to focus more on conceptual understanding of the behavior and use of stacks, and to see the link between the concept and the implementation more clearly.
# NullPointer should be set to -1 if using array element with index 0
NULLPOINTER =-1#Declare record type to store data and pointerclassNode:def __init__(self):
self.Data=""
self.Pointer= NULLPOINTER
defInitialiseStack():Stack=[Node()for i in range(8)]TopOfStack= NULLPOINTER # set start pointerFreeListPtr=0# set starting position of free istforIndexin range(7):Stack[Index].Pointer=Index+1Stack[7].Pointer= NULLPOINTER # last node of free listreturn(Stack,TopOfStack,FreeListPtr)defPush(Stack,TopOfStack,FreeListPtr,NewItem):ifFreeListPtr!= NULLPOINTER:# there is space in the array# take node from free list and store data itemNewNodePtr=FreeListPtrStack[NewNodePtr].Data=NewItemFreeListPtr=Stack[FreeListPtr].Pointer# insert new node at top of stackStack[NewNodePtr].Pointer=TopOfStackTopOfStack=NewNodePtrelse:print("no space for more data")return(Stack,TopOfStack,FreeListPtr)defPop(Stack,TopOfStack,FreeListPtr):ifTopOfStack== NULLPOINTER:print("no data on stack")Value=""else:Value=Stack[TopOfStack].DataThisNodePtr=TopOfStackTopOfStack=Stack[TopOfStack].PointerStack[ThisNodePtr].Pointer=FreeListPtrFreeListPtr=ThisNodePtrreturn(Stack,TopOfStack,FreeListPtr,Value)defOutputAllNodes(Stack,TopOfStack):CurrentNodePtr=TopOfStack# start at beginning of listifTopOfStack==
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that
you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice
sessions to improve your knowledge and scores.
manpreet
Best Answer
2 years ago
I am new to teaching the particular syllabus I have been asked to teach and I am confused by the approach given for several of the algorithms. For example the stack implementation based on the course materials given below seems very convoluted. I'm curious to hear if others would share my concerns if they had to teach about stacks in this way, or if they can offer any insight into the advantages of this approach.
The concerns I have which I'm curious to hear your opinion about are:
Using the call by reference approach makes the
push
andpop
calls very unwieldyIt looks like new items are added to the end of the list, making the algorithm O(n) rather than O(1)
The algorithm is hard to follow (IMO)
It is possible to implement a stack in a much simpler fashion, which would allow student to focus more on conceptual understanding of the behavior and use of stacks, and to see the link between the concept and the implementation more clearly.