I am working on my practice final for a data structures class, and I have a few questions I was hoping to get help with:
-
void BST::traverse(Vertex *V) // post order traversal recursively { if (V != NULL) { traverse(V->Left); traverse(V->Right); cout << V->elem << endl; } }I need to change this to depth-first search. I believe I have to re-visit the root each recursion to do so, but am confused because then I’d never leave the root. Perhaps a temporary root? Not sure!
-
For our linked list implementation, I have to describe 2 occasions when our copy constructor is used. I know it is called for function calls. But what’s another reason?
-
why do we use big O notation [e.g. O(n^2) instead of saying 2n^2 + 3n + 4). I know we ignore constants when doing so, but is there more to the answer I can give?
-
Time vs. Space complexities. The most obvious to me is merge sort vs. quick sort, but can you think of another one in case the test asks for more? We went over so many in class that I can’t believe I can’t name more.
It’s already a depth-first search if you just add the search code to it.
You already have the occasion when a
BSTis passed by value to a function as an argument. What is another time that you make a copy of an object? (Hint: one is also related to functions)Because when
nis large, 2n will be much much much larger than anything else in the equation so you just leave constants and everything else out. Big-O notation is definitely not meant to be precise, it’s only to let you know how a solution to a problem scales as the input grows very large. Whenngets large enough, the complexity is so huge that the other stuff is dwarfed and it’s basically 2n.You’ll have to be more specific for this one. Are you looking for two algorithms that trade speed for space?