DS Questions SET 1
DS Questions SET 1
DS Questions SET 1
TREE:
1. Define Tree. Explain with example.
2. What is binary tree? Prove that the maximum no of nodes in a binary tree of height
h is 2 h+1 -1.
3. What is a full binary tree and a complete binary tree? Prove that a full binary tree
with n leaves contains (2n -1 ) nodes.
4. How do we represent a binary tree in memory?
5. Write a C function to insert a node in binary search tree.
6. Write function to delete a node from a binary search tree.
7. Write recursive function for in-order, preorder and post order traversal of a binary
tree.
8. Write non recursive algorithm for pre-order traversal of a binary tree.
9. Write non recursive algorithm for in-order traversal of a binary tree.
10. Write non recursive algorithm for post-order traversal of a binary tree.
11. What is binary search tree? If we delete a node from a BST and then insert the
node again in the BST, is the resulting BST necessarily the same as before? Justify
your answer with a suitable example.
12. What is threaded binary tree?
13. Given the pre-order and in-order traversal of a binary tree, draw the tree and write
its post-order traversal:
Pre-order: A B D E F C G H J L K
In-order: D B F E A G C L J H K
14. Construct an expression tree for the expression E= (2x + y )* (5a - b) 3
15. Insert the following key into a B-Tree of order 3
p, q, r, d, h,m,l,s,k,n
16. What are AVL trees? Illustrate with a suitable example.
17. The following keys are to be inserted in the order shown below into an AVL tree,
5, 45, 50, 65, 75, 85.
18. Insert the following keys in the order given below to build an AVL tree
g, h, s, l, e, m, t,u
Clearly mention different rotations used and balance factor of each node.
19.i) Draw the AVL tree after performing each of the following operations
consecutively on an initially empty binary search tree :
a) Insert 8.
b) Insert 6
c) Insert 12
d) Insert 3
e) Insert 10
f) Insert 9
g) Delete 12
h) Delete 8
i) Insert 7
j) Insert 8
ii) If you delete an item from an AVL tree and then insert it back into the tree, will
you always get back the original tree? Justify your answer.
20. Create B-Tree of order 5 from the following lists of data items:
16, 20, 22, 42, 12, 30, 32, 18, 10, 34, 36, 38, 14, 24, 28, 40,26.
21. How an AVL tree differs from a binary search tree?
22. What do you mean by B-tree and what are the uses of such a tree in data
structure?
23. Show how the following numbers can be inserted in an empty Binary search tree
in the order they are given :
50, 30, 10, 90, 100, 40, 60, 20, 110, 5
23. Discuss how to insert an element in an AVL tree.
24. Construct a binary search tree with the help of following inorder and post order
traversal:
Post-order : B, C, A, P, N, T, L, K, G, F, P
In-order : A, B, C,D,F, G, K,L, N,P,T
25. Prove that, for any non empty binary tree T, if p be the no of leaves and q be the
no of nodes of degree 2 ,then p = q +1.
26. What is 2-way threading?
27. Is it possible to represent a binary tree using array ? if yes, how?
28. What are expression trees? Represent the following expression using a tree.
Comment on the result that you get when this tree is traversed in Preorder,
In-order and post-order. (a-b) / ((c*d)+e)
29. Draw the expression tree of the following infix expression. Convert it in to
Prefix and Postfix expressions.
a+b*c – d/e
30. Create a heap with following list of keys:
8, 20, 9, 4, 15, 10, 7, 22, 3, 12
31. What is a Binary Tree? What is the maximum number of nodes possible in a
Binary Tree of depth d. Explain the following terms with respect to Binary
trees
(i) Strictly Binary Tree (ii) Complete Binary Tree (iii) Almost
Complete Binary Tree
32. What are B-trees? Draw a B-tree of order 3 for the following sequence of
keys. 3,5,11,10,9,8,2,6,12
33. Sort the following list using Heap Sort technique, displaying each step.
20, 12, 25 6, 10, 15, 13
34. What are the two phases in heap sort algorithm? Sort the following data
using heap sort and show all the intermediate steps.
88, 12, 91, 23, 10, 36, 45, 55, 15, 39, 81
35. What are the properties of a heap? Distinguish between a max heap and a min
heap.
36. Transform the array 2 8 6 1 10 15 3 12 11 into a heap with a bottom up method
37. Show the result of inserting the keys 4,19, 17, 11, 3, 12, 8, 20, 22, 23, 13, 18, 14,
16, 1, 2, 24, 25, 26, 5 in order in to an empty B-Tree of degree 3. Only draw the
configurations of the tree just before some node must split, and also draw the final
configuration.
37. Show a tree (of more than one node) for which the preorder and inorder traversals
generate the same sequence. Is this possible for preorder and post order traversals? If
it is, show an example.
38. Construct an expression tree for the expression A+(B-C)*D+(E*F)
39. Write a program in C to create an empty binary search tree & search for an
Element X in it.
40. Define M-way trees. Build a B-tree of order 4 by inserting data in the sequence
given below: 92, 24, 6, 7, 11, 8, 22, 4, 5, 16, 19, 20, 78
41. Create a binary search tree for the following numbers start from an empty binary
search tree. 45,26,10,60,70,30,40 Delete keys 10,60 and 45 one after the other and
show the trees at each stage.
42. How to insert and delete an element into a binary search tree and write down the
code for the insertion routine with an example.
43.What are threaded binary tree? Write an algorithm for inserting a node in a
threaded binary tree