Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is a hash table?(a) A structure that maps values to keys(b) A structure that maps keys to values(c) A structure used for storage(d) A structure used to implement stack and queueMy query is from Hash Tables topic in chapter Hash Tables of Data Structures & Algorithms IThis question was addressed to me during a job interview.

Answer»

Correct OPTION is (b) A structure that MAPS keys to values

The best explanation: A HASH table is used to implement associative arrays which has a key-value pair, so the has table maps keys to values.

2.

If several elements are competing for the same bucket in the hash table, what is it called?(a) Diffusion(b) Replication(c) Collision(d) DuplicationI'm obligated to ask this question of Hash Tables in section Hash Tables of Data Structures & Algorithms IThis question was addressed to me by my school principal while I was bunking the class.

Answer»

Right ANSWER is (c) Collision

Explanation: In a hash table, if sevaral elements are computing for the same BUCKET then there will be a clash AMONG elements. This condition is called Collision. The Collision is reduced by adding elements to a LINKED list and head address of linked list is PLACED in hash table.

3.

What is direct addressing?(a) Distinct array position for every possible key(b) Fewer array positions than keys(c) Fewer keys than array positions(d) Same array position for all keysI want to ask this question from Hash Tables topic in section Hash Tables of Data Structures & Algorithms IThe question was posed to me by my college director while I was bunking the class.

Answer»

Correct option is (a) Distinct ARRAY position for EVERY possible KEY

To explain: Direct addressing is possible only when we can afford to allocate an array that has ONE position for every possible key.

4.

What is the search complexity in direct addressing?(a) O(n)(b) O(logn)(c) O(nlogn)(d) O(1)Asked question is from Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me in a national level competition.

Answer»

Correct option is (d) O(1)

The explanation is: SINCE every KEY has a unique array position, SEARCHING TAKES a CONSTANT time.

5.

What is a hash function?(a) A function has allocated memory to keys(b) A function that computes the location of the key in the array(c) A function that creates an array(d) A function that computes the location of the values in the arrayThe origin of the question is Hash Tables in portion Hash Tables of Data Structures & Algorithms IThis question was addressed to me during an interview.

Answer» RIGHT choice is (b) A function that computes the LOCATION of the key in the array

Easy explanation - In a hash table, there are FEWER array positions than the KEYS, so the POSITION of the key in the array has to be computed, this is done using the hash function.
6.

Which of the following is not a technique to avoid a collision?(a) Make the hash function appear random(b) Use the chaining method(c) Use uniform hashing(d) Increasing hash table sizeMy question is taken from Hash Tables topic in section Hash Tables of Data Structures & Algorithms II got this question by my school teacher while I was bunking the class.

Answer» CORRECT choice is (d) Increasing hash table size

To explain: On increasing hash table size, space complexity will increase as we NEED to reallocate the memory size of hash table for every collision. It is not the best TECHNIQUE to avoid a collision. We can avoid collision by MAKING hash FUNCTION random, chaining method and uniform hashing.
7.

What is the load factor?(a) Average array size(b) Average key size(c) Average chain length(d) Average hash table lengthQuestion is from Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me in homework.

Answer»

The correct ANSWER is (c) Average chain length

The BEST I can EXPLAIN: In simple chaining, load FACTOR is the average number of elements stored in a chain, and is GIVEN by the ratio of number of elements stored to the number of slots in the array.

8.

What is simple uniform hashing?(a) Every element has equal probability of hashing into any of the slots(b) A weighted probabilistic method is used to hash elements into the slots(c) Elements has Random probability of hashing into array slots(d) Elements are hashed based on priorityQuery is from Hash Tables topic in section Hash Tables of Data Structures & Algorithms IThis question was addressed to me by my college professor while I was bunking the class.

Answer»

The correct answer is (a) EVERY element has equal probability of hashing into any of the slots

To explain: In simple uniform hashing, any GIVEN element is equally LIKELY to hash into any of the slots AVAILABLE in the array.

9.

In simple uniform hashing, what is the search complexity?(a) O(n)(b) O(logn)(c) O(nlogn)(d) O(1)My question is from Hash Tables in division Hash Tables of Data Structures & Algorithms II have been asked this question in an international level competition.

Answer»

The CORRECT answer is (d) O(1)

For explanation: There are two cases, once when the search is successful and when it is UNSUCCESSFUL, but in both the cases, the complexity is O(1+alpha) where 1 is to compute the HASH function and alpha is the LOAD factor.

10.

In simple chaining, what data structure is appropriate?(a) Singly linked list(b) Doubly linked list(c) Circular linked list(d) Binary treesI want to ask this question from Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was posed to me in exam.

