Ds Tut Sheet
Ds Tut Sheet
Ds Tut Sheet
BIT Mesra
Tutorial Sheet
Module – I
1. How can you define algorithms? Discuss structure and properties of algorithms.
2. Define and Classify data structures.
3. How does one measure the efficiency of algorithms?
4. Distinguish between best, worst and average case complexities of an algorithm.
5. Define O, Ω and Θ notations of time complexity.
6. Compare and contrast exponential time complexity with polynomial time complexity.
7. How are recursive programs analyzed?
8. Analyze the time complexity of the following program:
for send = 1 to n do
for receive = 1 to send do
for ack = 2 to receive do
Message = send – (receive + ack);
end
end
end
9. Solve the recurrence relation:
= a, if n = 1
Module – II
10. Distinguish between row major and column major ordering of an array.
11. For an n-dimensional array [1 : u1, 1: u2, … 1 : un] obtain the address of the element A[i1, i2,
i3, … in] given β to be the home address.
12. Declare a one, two and a three-dimensional array in a programming language ( C/C++)
which has the capability to display the addresses of array elements. Verify the various
address calculation formulae for any arbitrary element of these arrays.
13. Open an ordered list L[d1, d2, … dn] where each di is the name of a peripheral device, which
is maintained in the alphabetical order. Write a program to
a. Insert a device dk onto the list L.
b. Delete an existing device di from L. In this case the new ordered list should be
Lnew = (d1, d2, … di-1, di+1, … dn) with (n – 1) elements.
c. Find the length of L.
d. Update the device dj to dk and print the new list.
14. How are insert operations carried out in a stack?
15. What are demerits of a linear stack?
16. If a stack S[1 : N] were to be implemented with the bottom of the stack at S[N], write a
procedure to undertake push and pop operations on S.
17. For the following logical expression
( a and b and c) or d or e or (not h)
(i) Obtain the equivalent postfix expression.
(ii) Evaluate the postfix expression for a = true, b = false, c = true, d = true, e = true, h =
false.
18. Implement a stack S of n elements using arrays. Write functions to perform PUSH and POP
operations. Implement queries using push and pop functions to
a. Retrieve the mth element of the stack S from the top (m < n), leaving the stack without its
top m – 1 elements.
b. Retain only the elements in the odd position of the stack and pop out all even
positioned elements.
19. Write a recursive program to obtain the nth order Fibonacci sequence number. Include
appropriate input/output statements to track the variables participating in recursion.
20. Implement a program to evaluate any given postfix expression. Test your program for the
evaluation of the equivalent postfix form of the expression ( - (A*B)/D) ↑ C + E – F * H * I
for A = 1, B = 2, D = 3, C = 14, E = 110, F = 220, H = 16.78, I = 364.621.
21. What are the disadvantages of the linear queues? How do circular queues help overcome the
disadvantages of linear queues?
22. If FRONT and REAR were pointers to the physical front and rear of a linear queue, comment
on the condition, FRONT = REAR.
23. How priority queues are implemented using a single queue?
24. Write a program to maintain a list of items as a circular queue which is implemented using an
array. Simulate insertions and deletions to the queue and display the content of the queue
after every operation.
25. Let PQUE be a priority queue data structure and , be n elements with
priorities pi ( 0 ≤ pi ≤ m – 1). Implement PQUE as a two dimensional array ARR_PQUE[1:m,
1:d] where m is the number of priority values and d is the maximum number of data items
with a given priority. Execute insertions and deletions presented in a random sequence.
26. Implement a deque DQUE in a one dimensional array.
Module – III
Module – IV
47. Sketch (i) an array representation and (ii) a linked representation for the binary tree shown in
figure 1.
4 9
5 7
Fig. 1
48. Sketch a linked representation for a threaded binary tree equivalent of the binary tree shown
in fig. 1.
49. Obtain inorder and post order traversals for the binary tree shown in fig. 1.
50. Draw an expression tree for the following logical expression: p and (q or not k) and (s or b or
h)
51. Given the following inorder and preorder traversals, trace the binary tree.
Inorder traversal: B F G H P R S T W Y Z Preorder traversal: P F B H G S R Y T W Z.
52. Write a program to implement a binary tree using linked representation. Use functions to
traverse it in inorder, preorder and post order.
53. Write a recursive function to count the number of nodes in a binary tree.
54. Write non-recursive functions to perform inorder, preorder and post order traversals of a
binary tree.
55. How is binary search tree representation of lists advantageous over their sequential list
representations?
56. How is the deletion of a node that has both left and right subtrees, undertaken in a binary
search tree?
57. What is the need for an AVL Tree?
58. How is the rotation free deletion of a node having both the subtrees, done in an AVL search
tree?
59. For the data list { AND, BEGIN, CASE, DO , END , FOR, GOTO, IF, IN, LET, NOT, OR,
QUIT, READ, REPEAT, RESET, THEN, UNTIL, WHILE, XOR}
a. Construct a binary search tree. What are your observations?
b. Construct an AVL search tree.
60. What are the merits of m-way search trees over AVL search trees?
61. What are the demerits of m-way search trees?
62. What is the need for B trees?
63. What is the height of a B tree of order m?
64. Insert the following elements in the order given into an empty B tree of order (i) 3 (ii) 4 and
(iii) 7: Z R T A D F H Q W C V B S E O P L J K M N U T X.
Undertake the following operations on the B trees: (i) delete Q (ii) delete A (iii) delete M
65. For the data list given in Question 63, construct a 3-way search tree. Insert G and delete J K
and Z from the search tree.
Module – VI
Module – VII
72. What are the advantages of binary search over sequential search?
73. When is a transpose sequential search said to be most successful?
74. What is the principle behind interpolation search?
75. For the following search list undertake (i) linear ordered search (ii) binary search in the data
list given. Tabulate the number of comparisons made for each key in the search list.
Search list: {766, 009, 999, 238}
Data list: {111, 453, 231, 112, 679, 238, 876, 655, 766, 877, 988, 009, 122, 233, 344, 566}
76. For the given data list and search list, tabulate the number of comparisons made when (i) a
transpose sequential search and (ii) interpolation search is undertaken on the keys belonging
to the search list.
Data list: {pin, ink, pen, clip, ribbon, eraser, duster, chalk, pencil, paper, stapler, pot, scale,
calculator}
Search list: {pen, clip, paper, pin, calculator}
------
•
Edited and Compiled By – D. K. Mallick, Course Coordinator.