DS-Question Bank
DS-Question Bank
Unit5: Tree
2 Marks
90. Define complete binary tree with example. Draw an example.
91. What is a binary tree?
92. Define depth and height of a tree.
93. Construct a max-heap for the following values:14,28,34,10,60
94. Define heap.
95. Differentiate between binary tree and complete binary tree.
96. Define max-heap and min-heap.
97. Define level of a tree.
98. Define tree. What is a binary search tree?
99. Define degree of a node and degree of a tree.
5Marks
100. Construct a binary tree from the following pre-order and in-order traversal.
Inorder: D B E A F C G
PreOrder: A B D E C F G
Generate Post Order traversal of the same.
101. Explain the array representation and linked list representation of binary with
an example.
102. Construct a binary tree from the following pre-order and in-order traversal.
Inorder: E D U C A T I O N
PreOrder: C D E U I T A N O
Generate Post Order traversal of the same
103. Show the step by step construction of a BST for the following data.
[50, 23, 94, 85, 63, 42, 17, 11, 19, 76]
10 Marks
104. What is a binary search tree? Construct a binary search tree for the following
elements:
{ 12, 45, 23, 43, 10, 6, 11 }
Write a C program to create a binary tree and display the same using any one of the
tree traversal techniques.
105. A. Construct a max heap for the following elements [23, 44, 67, 89, 34, 12, 9,
94]
B. Write a recursive C function to display the inorder traversal of a binary tree.
C. Show the step by step construction of a BST for the following data.
[46,35,12,67,42,53,72,8]
106. Explain all three traversal of binary tree with an algorithm and an example.
107. What is a binary search tree? Construct a binary search tree for the following
elements:
[98, 53, 135, 32, 71, 18, 9, 24, 65, 88]
Also write the steps for inorder, preorder and postorder traversal for the above drawn
tree.
Dynamic memory allocation and pointers
1. Differentiate between * and & operators.
2. If m and n are declared as integers and p1 and p2 are pointers to integers, then find
out the error if any, in the following.
a. p1=&m;
b. P2=n;
c. *p1=&n;
3. What is dynamic memory allocation? What are the advantages of dynamic memory
allocation over static memory allocation?
4. Give an example for accessing a variable through its pointer variable.
5. Explain the following functions
a. malloc()
b. calloc()
c. delete()
d. realloc()
e. free()
6. What is a pointer variable? What is the size of the pointer variable of different data
types?
7. What is a void pointer?
8. How do you initialize a pointer?
9. How memory can be deallocated?
10. Write the differences between static and dynamic memory allocation.
11. List the application of pointers.
12. Explain how array elements are accessed using pointers in one dimensional array.
13. List the advantages of pointers.
14. What is a pointer to pointer?
15. Explain how pointers are passed in function call with an example.
16. What is a heap?
17. What is garbage collection?
18. List the advantage of dynamic memory allocation.
19. What is a dangling pointer? Explain with an example.
20. What are the common errors that could occur during dynamic memory allocation?
21. Differentiate between static variables and dynamic variables.
Recursion
1. What data structure is used for performing recursion?
2. Mention the advantages of using recursive function.
3. Mention the disadvantages of using recursive function.
4. When is a recursive function said to be well defined?
5. Explain Towers of Hanoi problem as an example for recursion. Give the solution for
disks.
6. Write a recursive program to find the product of two numbers.
7. Explain the types of recursion.
8. Write a recursive program to find the sum of first n natural numbers.
9. Write a recursive program to print numbers 1 to n in descending order using
recursion.
10. Write a recursive function to find the sum of first n natural numbers.
11. Define recursion.
12. Write a c program to find the binomial coefficient using recursion.
13. Write a c program to find the GCD of any given two numbers using recursion.
Illustrate with an example.
14. Write a c program to find the factorial of a number using recursion.
15. Write a c program to generate the Fibonacci series using recursion.
16. Write a recursive program to reverse a string.
17. Write a recursive program to find the length of a given stirng?
18. explain how power(x,n) can be found.
19. Write a C program to print numbers 1 to n in descending order using recursion.
20. Explain the towers of Hanoi problem.
21. What is the output of the following recursive function?
Int function(int x)
{
a. If(x<3)
i. return (1);
b. else
i. return(function(x-
1)+function(x-2)); } main()
{
c. int I,n=5;
d. for(i=1;i<=n;i++)
i. printf(“\n%d”,functio
n(i)); }
22. Explain the difference between iterative and recursive methods.
A+B*C+D
a. (A + B) * (C + D)
b. A * B + C * D
c. A + B + C + D
d. A/B^C-D
e. (d-e)/(p+q)2
f. ((p+q)*(a-n))/((t-r)+(b-u)3)
24. Convert A * (B + C) * D to postfix notation. Show the state of the stack.
25. Convert A+(B*C-(D/E-F)*G)*H to postfix notation. Show the state of the stack
26. Evaluate the post fix expression 2 3 4 + * 5 *
27. Write an algorithm to convert an infix expression to postfix expression. Trace the
algorithm to indicate the content of stack for the expression (a-b)/(c-d)+e.
Linked Lists
1. Write an algorithm to create a singly linked list.
2. Mention the disadvantages of static memory allocation.
3. What are the disadvantages of linked list?
4. Explain the components of a linked list with a diagram.
5. How is linked list represented in memory?
6. What are the advantages and disadvantages of singly linked list.
7. What is a header node? Explain.
8. Compare singly and doubly linked list.
9. What is a circular linked list?write one advantage and disadvantage of circular
linked list.
10. What is garbage collection?
11. What is the difference between linked list and an array?
12. Write an algorithm to insert a node after a node in a linked list.
13. Write an algorithm to delete a node from a linked list.
14. Write an algorithm to count the number of nodes in a linked list.
15. Write an algorithm to count the number of nodes in a circular linked list.
16. What is a linked list? What are the advantages of linked list over array?
17. Write an algorithm to implement a stack using linked list.
18. Write a C program to implement a queue using linked list.
19. What is the advantage of singly linked list over a doubly linked list?
20. What is the disadvantage of singly linked list over a doubly linked list?
21. Explain the concept of doubly linked list.
22. Explain how a node is created in a linked list.
23. Explain the various types of linked list.
24. Explain how the elements in a linked list can be displayed.
25. Explain how an element can be searched in a sorted linked list.
26. Explain how an element can be searched in a unsorted linked list.
27. Explain how a node can be inserted at the beginning of a linked list with an
algorithm.
28. Explain the insertion of a node at a particular position in a linked list.
29. Explain the deletion of anode from the beginning of the list, from a particular
position.
Trees