Answer»

The correct CHOICE is (b) Doubly LINKED list

Easy explanation - DELETION becomes easier with doubly linked list, hence it is appropriate.

11.

The case in which a key other than the desired one is kept at the identified location is called?(a) Hashing(b) Collision(c) Chaining(d) Open addressingMy question is based upon Hash Tables topic in portion Hash Tables of Data Structures & Algorithms IThis question was addressed to me by my college professor while I was bunking the class.

Answer»

Right choice is (b) Collision

Easy EXPLANATION - When some other VALUE is PLACED at a specified LOCATION other than the DESIRED key, it is said to be a collision.

12.

What data organization method is used in hash tables?(a) Stack(b) Array(c) Linked list(d) QueueThis intriguing question originated from Hash Tables topic in section Hash Tables of Data Structures & Algorithms II have been asked this question in an online quiz.

Answer»

Correct option is (c) Linked LIST

Explanation: The data STRUCTURE USED to organize data for hash TABLES is linked list. It contains a data field and a pointer field.

13.

The task of generating alternative indices for a node is called?(a) Collision handling(b) Collision detection(c) Collision recovery(d) Closed hashingThe origin of the question is Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me by my college professor while I was bunking the class.

Answer»

The correct OPTION is (a) Collision handling

Explanation: Collision handling INVOLVES the PROCESS of formulating alternative indices for a KEY.

14.

Which of the following is not a collision resolution technique?(a) Separate chaining(b) Linear probing(c) Quadratic probing(d) HashingThe query is from Hash Tables in chapter Hash Tables of Data Structures & Algorithms IThis question was addressed to me in final exam.

Answer»

The correct choice is (d) HASHING

The best explanation: Hashing is a technique of placing DATA ITEMS in specific LOCATIONS. Collision may OCCUR in hashing but hashing is not a collision resolution technique.

15.

Hashing is the problem of finding an appropriate mapping of keys into addresses.(a) True(b) FalseThis is a very interesting question from Hash Tables in chapter Hash Tables of Data Structures & Algorithms II have been asked this question in homework.

Answer» CORRECT option is (a) True

Easiest explanation - HASHING is a DATA structure which is used to locate data in a table BASED on a key value.
16.

In a hash table of size 10, where is element 7 placed?(a) 6(b) 7(c) 17(d) 16I'd like to ask this question from Hash Tables topic in division Hash Tables of Data Structures & Algorithms IThe question was posed to me in exam.

Answer»

The correct option is (b) 7

Best EXPLANATION: The HASH location is defined as hash(F)= key MOD table_size.

7 mod 10 gives 7. It is placed in 7^th position.

17.

What should be the load factor for separate chaining hashing?(a) 0.5(b) 1(c) 1.5(d) 2The question is from Hash Tables topic in chapter Hash Tables of Data Structures & Algorithms IThis question was addressed to me during an internship interview.

Answer»

Right option is (b) 1

To EXPLAIN: For hashing using separate chaining method, the load factor should be maintained as 1. For open ADDRESSING method, it should not EXCEED 0.5.

18.

Which of the following operations are done in a hash table?(a) Insert only(b) Search only(c) Insert and search(d) ReplaceI'm obligated to ask this question of Hash Tables in chapter Hash Tables of Data Structures & Algorithms II got this question in a national level competition.

Answer»

Correct answer is (c) Insert and search

Easiest explanation - Hash tables are used to implement Insert and Find OPERATIONS in CONSTANT average TIME. This is the prime PURPOSE of hashing.

19.

Which of the following is identical to that of a separate chaining hash node?(a) Linked list(b) Array(c) Stack(d) QueueI'm obligated to ask this question of Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me during an internship interview.

Answer»

The correct answer is (a) Linked LIST

Best explanation: The hash node in SEPARATE CHAINING is similar to that of a linked list. The separate chaining hash table is an ARRAY of linked LISTS.

20.

Which of the following is the hashing function for separate chaining?(a) H(x)=(hash(x)+f(i)) mod table size(b) H(x)=hash(x)+i^2mod table size(c) H(x)=x mod table size(d) H(x)=x mod (table size * 2)This interesting question is from Hash Tables in chapter Hash Tables of Data Structures & Algorithms IThe question was posed to me in final exam.

Answer»

The correct option is (c) H(x)=x mod table size

For explanation: The hashing FUNCTION for separate chaining is GIVEN by H(x)= KEY mod table size. H(x)=hash(x)+i2mod table size DEFINES quadratic PROBING.

