Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exam paper of Data structure, Exams of Data Structures and Algorithms

This is practice paper of data structure and algorithm. It is very helpful to solve different problems

Typology: Exams

2019/2020

Uploaded on 11/07/2020

modi-ketul-1
modi-ketul-1 🇮🇳

4.7

(3)

12 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
IT205 Roll No. 201901
IT205: Data Structures
Examination-2
Max. 80 points Max. 120 minutes
This booklet has 12 pages. Ensure that you have all the pages.
Write your roll number on all the pages.
Write your answer(s) only in the space provided on this booklet.
You can earn up to 20 points per question. You can score up to 80 (= 4 ×5) points.
No clarification will be provided during the examination.
Rough sheets will be provided which have to be submitted. However, the rough sheets will not
be used for evaluation and will be discarded.
The exam is open book and open notes; no exchanging, lending or borrowing during the exam.
For evaluators’ use:
Question 1 2 3 4 Total
Points
06 March, 2020 Page 1 of 12
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Exam paper of Data structure and more Exams Data Structures and Algorithms in PDF only on Docsity!

IT205: Data Structures

Examination-

Max. 80 points Max. 120 minutes

  • This booklet has 12 pages. Ensure that you have all the pages.
  • Write your roll number on all the pages.
  • Write your answer(s) only in the space provided on this booklet.
  • You can earn up to 20 points per question. You can score up to 80 (= 4 × 5) points.
  • No clarification will be provided during the examination.
  • Rough sheets will be provided which have to be submitted. However, the rough sheets will not be used for evaluation and will be discarded.
  • The exam is open book and open notes; no exchanging, lending or borrowing during the exam.

For evaluators’ use:

Question 1 2 3 4 Total

Points

  1. Definition: A binary tree is said to be height balanced if at each node x of the tree,

|height(lef tsubtree(x)) − height(rightsubtree(x))| ≤ 1.

Using { 1 , 2 ,... , 9 } as keys,

(a) draw a binary tree on nine nodes which is neither a BST nor is height balanced.

Solution:

(b) draw a height balanced binary tree on nine nodes which is not a BST.

Solution:

  1. Definition: In a binary tree, the neighbours of a given node are its parent, left-child and right-child. Definition: For a node x in a BST, it’s successor is y if inorder−number(y) = inorder−number(x)+
    1. [Note: In a BST, inorder − number(u) = rank(u) for every node u.] (a) Consider the following binary search tree (keys not included). ~

~ ~

~ ~ ~

~ ~





H HH HHH

@

@@

@

@@



 



For the binary search tree shown in the picture, state how many of the tree edges represent a link between an element and its successor (in either direction: parent is successor of child or child is successor of parent). You may assume the keys are all distinct.

Solution:

(b) Consider a binary search tree on eight nodes with distinct keys. For the type of edges defined in part (a): i. What is the maximum possible number of such edges? Describe a tree structure achieving this maximum.

Solution: The maximum possible number of such edges in a BST on eight nodes with distinct keys is. A tree structure achieving this maximum is:

ii. What is the minimum possible number of such edges? Describe a tree structure achieving this minimum.

Solution: The minimum possible number of such edges in a BST on eight nodes with distinct keys is. A tree structure achieving this minimum is:

(c) In a binary search tree with distinct keys, a node x is the successor of its neighbouring node in the tree if and only if one of the following two conditions hold: (Fill in each blank with an appropriate choice from among “left-child”, “right-child”, “parent”.)

  • x is the of its and it doesn’t have

a. OR

  • x has a which doesnt have a.

(d) Combine your responses to part (c) and the standard recursive programming constructs to write a pseudocode to compute the number of such edges in an input binary search tree. Your code can take as input a tree and its root, but should not read key values. It should be based on the tree structure, as calculated in part (c). Write down the running time of your routine, as a function of the number of nodes n, using θ notation.

Solution:

  1. Consider the following BST. 5 m

@ m @ 2

@ @

6 m @ m @ 1 4 m

10 m m 3 8 m

@ m @ 7 9 m

(a) Push the keys of the BST into a stack S with the order for insertion being the level-order traversal of the BST. Construct/draw a BST from the keys popped out of the stack S.

Solution: The contents of the stack S when the insertions are completed is as follows: Bottom Top

The BST from the keys popped out of S is:

(b) Push the keys of the BST into a stack S with the order for insertion being the pre-order traversal of the BST. Construct/draw a BST from the keys popped out of the stack S.

Solution: The contents of the stack S when the insertions are completed is as follows: Bottom Top

The BST from the keys popped out of S is:

(c) Push the keys of the BST into a stack S with the order for insertion being the post-order traversal of the BST. Construct/draw a BST from the keys popped out of the stack S.

Solution: The contents of the stack S when the insertions are completed is as follows: Bottom Top

The BST from the keys popped out of S is:

(d) Push the keys of the BST into a stack S with the order for insertion being the in-order traversal of the BST. Construct/draw a BST from the keys popped out of the stack S.

Solution: The contents of the stack S when the insertions are completed is as follows: Bottom Top

The BST from the keys popped out of S is:

while (Residue 6 = 0) do

T otal ← 0

while (T otal < Residue) do

T emp ← DEQU EU E(Qf eed) T otal ← T otal + 2T emp EN QU EU E(Qshunt, T emp)

end while

if (T otal = Residue) then

while (Qshunt 6 = ∅) do EN QU EU E(Qf reeze, DEQU EU E(Qshunt)) end while

while (Qf eed 6 = ∅) do EN QU EU E(Qreject, DEQU EU E(Qf eed)) end while

Residue ← 0

return Qf reeze

else

Residue ← Residue − 2 T emp

while (Qf eed 6 = ∅) do EN QU EU E(Qreject, DEQU EU E(Qf eed)) end while

while (|Qshunt| > 1) do EN QU EU E(Qf eed, DEQU EU E(Qshunt)) end while

EN QU EU E(Qf reeze, DEQU EU E(Qshunt))

end if

end while

while (Qf eed 6 = ∅) do EN QU EU E(Qreject, DEQU EU E(Qf eed)) end while

(a) When the procedure terminates, what will be the contents of Qf reeze for the following values of the input? [Write the contents of the queue in order starting from the front and moving up to the rear.] i. n = 50

Solution:

ii. n = 63

Solution:

iii. n = 89

Solution:

iv. n = 128

Solution:

(b) When the procedure terminates, what will be the contents of Qreject for the following values of the input? [Write the contents of the queue in order starting from the front and moving up to the rear.] i. n = 50

Solution:

ii. n = 63

Solution: