NPTEL Data Structure and Algorithms using Java Week 7 Assignment Answers 2024
1. When searching for an element in a Binary Search Tree (BST), which of the following statements is true?
a. The search operation always visits every node in the tree.
b. The search operation in a BST can be performed in O(log n) time complexity in the average case.
c. The search operation in a BST starts from the leftmost node.
d. The search operation in a BST always takes O(n) time complexity.
Answer :- For Answers Click Here
2. Given the following Binary Search Tree (BST):
If a pre-order traversal is performed on the BST, what is the sequence of nodes visited immediately after visiting node 10 and before visiting node 20?
a. 5, 12, 13
b. 12, 5, 13
c. 5, 13, 12
d. 13, 12, 5
Answer :- For Answers Click Here
3. Which of the following statements about AVL trees is true?
a. AVL trees are unbalanced binary search trees.
b. AVL trees guarantee O(log n) time complexity for both insertion and deletion operations.
c. AVL trees allow any arbitrary rotation during balancing.
d. AVL trees prioritize space efficiency over time efficiency.
Answer :- For Answers Click Here
4. What is the balance factor of a node in an AVL tree?
a. The height difference between the left and right subtrees.
b. The total number of nodes in the left subtree minus the total number of nodes in the right subtree.
c. The depth of the node in the tree.
d. The difference in the number of children between the left and right subtrees.
Answer :-
5. If a new node with the value 17 is inserted into the BST, which nodes will be visited in the process?
a. 15, 10
b. 15, 20, 18
c. 15, 20, 25
d. 15, 10, 12
Answer :-
6. Consider a binary max heap data structure. If the highest value in the heap is removed, which of the following options best describes the subsequent action that must be taken to maintain the max heap property?
a. The last element in the heap is moved to the root, and a heapify operation is performed starting from the root.
b. The heap is rebuilt from scratch starting with the second highest value as the new root.
c. The root is left empty, and a heapify operation is performed starting from the last leaf node.
d. No action is needed as the heap will automatically maintain the max heap property after the removal.
Answer :- For Answers Click Here
7. Which of the following arrays represents a valid Min-Heap?
a. [2, 3, 4, 5, 10, 7, 8]
b. [5, 3, 8, 10, 12, 9, 15]
c. [1, 4, 7, 6, 9, 8, 3]
d. [10, 20, 40, 70, 50, 60, 30]
Answer :-
8. Consider the following AVL tree:
Which node in the given AVL tree is unbalanced, violating the AVL balance property?
a. Node with value 15
b. Node with value 10
c. Node with value 12
d. Node with value 8
Answer :-
9. You are given the following set of integers: {40, 15, 20, 30, 10, 5}. Construct a Max-Heap by inserting the integers in the given order. What will be the root of the resulting Max-Heap?
a. 5
b. 10
c. 30
d. 40
Answer :-
10. Given a Max-Heap with n elements, what is the time complexity of the following operations?
- Building a Max-Heap from an unsorted array of n elements
- Inserting an element
- Deleting the maximum element (root)
a. Inserting: O(log n), Deleting max: O(log n), Building: O(n log n)
b. Inserting: O(log n), Deleting max: O(log n), Building: O(n)
c. Inserting: O(1), Deleting max: O(log n), Building: O(n log n)
d. Inserting: O(log n), Deleting max: O(1), Building: O(n)
Answer :- For Answers Click Here