1Which property is always satisfied by a binary heap?
Introduction to heaps
Easy
A.It is a complete binary tree
B.It is always a binary search tree
C.It contains exactly two children per node
D.It stores data only in sorted order
Correct Answer: It is a complete binary tree
Explanation:
A binary heap is a complete binary tree that also follows a heap-order property.
Incorrect! Try again.
2In a max-heap, where is the largest element located?
Introduction to heaps
Easy
A.In the left subtree
B.In the right subtree
C.At the last leaf
D.At the root
Correct Answer: At the root
Explanation:
In a max-heap, every parent is greater than or equal to its children, so the largest element is at the root.
Incorrect! Try again.
3Where is a new element first placed when it is inserted into a binary heap?
Heap insertion
Easy
A.At the leftmost internal node
B.At the next available leaf position
C.Directly above the root
D.At a randomly selected position
Correct Answer: At the next available leaf position
Explanation:
The new element is placed at the next available position to preserve the complete-tree structure.
Incorrect! Try again.
4What operation restores heap order after inserting an element?
Heap insertion
Easy
A.Reversing the entire array
B.Removing the root element
C.Sorting all elements again
D.Sifting the element upward
Correct Answer: Sifting the element upward
Explanation:
After insertion, the new element may be greater than its parent in a max-heap or smaller than its parent in a min-heap, so it moves upward.
Incorrect! Try again.
5Which element is usually removed in a standard binary heap deletion?
Heap deletion
Easy
A.The root element
B.The leftmost leaf
C.The smallest leaf
D.The deepest internal node
Correct Answer: The root element
Explanation:
The root is removed because it contains the maximum value in a max-heap or the minimum value in a min-heap.
Incorrect! Try again.
6After deleting the root, which element commonly replaces it?
Heap deletion
Easy
A.The last element
B.The second element
C.A newly generated element
D.The leftmost leaf
Correct Answer: The last element
Explanation:
The last element is moved to the root to preserve the complete-tree structure, and heap order is then restored.
Incorrect! Try again.
7Which data structure is used as the main basis of heap sort?
Heap sort
Easy
A.A binary heap
B.A hash table
C.A linked list
D.A graph
Correct Answer: A binary heap
Explanation:
Heap sort repeatedly uses a binary heap to select elements in the required order.
Incorrect! Try again.
8What is the usual time complexity of heap sort?
Heap sort
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Building and repeatedly adjusting the heap results in an overall time complexity of .
Incorrect! Try again.
9What is the main purpose of hashing?
Introduction to hashing
Easy
A.To locate data quickly
B.To connect nodes in a graph
C.To arrange data alphabetically
D.To compress every file
Correct Answer: To locate data quickly
Explanation:
Hashing uses a key to compute a position where the related data can be stored or found.
Incorrect! Try again.
10What is a collision in hashing?
Introduction to hashing
Easy
A.Two keys map to one position
B.Two tables have different sizes
C.A table contains no empty positions
D.A key is larger than the table
Correct Answer: Two keys map to one position
Explanation:
A collision occurs when different keys produce the same hash-table index.
Incorrect! Try again.
11What does a hash function return for a given key?
Hash functions
Easy
A.A memory address only
B.A table index
C.A sorted list
D.A tree height
Correct Answer: A table index
Explanation:
A hash function converts a key into an index used to access a hash table.
Incorrect! Try again.
12Which operation is commonly used in a simple hash function for integer keys?
Hash functions
Easy
A.The factorial operation
B.The square-root operation
C.The comparison operation
D.The modulo operation
Correct Answer: The modulo operation
Explanation:
The modulo operation, such as , commonly produces a valid table index.
Incorrect! Try again.
13A hash table stores data using which type of access?
Hash tables
Easy
A.Position-only access
B.Key-based access
C.Sequential-only access
D.Depth-based access
Correct Answer: Key-based access
Explanation:
A key is passed to a hash function to determine where the associated value is stored.
Incorrect! Try again.
14Which collision-resolution method is generally associated with open hashing?
Open hashing
Easy
A.Double hashing
B.Quadratic probing
C.Separate chaining
D.Linear probing
Correct Answer: Separate chaining
Explanation:
Open hashing commonly handles collisions by storing multiple entries in a chain at the same table index.
Incorrect! Try again.
15In separate chaining, collided entries are usually stored in what structure?
Separate chaining
Easy
A.A linked list
B.A circular queue
C.A separate matrix
D.A binary heap
Correct Answer: A linked list
Explanation:
Each table position can point to a linked list containing entries that hash to that position.
Incorrect! Try again.
16Which technique is commonly used in closed hashing?
Closed hashing
Easy
A.Tree traversal
B.Open addressing
C.External sorting
D.Separate chaining
Correct Answer: Open addressing
Explanation:
Closed hashing stores all entries within the hash table and commonly resolves collisions using open addressing.
Incorrect! Try again.
17In open addressing, where is a collided key placed?
Open addressing
Easy
A.A linked list outside the table
B.The root of a heap
C.A separate database file
D.Another table position
Correct Answer: Another table position
Explanation:
Open addressing searches for another available position within the hash table.
Incorrect! Try again.
18How does linear probing search for an empty position?
Linear probing
Easy
A.It checks only the first position
B.It checks random positions
C.It checks consecutive positions
D.It checks linked-list nodes
Correct Answer: It checks consecutive positions
Explanation:
Linear probing examines positions one after another, usually using a fixed step of one.
Incorrect! Try again.
19What type of sequence is used by quadratic probing?
Quadratic probing
Easy
A.A sequence of linked nodes
B.A sequence based on sorted keys
C.A sequence based on squared steps
D.A sequence of consecutive steps
Correct Answer: A sequence based on squared steps
Explanation:
Quadratic probing uses offsets such as , , and to find another table position.
Incorrect! Try again.
20How does double hashing determine the next position after a collision?
Double hashing
Easy
A.It uses a second hash function
B.It uses the table midpoint
C.It uses a linked-list pointer
D.It uses the previous key
Correct Answer: It uses a second hash function
Explanation:
Double hashing uses a second hash function to calculate the step size for probing.
Incorrect! Try again.
21A binary max-heap is stored in a zero-indexed array. If an element is at index , what are the indices of its children?
Introduction to heaps
Medium
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
In a zero-indexed heap, the children of index are at and . For , they are and .
Incorrect! Try again.
22The array represents a max-heap. What is the array after inserting ?
Heap insertion
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The new value is appended and compared with its parent. Since , the values swap, but , so no further swap is needed.
Incorrect! Try again.
23The array represents a min-heap. Which array results after inserting ?
Heap insertion
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
After being appended, swaps with its parent . It then stops because its new parent, , is smaller.
Incorrect! Try again.
24The array represents a max-heap. What is the heap after deleting the maximum element?
Heap deletion
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The root is replaced by . It is then swapped with the larger child, , restoring the max-heap property.
Incorrect! Try again.
25A min-heap is represented by . Which array results after deleting the root?
Heap deletion
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The last element, , replaces the root and then swaps with the smaller child, . The resulting array satisfies the min-heap property.
Incorrect! Try again.
26Heap sort builds a max-heap from and repeatedly moves the root to the end. What is the final array?
Heap sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Repeatedly moving the maximum element to the end of the array produces ascending order: .
Incorrect! Try again.
27Which statement correctly describes the worst-case performance and stability of standard in-place heap sort?
Heap sort
Medium
A.It runs in time and is stable.
B.It runs in time and is not stable.
C.It runs in time and is not stable.
D.It runs in time because the heap is constructed in linear time and no additional ordering work is needed.
Correct Answer: It runs in time and is not stable.
Explanation:
Heap construction takes , while repeated deletions take overall. Swaps can change the relative order of equal elements, so heap sort is not stable.
Incorrect! Try again.
28Two different keys are mapped to the same table index by a hash function. What has occurred?
Introduction to hashing
Medium
A.A heap violation
B.A hash collision
C.A table overflow
D.A key inversion
Correct Answer: A hash collision
Explanation:
A collision occurs when distinct keys produce the same hash table index. A collision-resolution method is then required.
Incorrect! Try again.
29For the hash function , which statement is true for the keys , , , and ?
Hash functions
Medium
A.Only and collide.
B.Both and collide.
C.All four keys map to one index.
D.Only and collide.
Correct Answer: Both and collide.
Explanation:
, while . Thus, both pairs collide.
Incorrect! Try again.
30A program stores sequential employee IDs in a hash table. Which property is most important when selecting a hash function?
Hash functions
Medium
A.It should distribute IDs uniformly across the table.
B.It should map larger IDs only to larger indices.
C.It should always use the first digit of each ID.
D.It should preserve the numerical ordering of all employee IDs when assigning table positions.
Correct Answer: It should distribute IDs uniformly across the table.
Explanation:
Uniform distribution reduces collisions and prevents clusters, improving expected insertion, search, and deletion performance.
Incorrect! Try again.
31A hash table has buckets and currently stores keys. What is its load factor?
Hash tables
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The load factor is , where is the number of keys and is the number of buckets.
Incorrect! Try again.
32An open-hashing table uses and inserts colliding keys at the front of each chain. After inserting in that order, how many key comparisons are needed to find in bucket ?
Open hashing
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The chain is . Finding requires comparisons with , , and .
Incorrect! Try again.
33A separate-chaining table of size uses and appends keys to each chain. After inserting , which chains are correct?
Separate chaining
Medium
A.Bucket : ; bucket :
B.Bucket : ; bucket :
C.Bucket : ; bucket :
D.Bucket : ; bucket :
Correct Answer: Bucket : ; bucket :
Explanation:
and map to bucket , while and map to bucket . Appending preserves their insertion order.
Incorrect! Try again.
34A closed-hashing table has slots, of which contain active keys and none contain deleted markers. Which statement is correct?
Closed hashing
Medium
A.Its load factor is , and two slots are empty.
B.Its load factor is , and eight slots are empty.
C.Its load factor is , and two slots are empty.
D.Its load factor is , and additional keys can be inserted indefinitely without resizing because collisions reuse occupied slots.
Correct Answer: Its load factor is , and two slots are empty.
Explanation:
The load factor is . Since eight of the ten slots are occupied, two slots remain empty.
Incorrect! Try again.
35Why is a deleted slot usually marked with a tombstone instead of being made immediately empty in an open-addressing table?
Open addressing
Medium
A.To ensure every unsuccessful search scans the entire table before reporting that the key is absent
B.To reduce the physical size of the table
C.To guarantee that future insertions avoid the slot
D.To preserve probe sequences used by later keys
Correct Answer: To preserve probe sequences used by later keys
Explanation:
Making the slot empty could stop a search too early. A tombstone allows searches to continue while still permitting later reuse of the slot.
Incorrect! Try again.
36A table of size uses with linear probing. Slots , , and are occupied. At which index will key be inserted?
Linear probing
Medium
A.Index
B.Index
C.Index
D.Index
Correct Answer: Index
Explanation:
initially maps to index . Linear probing checks , , and then , so the key is inserted at index .
Incorrect! Try again.
37A linear-probing table contains a long consecutive block of occupied slots. Which effect is most likely as more colliding keys are inserted?
Linear probing
Medium
A.Keys in the cluster are redistributed uniformly whenever a new colliding key reaches the occupied block.
Linear probing tends to create contiguous clusters. New keys that reach a cluster extend it, increasing the number of probes required.
Incorrect! Try again.
38A hash table of size uses quadratic probing with , starting at . If , what are the first four indices examined?
Quadratic probing
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
For , the indices are , , , and .
Incorrect! Try again.
39A table of size uses the probe formula . If , why might insertion fail even when some slots are empty?
Quadratic probing
Medium
A.Quadratic probing never checks the original hash index.
B.Every collision permanently reserves two additional empty slots, eventually preventing insertion despite available capacity.
C.The probe sequence can cycle through only a subset of slots.
D.The formula changes the table size after every collision.
Correct Answer: The probe sequence can cycle through only a subset of slots.
Explanation:
The sequence begins , so it repeatedly visits only a few slots and can miss other empty positions.
Incorrect! Try again.
40A table of size uses and . Using , what are the first four indices examined for ?
Double hashing
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
For , and . The first indices are , giving .
Incorrect! Try again.
41A complete -ary heap contains elements stored in a zero-indexed array. Children of index occupy indices through . What is the index of the first leaf?
Introduction to heaps
Hard
A.26
B.25
C.20
D.24
Correct Answer: 25
Explanation:
The last internal node is at index . Therefore, the first leaf is at index .
Incorrect! Try again.
42The array represents a max heap. What is the array after inserting ?
Heap insertion
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The new key is appended, swapped with , and then swapped with . It stops below .
Incorrect! Try again.
43A max heap is stored as . After one delete-max operation using the standard replacement-and-sift-down procedure, which array remains?
Heap deletion
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The last key replaces , then swaps with and subsequently with .
Incorrect! Try again.
44An arbitrary element is removed from a valid binary min heap, and the last element is moved into the vacated position. Which repair rule is correct?
Heap deletion
Hard
A.Perform both upward and downward sifts because either direction may remain invalid afterward
B.Always sift upward because the replacement originated at a lower heap level
C.Sift upward if it is smaller than its parent; otherwise sift it downward if it exceeds a child
D.Always sift downward because deletion can only create violations with children
Correct Answer: Sift upward if it is smaller than its parent; otherwise sift it downward if it exceeds a child
Explanation:
A replacement smaller than its parent creates an upward violation. Otherwise, only a violation with one of its children can require downward movement.
Incorrect! Try again.
45Heap sort begins with the max heap . What is the complete array after exactly two maximum extractions, including the sorted suffix?
Heap sort
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
After the first extraction, is fixed at the end. The second extraction fixes before it, while the remaining prefix is restored to a max heap.
Incorrect! Try again.
46To find the largest elements of an unsorted array of elements without fully sorting it, an algorithm maintains a min heap of size at most . What are its worst-case time and auxiliary-space complexities?
Introduction to heaps
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
Each candidate is compared with the heap minimum, and at most replacements cost each. The heap stores at most elements.
Incorrect! Try again.
47A hash function is chosen from a universal family mapping distinct keys into slots. What is the maximum expected number of colliding unordered key pairs guaranteed by universality?
Introduction to hashing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each pair collides with probability at most . Thus the expected number is at most .
Incorrect! Try again.
48Every key in a data set has the form , and a table has slots. Which replacement for is guaranteed to preserve the collision among all these keys?
Hash functions
Hard
A.A universal hash modulo a prime above the key range
B.A multiplication hash using an irrational constant
C.Any hash function depending only on
D.A randomized tabulation hash over all key bits
Correct Answer: Any hash function depending only on
Explanation:
All keys have the same residue modulo . A function using only that residue receives identical input for every key.
Incorrect! Try again.
49A hash table doubles its capacity whenever an insertion would make the load factor exceed . Rehashing existing entries costs . Under uniform hashing, what is the amortized expected cost per insertion over a long sequence?
Hash tables
Hard
A. because collisions grow with the load factor
B. because each resize doubles the capacity
C. because resize costs form a geometric series
D. because some insertions trigger complete rehashing
Correct Answer: because resize costs form a geometric series
Explanation:
Although an individual resize is linear, capacities grow geometrically. The total rehashing work over insertions is .
Incorrect! Try again.
50One hundred keys are independently hashed uniformly into buckets using open hashing. What is the expected number of empty buckets?
Open hashing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A particular bucket is empty with probability . Linearity of expectation multiplies this probability by buckets.
Incorrect! Try again.
51A separate-chaining table has chain lengths . Assuming each stored key is equally likely to be searched and keys are examined sequentially within a chain, what is the expected number of key comparisons for a successful search?
Separate chaining
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The total search positions are . Dividing by the stored keys gives comparisons.
Incorrect! Try again.
52In a closed-hashing table, a key in the middle of a probe sequence is deleted. Why is its slot normally marked with a tombstone instead of being marked empty?
Closed hashing
Hard
A.A tombstone prevents future insertions from creating duplicate hash values
B.An empty slot could terminate searches for keys stored later in that probe sequence
C.An empty slot would force every subsequent key to be reinserted immediately
D.A tombstone reduces the load factor without changing the table capacity
Correct Answer: An empty slot could terminate searches for keys stored later in that probe sequence
Explanation:
Search stops at a genuinely empty slot. A tombstone preserves probe-sequence continuity while still allowing the slot to be reused.
Incorrect! Try again.
53Under the uniform-hashing model for open addressing, the expected number of probes in an unsuccessful search is approximately . What is the expectation when the load factor is ?
Open addressing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Substitution gives expected probes.
Incorrect! Try again.
54A linear-probing table of size uses . Keys are inserted in that order. How many slots are examined in an unsuccessful search for , counting the final empty slot?
Linear probing
Hard
A.6
B.8
C.5
D.7
Correct Answer: 7
Explanation:
The keys occupy slots through . Searching for starts at slot , examines six occupied slots, and terminates at empty slot .
Incorrect! Try again.
55For linear probing, the standard approximation for an unsuccessful search is . What is the estimate at load factor ?
Linear probing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The estimate is probes.
Incorrect! Try again.
56A table of size uses quadratic probing . If , which sequence gives the first six distinct slots visited?
Quadratic probing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
For , evaluating gives .
Incorrect! Try again.
57For a prime table size , quadratic probing uses . Which condition guarantees that an insertion finds an empty slot?
Quadratic probing
Hard
A.The load factor is below
B.The load factor is below
C.The table size is a power of two
D.The number of keys is relatively prime to
Correct Answer: The load factor is below
Explanation:
For prime , the first quadratic offsets are distinct. If fewer than half the slots are occupied, at least one of those probes is empty.
Incorrect! Try again.
58A table of size uses double hashing with and . Which key produces a probe step that cannot visit every table slot?
Double hashing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
For , the step is , and . The probe sequence therefore visits only two distinct slots.
Incorrect! Try again.
59A table of size uses , where and . What are the first six slots probed for ?
Double hashing
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Here and . Adding modulo repeatedly gives .
Incorrect! Try again.
60An open-addressing table is resized from capacity to capacity . Why must stored keys generally be rehashed rather than copied to the same array indices?
Hash tables
Hard
A.Probe sequences are valid only when the table contains no deleted entries
B.Copying indices would necessarily make the new load factor exceed one
C.Existing indices become invalid because every key's stored value changes
D.Hash values and probe sequences may depend on the new table capacity
Correct Answer: Hash values and probe sequences may depend on the new table capacity
Explanation:
Functions such as and capacity-dependent probe sequences change when changes. Each key must therefore be placed using the new capacity.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →