Tree basic algo questions list: Set - 1



Instead of having separate post for each question, somehow it made sense to put all the basic questions here in one question section.

1. Write a program / pseudo-code to find the depth or height of a tree.
2. Write a program / pseudo-code to determine the number of elements (or size) in a tree.
3. Write a program / pseudo-code to delete a tree (i.e, free up its nodes)
4. Write program / pseudo-code to determine if two trees are identical .
5. Write a program / pseudo-code to find the mininum value in a binary search tree.
6. Write a program / pseudo-code to compute the maximum depth in a tree?
7. Write a program / pseudo-code to create a mirror copy of a tree (left nodes become right and right nodes become left)!
8. Write program / pseudo-code to return a pointer to the nth node of an inorder traversal of a BST.
9. Write program / pseudo-code to implement the preorder(), inorder() and postorder() traversals. Whats their time complexities?
10. Write a program / pseudo-code to create a copy of a tree.
11. Write program / pseudo-code to check if a given binary tree is a binary search tree or not?
12. Write program / pseudo-code to implement level order traversal of a tree.
13. Write a program / pseudo-code to delete a node from a Binary Search Tree?
14. Write program / pseudo-code to search for a value in a binary search tree (BST).
15. Write program / pseudo-code to count the number of leaves in a tree.
16. Write program / pseudo-code for iterative preorder, inorder and postorder tree traversals
17. Can you construct a tree using postorder and preorder traversal?
18. Construct a tree given its inorder and preorder traversal strings. Similarly construct a tree given its inorder and post order traversal strings.
19. Find the closest ancestor of two nodes in a tree.
20. Given an expression tree, evaluate the expression and obtain a paranthesized form of the expression.
21. How do you convert a tree into an array? What is an AVL tree?
22. How many different trees can be constructed using n nodes?
23. A full N-ary tree has M non-leaf nodes, how many leaf nodes does it have?
24. Implement Breadth First Search (BFS) and Depth First Search (DFS) Updated!
25. Write pseudocode to add a new node to a Binary Search Tree (BST) Updated!
26. What is a threaded binary tree?
This should act as a checklist. I will add individual post for each of the questions and link them here.
(For responding with answers, please do mention the question no for reference here.)

0 comments:

Post a Comment