21.

What is the correct notation for a load factor?(a) Ω(b) ∞(c) ∑(d) ⅄The query is from Hash Tables topic in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me during an interview.

Answer»

The CORRECT option is (d) ⅄

Easy explanation - In general, load factor is DENOTED as ⅄. In separate CHAINING method, load factor is MAINTAINED as 1.0.

22.

In hash tables, how many traversal of links does a successful search require?(a) 1+⅄(b) 1+⅄^2(c) 1+ (⅄/2)(d) ⅄^3My query is from Hash Tables topic in portion Hash Tables of Data Structures & Algorithms II had been asked this question by my school principal while I was bunking the class.

Answer»

Right option is (C) 1+ (⅄/2)

EXPLANATION: A successful search REQUIRES about 1+ (⅄/2) links to be TRAVERSED. There is a GUARANTEE that at least one link must be traversed.

23.

Which of the following is a disadvantage of using separate chaining using linked lists?(a) It requires many pointers(b) It requires linked lists(c) It uses array(d) It does not resolve collisionThe query is from Hash Tables topic in chapter Hash Tables of Data Structures & Algorithms IThe question was asked during an interview.

Answer»

Correct choice is (a) It requires MANY POINTERS

The best I can explain: One of the major DISADVANTAGES of using separate chaining is the requirement of pointers. If the NUMBER of elements are more, it requires more pointers.

24.

What is the worst case search time of a hashing using separate chaining algorithm?(a) O(N log N)(b) O(N)(c) O(N^2)(d) O(N^3)The above asked question is from Hash Tables topic in portion Hash Tables of Data Structures & Algorithms II got this question in unit test.

Answer» RIGHT answer is (b) O(N)

For explanation: The worst CASE search time of SEPARATE chaining algorithm using linked lists is mathematically FOUND to be O(N).
25.

Which of the following is used in hash tables to determine the index of any input record?(a) hash function(b) hash linked list(c) hash tree(d) hash chainingQuery is from Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was posed to me in semester exam.

Answer»

Right option is (a) hash function

Easiest explanation - Hash table is an example of a DATA structure that is built for fast ACCESS of elements. Hash functions are used to determine the INDEX of any INPUT RECORD in a hash table.

26.

What is the advantage of a hash table as a data structure?(a) faster access of data(b) easy to implement(c) very efficient for less number of entries(d) exhibit good locality of referenceMy enquiry is from Hash Tables topic in chapter Hash Tables of Data Structures & Algorithms IThe question was asked in homework.

Answer»

Right CHOICE is (a) faster access of data

Explanation: Hash table is a data structure that has an advantage that it allows fast access of ELEMENTS. Hash functions are used to DETERMINE the INDEX of any input RECORD in a hash table.

27.

What is the use of a hash function?(a) to calculate and return the index of corresponding data(b) to store data(c) to erase data(d) to change dataMy question is taken from Hash Tables in division Hash Tables of Data Structures & Algorithms IThe question was asked in my homework.

Answer»

The correct answer is (a) to CALCULATE and return the index of corresponding DATA

The explanation is: Hash function calculates and RETURNS the index for corresponding data. This data is then MAPPED in a hash table.

28.

What is the time complexity of insert function in a hash table using a doubly linked list?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)My question is taken from Hash Tables in division Hash Tables of Data Structures & Algorithms IThis question was addressed to me in quiz.

Answer»

The correct option is (a) O(1)

Easy explanation - Time complexity of INSERT function in a HASH table is O(1). Condition is that the number of COLLISIONS should be low.

29.

What is the time complexity of search function in a hash table using a doubly linked list?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)This interesting question is from Hash Tables in section Hash Tables of Data Structures & Algorithms II have been asked this question in examination.

Answer» RIGHT ANSWER is (a) O(1)

To explain: Time complexity of search function in a HASH table is O(1). Condition is that the number of collisions should be LOW.
30.

What is the time complexity of delete function in the hash table using a doubly linked list?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)This key question is from Hash Tables in portion Hash Tables of Data Structures & Algorithms IThis question was addressed to me during an online exam.

Answer»

Right OPTION is (a) O(1)

The best EXPLANATION: Time complexity of delete function in a HASH table is O(1). Condition is that the hash function should be such that the number of collisions should be LOW.

31.

Hashing can be used to encrypt and decrypt digital signatures.(a) true(b) falseThe origin of the question is Hash Tables in division Hash Tables of Data Structures & Algorithms II had been asked this question in an online quiz.

Answer»

Right option is (a) true

