Amazon Interview Question
Software Engineer / DevelopersI think that they are looking for in-order as opposed to post-order. Something like this:
void printInOrder(Nameval *nvp) {
if (nvp == NULL) return;
printInOrder(nvp->left);
printf("nvp = %p, name = %s, val = %d\n", nvp, nvp->name, nvp->val);
printInOrder(nvp->right);
}
Convert BT in to singly or doubly Linked list it will take O(N) time & O(1) Time
sort linked list it will take O(nlogn) time & O(1) space & coding this is not typical task...:)
Correct me if i am wrong
Shashank
convert Binary Tree to BST -> do inorder traversal.
better than creating a heap i guess
complexity O(n log(n)) depends on how balance your BST is though.
something like heapsort or what?
- arpit June 20, 2011