Вы находитесь на странице: 1из 9

HOMEWORK NO:3

Part-A
1. Does the Sequence <23,17,14,6,13,10,1,5,7,12> represents a Max Heap?
ANS1) Yes , the Sequence <23,17,14,6,13,10,1,5,7,12> represents a Max Heap, because
according to structure property of heap , this sequence is having all levels filled and last node is
having only

2. Which of the Operations on BST are more complex and why?


Give suitable Example.

Ans2) While deleting an element say n from binary tree three cases are concerned

(a) When n has no child

(b) When n has 1 child

(c) When n has 2 child

In 3rd case n has two children . let s(n) denote the inorder successor of n .then n is deleted from t by
first deleting s(n) from t and then replacing node n in t by the node s(n).

Out if these 3 , third case is the most complex operation in binary search tree. In all three cases the
memory space of the deleted node n is returned to the AVAIL list.

Remove 12 from a BST.


Find minimum element in the right subtree of the node to be removed. In current example it is 19

Replace 12 with 19. Notice, that only values are replaced, not nodes. Now we have two nodes with
the same value

Remove 19 from the left subtree.


3. When we insert a new node in a binary search tree, will it become an internal node or
terminal node? Explain your answer with example.

ANS 3) When we insert a new node in a binary search tree, it becomes a terminal node everytime
insertion is done, the newly inserted node is inserted as a leaf node. Eg. Insertion of new element
18 in bst.

Binary Tree After Adding Node 18

Part-B

4. For a binary tree T, the Pre-Order and In-Order traversal sequences are as

Follows:-

Pre-Order: A B L M K N P Q

In-Order: L B M A N K Q P

Draw the Binary Tree.

ANS4) given , Pre-Order : A B L M K N P Q


In-Order : L B M A N K Q P

The binary search tree is :

5. For a binary tree T, the Pre-Order and In-Order traversal sequences are as

Follows:-

Pre-Order: A B E H Q R C D K L M

In-Order: B Q R H E A D L K M C

(a) What is the height of the tree?


(b) What are the internal nodes?
(c) What is its Post-Order traversal sequence?

ANS 5) given , Pre-Order: A B E H Q R C D K L M


In-Order: B Q R H E A D L K M C

The binary search tree is :

(a) The height of tree is 6

(b) The internal nodes are B ,C ,E ,D ,H ,K ,Q ,L ,M.

(c) The post order transversal is : B ,Q ,R ,H ,E ,D ,L ,M ,K ,C ,A .

6. The Sequence <70,15,50,5,12,35,10> represents a Max Heap. Show the

Following operations:

(a) Insertion of element 25


(b) Deletion from Root
(c) Insertion of element 75
Also give the number of exchanges performed n each case.

ANS 6) Given Sequence is : <70,15,50,5,12,35,10>

(a) Insertion of element 25 :


After heap sort : the element 25 goes in its new place.

(b) Deletion from the root : the deletion is done from the root , for that replace the last entered
element with the node root and reheap the heap to get the exact postion of node.
(c)

After reheaping :

(d) Insertion of element 75 :


After heap sort :

7. Suppose a binary tree is in memory:-

INFO LEFT RIGHT

1 H 4 11

2 R 0 0
3 17

4 P 0 0

5 B 18 7

6 3

7 E 1 0

8 6

9 C 0 10

10 F 15 16

11 Q 0 12

12 S 0 0

13 0

14 A 5 9

15 K 2 0

16 L 0 0

17 13

18 D 0 0

Draw the Binary Tree. if the root of the tree is 14.

ANS 7) the given root of the binary tree is 14 :

Вам также может понравиться