To EXPLAIN: Hashing is also USED in encryption ALGORITHMS. It is used for encryption and DECRYPTION of digital signatures.

32.

What is the advantage of using a doubly linked list for chaining over singly linked list?(a) it takes less memory(b) it is easy to implement(c) it makes the process of insertion and deletion faster(d) it causes less collisionsThis interesting question is from Hash Tables in chapter Hash Tables of Data Structures & Algorithms II had been asked this question during an online interview.

Answer» CORRECT option is (c) it makes the PROCESS of insertion and DELETION faster

Easiest explanation - Using a doubly linked list reduces time complexity significantly. THOUGH it USES more memory to store the extra pointer.
33.

Which of the following technique stores data in the hash table itself in case of a collision?(a) Open addressing(b) Chaining using linked list(c) Chaining using doubly linked list(d) Chaining using binary treeI want to ask this question from Hash Tables in division Hash Tables of Data Structures & Algorithms IThe question was asked in quiz.

Answer»

Correct answer is (a) Open ADDRESSING

To EXPLAIN: Open addressing is USED to store DATA in the table itself in case of a collision. Whereas CHAINING stores data in a separate entity.

34.

Which of the following technique stores data in a separate entity in case of a collision?(a) Open addressing(b) Chaining using doubly linked list(c) Linear probing(d) Double hashingThis is a very interesting question from Hash Tables in portion Hash Tables of Data Structures & Algorithms II got this question during an online interview.

Answer» CORRECT answer is (b) Chaining using doubly linked list

Best EXPLANATION: Chaining using doubly linked list is used to store data in a separate entity (doubly linked list in this CASE) in case of a COLLISION. Whereas open addressing stores it in the table itself.
35.

Collision is caused due to the presence of two keys having the same value.(a) True(b) FalseThis interesting question is from Hash Tables topic in division Hash Tables of Data Structures & Algorithms IThe question was asked in final exam.

Answer»

Right choice is (a) True

Explanation: A COLLISION is CAUSED DUE to the presence of two KEYS having the same value. It is handled by using any one of the two methods namely:- Chaining and Open ADDRESSING.

36.

Which of the following variant of a hash table has the best cache performance?(a) hash table using a linked list for separate chaining(b) hash table using binary search tree for separate chaining(c) hash table using open addressing(d) hash table using a doubly linked list for separate chainingEnquiry is from Hash Tables in section Hash Tables of Data Structures & Algorithms IThe question was posed to me in quiz.

Answer»

The correct choice is (c) hash table using open ADDRESSING

Easy EXPLANATION - Implementation of the hash table using open addressing has a better cache performance as compared to separate chaining. It is because open addressing stores DATA in the same table without using any extra SPACE.

37.

What is the advantage of hashing with chaining?(a) cache performance is good(b) uses less space(c) less sensitive to hash function(d) has a time complexity of O(n) in the worst caseThis key question is from Hash Tables in division Hash Tables of Data Structures & Algorithms IThe question was asked during an online interview.

Answer»

The correct CHOICE is (c) LESS sensitive to hash FUNCTION

Explanation: Hashing with separate chaining has an advantage that it is less sensitive to a hash function. It is also EASY to implement.

38.

What is the disadvantage of hashing with chaining?(a) not easy to implement(b) takes more space(c) quite sensitive to hash function(d) table gets filled up easilyQuestion is taken from Hash Tables in division Hash Tables of Data Structures & Algorithms II had been asked this question in an interview.

Answer»

Right choice is (B) TAKES more space

Easy explanation - Hashing with separate CHAINING has a disadvantage that it takes more space. This space is used for storing elements in CASE of a COLLISION.

39.

What is the time complexity of insert function in a hash table using a binary tree?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)My question comes from Hash Tables in division Hash Tables of Data Structures & Algorithms II had been asked this question in homework.

Answer»

Right ANSWER is (a) O(1)

The EXPLANATION is: TIME complexity of insert function in a hash table is O(1) on an average. CONDITION is that the number of collisions should be low.

40.

What is the time complexity of the search function in a hash table using a binary tree?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)Question is from Hash Tables in division Hash Tables of Data Structures & Algorithms II had been asked this question in unit test.

Answer» RIGHT CHOICE is (a) O(1)

BEST EXPLANATION: Time complexity of search function in a hash table is O(1). Condition is that the number of COLLISIONS should be low.
41.

What is the time complexity of the delete function in the hash table using a binary tree?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)Question is from Hash Tables in section Hash Tables of Data Structures & Algorithms II got this question in an interview.

Answer»

The correct choice is (a) O(1)

