Draw the Binary Search Tree (BST) we would get if we were to insert the letters
C O M P U T E R S in the order listed (i.e., C is the first letter added to the tree).
Wait… didn’t we do this last week??? Yes… but now we’re working in the opposite direction.
Now consider the following function:
def traverse(container, root):
result = ""
next_node = container.get()
if(next_node is not None):
result += next_node.data
What is the result of calling print(traverse(my container, my root)) when my root is the root node of the tree you made, and my container is:
- A stack
- A queue
- An alternating queue
- A neck queue
- A steue
If you are unsure how any of the containers above work, you can ask a TA during practicals, or ask on
Piazza. Make sure you understand the ADT before you start working.
You can trace the code by hand, but we recommend actually implementing each container and running it, then you can just copy/paste the output.
You must submit a file called ex4.txt with what would be printed for each of the containers listed above, in order, one container per line. For example, your file might look something like (once again, the format is correct, the answers are not):
COMPUTERS SRETUPMOC COMPSRETU RETUSPCUP PROCTORUS