Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
In a Max-Heap, what is the relationship between the value of a node and its children?
Not quite. Try another option.
Answer: The node is greater than or equal to its children
In a Max-Heap, the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursively true for all sub-trees.
Question 2 of 50
Which data structure is commonly used to implement a Heap efficiently?
Not quite. Try another option.
Answer: Array
Heaps are usually implemented using arrays because they are complete binary trees. The parent-child relationship can be easily calculated using indices.
Question 3 of 50
If a node is stored at index 'i' in an array representation of a binary heap (0-indexed), what is the index of its left child?
Not quite. Try another option.
Answer: 2i + 1
In a 0-indexed array representing a binary heap, the left child of a node at index 'i' is located at index '2i + 1'.
Question 4 of 50
What is the time complexity to insert a new element into a binary heap of size N?
Not quite. Try another option.
Answer: O(log N)
Insertion involves adding the element to the end and then 'bubbling up' (percolating) to restore the heap property, which takes time proportional to the height of the tree, O(log N).
Question 5 of 50
What is the time complexity to find the maximum element in a Max-Heap?
Not quite. Try another option.
Answer: O(1)
In a Max-Heap, the maximum element is always at the root, which can be accessed in constant time O(1).
Question 6 of 50
Which operation is required to restore the heap property after extracting the root element?
Not quite. Try another option.
Answer: Heapify (Percolate Down)
After removing the root, the last element is moved to the root, and the 'Heapify' or 'Percolate Down' process is used to move it down to its correct position.
Question 7 of 50
A binary heap is strictly a __.
Not quite. Try another option.
Answer: Complete Binary Tree
A binary heap must be a complete binary tree, meaning all levels are fully filled except possibly the last, which is filled from left to right.
Question 8 of 50
What is the parent index of a node at index 'i' in a 0-indexed array heap?
Not quite. Try another option.
Answer: (i - 1) / 2
The parent of a node at index 'i' is located at floor((i - 1) / 2).
Question 9 of 50
What is the worst-case time complexity of HeapSort?
Not quite. Try another option.
Answer: O(N log N)
HeapSort involves building the heap (O(N)) and then extracting elements N times (each taking O(log N)), resulting in a total complexity of O(N log N).
Question 10 of 50
HeapSort is generally considered stable. True or False?
Not quite. Try another option.
Answer: False
HeapSort is not a stable sort because the structure of the heap changes the relative order of equal elements during the heapify process.
Question 11 of 50
Which of the following scenarios is the best use case for a Heap?
Not quite. Try another option.
Answer: Implementing a Priority Queue
Heaps are ideal for Priority Queues because they efficiently support Insert and Extract-Min/Max operations.
Question 12 of 50
What is the time complexity to build a heap from an unsorted array of N elements?
Not quite. Try another option.
Answer: O(N)
While naive insertion takes O(N log N), the optimized 'build heap' algorithm (starting from the last non-leaf node) takes linear time O(N).
Question 13 of 50
In HeapSort, where is the sorted array constructed?
Not quite. Try another option.
Answer: In-place within the same array
HeapSort is an in-place algorithm. It swaps the root with the last element and reduces the heap size effectively building the sorted sequence at the end of the array.
Question 14 of 50
What is the height of a binary heap with N nodes?
Not quite. Try another option.
Answer: O(log N)
Since a binary heap is a complete binary tree, its height is bounded by log2(N).
Question 15 of 50
Which hashing technique allows multiple keys to be stored in the same slot using a data structure like a linked list?
Not quite. Try another option.
Answer: Separate Chaining
Separate Chaining uses a linked list (or another structure) at each bucket to store all keys that hash to the same index.
Question 16 of 50
What is a 'Collision' in hashing?
Not quite. Try another option.
Answer: When two different keys hash to the same index
A collision occurs when a hash function maps two distinct keys to the same location (index) in the hash table.
Question 17 of 50
In the context of hash tables, what is the Load Factor (alpha)?
Not quite. Try another option.
Answer: Number of elements / Number of buckets
The load factor is the ratio of the number of elements stored (n) to the total number of buckets/slots (m) in the hash table.
Question 18 of 50
Which simple hash function is defined as h(k) = k mod m?
Not quite. Try another option.
Answer: Division Method
The division method maps a key 'k' into one of 'm' slots by taking the remainder of k divided by m.
Question 19 of 50
In Open Addressing, where are colliding elements stored?
Not quite. Try another option.
Answer: In the same hash table at a different slot
Open addressing (Closed Hashing) stores all elements within the hash table array itself, searching for the next available slot upon collision.
Question 20 of 50
What is the probe sequence for Linear Probing?
Not quite. Try another option.
Answer: (h(k) + i) % m
Linear probing looks for the next available slot sequentially: index, index+1, index+2, etc., wrapping around modulo m.
Question 21 of 50
What is the main disadvantage of Linear Probing?
Not quite. Try another option.
Answer: Primary Clustering
Linear probing suffers from primary clustering, where long runs of occupied slots build up, increasing the average search time.
Question 22 of 50
Quadratic Probing reduces primary clustering but suffers from which issue?
Not quite. Try another option.
Answer: Secondary Clustering
Quadratic probing resolves primary clustering but causes secondary clustering, where keys hashing to the same initial position follow the exact same probe sequence.
Question 23 of 50
Which collision resolution technique uses a second hash function?
Not quite. Try another option.
Answer: Double Hashing
Double hashing uses a second hash function h2(k) to determine the step size when a collision occurs: (h1(k) + i * h2(k)) % m.
Question 24 of 50
In Double Hashing, what property must the second hash function h2(k) have?
Not quite. Try another option.
Answer: It should never evaluate to 0
If h2(k) evaluates to 0, the probe sequence will not advance (step size 0), causing an infinite loop on the same index.
Question 25 of 50
Which hashing method allows the load factor to exceed 1?
Not quite. Try another option.
Answer: Separate Chaining
In Separate Chaining, because elements are stored in external lists, the number of elements can exceed the number of table slots.
Question 26 of 50
What is the worst-case search time in a Hash Table using Separate Chaining?
Not quite. Try another option.
Answer: O(N)
In the worst case, all keys hash to the same slot, creating a linked list of length N. Searching becomes O(N).
Question 27 of 50
What is the average-case search time for a well-implemented hash table?
Not quite. Try another option.
Answer: O(1)
With a good hash function and reasonable load factor, the average search time is constant, O(1).
Question 28 of 50
What technique is used to handle deletions in Open Addressing tables?
Not quite. Try another option.
Answer: Lazy deletion (Tombstones)
Simply removing an element breaks the probe chain. Usually, deleted slots are marked with a specific flag (Tombstone) to allow searches to continue past them.
Question 29 of 50
When choosing a table size 'm' for the Division Method (h(k) = k % m), 'm' should preferably be:
Not quite. Try another option.
Answer: A prime number
Using a prime number helps distribute keys more uniformly and reduces clustering, especially if keys have patterns (like arithmetic progressions).
Question 30 of 50
In the Mid-Square method of hashing, which part of the squared key is usually taken as the hash?
Not quite. Try another option.
Answer: The middle digits
The middle digits of the squared value depend on all bits of the original key, providing a good distribution.
Question 31 of 50
What happens when the load factor of a hash table becomes too high?
Not quite. Try another option.
Answer: Collisions increase and performance degrades
A high load factor means the table is filling up, leading to more collisions and longer probe sequences or longer chains, slowing down operations.
Question 32 of 50
The process of increasing the size of a hash table and re-inserting all existing elements is called:
Not quite. Try another option.
Answer: Rehashing
Rehashing involves creating a larger table and calculating new hash positions for all existing elements to maintain the load factor.
Question 33 of 50
Which probing method uses the formula H(k, i) = (h(k) + c1i + c2i^2) % m?
Not quite. Try another option.
Answer: Quadratic Probing
This formula represents Quadratic Probing, where the step size increases quadratically.
Question 34 of 50
What is 'Perfect Hashing'?
Not quite. Try another option.
Answer: A technique with no collisions
Perfect hashing maps a static set of keys to a hash table with no collisions.
Question 35 of 50
If we have a Max-Heap array: [100, 80, 90, 40, 50, 70], what is the left child of 80?
Not quite. Try another option.
Answer: 40
80 is at index 1. Left child is at 2(1)+1 = 3. The element at index 3 is 40.
Question 36 of 50
In a Min-Heap, the root node always contains:
Not quite. Try another option.
Answer: The minimum value
By definition of a Min-Heap, the root is the smallest element.
Question 37 of 50
Which of the following is NOT a requirement for a good hash function?
Not quite. Try another option.
Answer: It must be cryptographically secure
For standard data structures, cryptographic security is not required; speed and uniform distribution are the primary concerns.
Question 38 of 50
In Open Hashing (Separate Chaining), if the table size is 10 and we insert 20 elements, the load factor is:
Not quite. Try another option.
Answer: 2.0
Load Factor = Elements / Slots = 20 / 10 = 2.0.
Question 39 of 50
What is the relationship between Open Hashing and Closed Addressing?
Not quite. Try another option.
Answer: Open Hashing is Separate Chaining; Closed Addressing is Open Addressing
Open Hashing refers to chaining (elements stored outside the table slots). Closed Hashing refers to Open Addressing (elements stored inside table slots).
Question 40 of 50
In Linear Probing, search for a key stops when:
Not quite. Try another option.
Answer: All of the above
Search stops on finding the key, hitting an empty slot (implying key not found), or traversing the whole table.
Question 41 of 50
Which operation is typically faster in a Hash Table compared to a Binary Search Tree (BST)?
Not quite. Try another option.
Answer: Exact match search
Exact match search is O(1) on average in a Hash Table, while it is O(log N) in a balanced BST.
Question 42 of 50
When performing HeapSort on an array in ascending order, which type of heap is typically used?
Not quite. Try another option.
Answer: Max-Heap
A Max-Heap is used. The largest element (root) is swapped to the end of the array, and the heap size is reduced.
Question 43 of 50
In the folding method of hashing, the key is:
Not quite. Try another option.
Answer: Partitioned into parts and added together
The folding method involves splitting the key into parts and adding them (sometimes with shifting) to generate the hash.
Question 44 of 50
What is the primary benefit of Double Hashing over Quadratic Probing?
Not quite. Try another option.
Answer: No secondary clustering
Double hashing uses a second hash function dependent on the key, so keys mapping to the same initial slot have different probe sequences, eliminating secondary clustering.
Question 45 of 50
If a hash table using Open Addressing is full, what is the time complexity to insert a new item?
Not quite. Try another option.
Answer: Infinite loop (until resized or error)
If the table is completely full in open addressing, the probe sequence will cycle indefinitely (or stop after checking N slots), requiring a resize or error handling.
Question 46 of 50
For string keys, a common hashing approach involves:
Not quite. Try another option.
Answer: Using a polynomial rolling hash
Simple addition causes many collisions (anagrams). A polynomial rolling hash (using a multiplier like 31 or 33) preserves order information.
Question 47 of 50
Which heap operation decreases the value of a key and restores the heap property?
Not quite. Try another option.
Answer: Decrease-Key
Decrease-Key updates a value to be smaller. In a Min-Heap, this might require bubbling up; in a Max-Heap, it might require percolating down.
Question 48 of 50
In a hash table with size m = 10 and hash function h(k) = k % 10, where does key 23 go?
Not quite. Try another option.
Answer: 3
23 % 10 = 3.
Question 49 of 50
Using Linear Probing with h(k) = k % 10, if slots 2 and 3 are occupied, where does key 12 go?
Not quite. Try another option.
Answer: 4
12 % 10 = 2. Slot 2 is full -> try 3. Slot 3 is full -> try 4. 4 is the insertion point.
Question 50 of 50
What is the space complexity of a binary heap?
Not quite. Try another option.
Answer: O(N)
A binary heap stores N elements typically in an array, requiring linear space O(N).
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of CSE205 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of CSE205 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.