Explanation: Time COMPLEXITY of delete function in a hash table is O(1). Condition is that the hash function should be such that the NUMBER of collisions should be LOW.

42.

What is the advantage of a hash table over BST?(a) hash table has a better average time complexity for performing insert, delete and search operations(b) hash table requires less space(c) range query is easy with hash table(d) easier to implementI want to ask this question from Hash Tables in portion Hash Tables of Data Structures & Algorithms IThe question was posed to me in an online interview.

Answer»

Right answer is (a) hash table has a better average time complexity for PERFORMING insert, delete and search OPERATIONS

The best EXPLANATION: Hash table and BST both are examples of DATA STRUCTURES. Hash table has an advantage that it has a better time complexity for performing insert, delete and search operations.

43.

What is the disadvantage of BST over the hash table?(a) BST is easier to implement(b) BST can get the keys sorted by just performing inorder traversal(c) BST can perform range query easily(d) Time complexity of hash table in inserting, searching and deleting is less than that of BSTI want to ask this question from Hash Tables topic in section Hash Tables of Data Structures & Algorithms II have been asked this question during an online exam.

Answer» CORRECT option is (d) TIME complexity of hash table in inserting, searching and deleting is less than that of BST

To explain: BST has an advantage that it is easier to implement, can get the keys sorted by just performing in-order traversal and can perform range query easily. Hash table has LESSER time complexity for performing insert, DELETE and search OPERATIONS.
44.

Which of the following technique stores data separately in case of a collision?(a) Open addressing(b) Double hashing(c) Quadratic probing(d) Chaining using a binary treeThis is a very interesting question from Hash Tables in section Hash Tables of Data Structures & Algorithms IThis question was addressed to me in an interview.

Answer»

Correct option is (d) Chaining using a binary tree

To explain: Open ADDRESSING is used to store data in the table itself in CASE of a collision. Whereas chaining STORES data in a separate ENTITY.

45.

Separate chaining is easier to implement as compared to open addressing.(a) true(b) falseMy question is from Hash Tables in division Hash Tables of Data Structures & Algorithms II got this question in quiz.

Answer»

Correct answer is (a) true

Easy EXPLANATION - There are TWO methods of HANDLING collisions in a hash table:- OPEN addressing and separate chaining. Open addressing requires more computation as COMPARED to separate chaining.

46.

In open addressing the hash table can never become full.(a) True(b) FalseMy doubt stems from Hash Tables in section Hash Tables of Data Structures & Algorithms II had been asked this question during an internship interview.

Answer»

Correct option is (B) False

Easy explanation - There are two METHODS of HANDLING collisions in a hash table:- open addressing and SEPARATE chaining. In open addressing the hash table can become FULL.

47.

Which of the following helps keys to be mapped into addresses?(a) hash function(b) separate chaining(c) open addressing(d) chaining using a linked listThis question is from Hash Tables topic in division Hash Tables of Data Structures & Algorithms II had been asked this question by my college director while I was bunking the class.

Answer»

The CORRECT answer is (a) hash function

The explanation is: Hash table is an example of a data structure that is built for fast ACCESS of elements. Hash FUNCTIONS are used to determine the INDEX of any input record in a hash table.

48.

What is the advantage of the hash table over a linked list?(a) faster access of data(b) easy to implement(c) very efficient for less number of entries(d) exhibit good locality of referenceThe query is from Hash Tables topic in division Hash Tables of Data Structures & Algorithms IThe question was posed to me during an internship interview.

Answer»

Right ANSWER is (a) faster access of data

Easy EXPLANATION - Hash table is a data STRUCTURE that has an advantage that it allows fast access of elements. But linked list is easier to IMPLEMENT as compared to the hash table.

49.

Which of the following trait of a hash function is most desirable?(a) it should cause less collisions(b) it should cause more collisions(c) it should occupy less space(d) it should be easy to implementQuery is from Hash Tables topic in portion Hash Tables of Data Structures & Algorithms II got this question in an internship interview.

Answer»

Correct option is (a) it should CAUSE less collisions

The best I can explain: Hash function calculates and RETURNS the INDEX for corresponding data. So the most IMPORTANT trait of a hash function is that it should cause a MINIMUM number of collisions.

50.

What is the time complexity of insert function in a hash table using list head?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)The above asked question is from Hash Tables topic in division Hash Tables of Data Structures & Algorithms IThe question was posed to me during an interview for a job.

Answer» CORRECT answer is (a) O(1)

The best I can explain: TIME complexity of insert function in a HASH table is O(1). Condition is that the number of collisions should be LOW.