Assignment-2 DSA
Assignment-2 DSA
06320802821
ECE-B
Q1) The following list of numbers is inserted into an empty binary search tree (BST): 45, 32, 90,
34, 68, 72, 15, 24, 30, 66, 11, 50, 10.
(a) Construct the Binary Search Tree (BST):
A BST is constructed by inserting nodes based on the rule:
Smaller values go to the left of the parent.
Larger values go to the right of the parent.
Resulting Tree Structure:
45
/ \
32 90
/ \ /
15 34 68
/ \ / \
11 24 50 72
/ \
10 30
\
66
(b) Find the Inorder, Preorder, and Postorder Traversals of the BST:
Inorder (Left, Root, Right): 10, 11, 15, 24, 30, 32, 34, 45, 50, 66, 68, 72, 90
Preorder (Root, Left, Right): 45, 32, 15, 11, 10, 24, 30, 34, 90, 68, 50, 66, 72
Postorder (Left, Right, Root): 10, 11, 30, 24, 15, 34, 32, 66, 50, 72, 68, 90, 45
Q2) Find the depth of a complete tree if the number of nodes is 1,000,000.
Formula for depth of a complete binary tree: Depth=⌈log2(Number of nodes)⌉
log2(1,000,000)≈19.93, so rounding up gives a depth of 20.
Q4) Construct a Max Heap from the following keys: 11, 6, 2, 3, 8, 10, 13.
Steps to Construct the Max Heap:
1. Insert keys one by one while maintaining the max-heap property.
2. At each step, compare the inserted key with its parent and swap if necessary.
Resulting Max Heap:
13
/ \
11 10
/ \ / \
3 8 2 6