Software Development Exam  >  Software Development Test  >  DSA in C++  >  Test: Hashmaps - 1 - Software Development MCQ

Hashmaps - 1 - Free MCQ Practice Test with solutions, Software Development


MCQ Practice Test & Solutions: Test: Hashmaps - 1 (15 Questions)

You can prepare effectively for Software Development DSA in C++ with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Hashmaps - 1". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.

Test Highlights:

  • - Format: Multiple Choice Questions (MCQ)
  • - Duration: 30 minutes
  • - Number of Questions: 15

Sign up on EduRev for free to attempt this test and track your preparation progress.

Test: Hashmaps - 1 - Question 1

Which of the following best describes a hashmap?

Detailed Solution: Question 1

Hashmaps allow constant-time access to elements based on their keys by using a hash function to convert the key into an array index.

Test: Hashmaps - 1 - Question 2

What is hashing in the context of hashmaps?

Detailed Solution: Question 2

Hashing is a method for converting a key into an array index using a hash function. The hash function maps the key to an array index.

Test: Hashmaps - 1 - Question 3

Which of the following collision resolution techniques is used in separate chaining?

Detailed Solution: Question 3

Separate chaining uses linked lists to handle collisions. Each slot of the hashmap contains a linked list of key-value pairs.

Test: Hashmaps - 1 - Question 4

What is the purpose of open addressing in hashmaps?

Detailed Solution: Question 4

Open addressing is used to find the next available slot in the hashmap when a collision occurs. It avoids storing multiple values for the same key.

Test: Hashmaps - 1 - Question 5

The Rabin-Karp algorithm is primarily used for which of the following?

Detailed Solution: Question 5

The Rabin-Karp algorithm is primarily used for string matching. It efficiently finds occurrences of a pattern string within a longer text string.

Test: Hashmaps - 1 - Question 6

What will be the output of the following code?
#include <iostream>
#include <unordered_map>

int main() {
    std::unordered_map<int, std::string> map;
    map[1] = "Alice";
    map[2] = "Bob";
    map[3] = "Charlie";

    std::cout << map[2] << std::endl;
    return 0;
}

Detailed Solution: Question 6

The code assigns values to keys in the hashmap and then retrieves the value associated with the key 2, which is "Bob". The output will be "Bob".

Test: Hashmaps - 1 - Question 7

What will be the output of the following code?
#include <iostream>
#include <unordered_map>

int main() {
    std::unordered_map<int, int> map;

    for (int i = 0; i < 5; i++) {
        map[i] = i * 10;
    }

    std::cout << map[5] << std::endl;
    return 0;
}

Detailed Solution: Question 7

The code assigns values to keys from 0 to 4, but the key 5 is not assigned a value. Accessing map[5] will return a default-constructed value, which is 0 for integers.

Test: Hashmaps - 1 - Question 8

What will be the output of the following code?
#include <iostream>
#include <unordered_map>

int main() {
    std::unordered_map<int, int> map;

    map[1] = 10;
    map[2] = 20;
    map[3] = 30;
    map[4] = 40;

    std::cout << map.size() << std::endl;
    return 0;
}

Detailed Solution: Question 8

The code assigns values to four different keys in the hashmap. The 'size()' function returns the number of elements in the hashmap, which is 4 in this case.

Test: Hashmaps - 1 - Question 9

What will be the output of the following code?
#include <iostream>
#include <unordered_map>

int main() {
    std::unordered_map<int, int> map;

    map[1] = 10;
    map[2] = 20;
    map[3] = 30;
    map[4] = 40;

    map.erase(2);

    std::cout << map.size() << std::endl;
    return 0;
}

Detailed Solution: Question 9

The code assigns values to four different keys in the hashmap and then erases the key 2. The 'size()' function returns the number of elements in the hashmap, which is 3 after erasing.

Test: Hashmaps - 1 - Question 10

What will be the output of the following code?
#include <iostream>
#include <unordered_map>

int main() {
    std::unordered_map<char, int> map;

    map['a'] = 1;
    map['b'] = 2;
    map['c'] = 3;
    map['d'] = 4;

    std::cout << map['z'] << std::endl;
    return 0;
}

Detailed Solution: Question 10

The code assigns values to keys 'a' to 'd', but the key 'z' is not assigned a value. Accessing map['z'] will return a default-constructed value, which is 0 for integers.

Test: Hashmaps - 1 - Question 11

Which of the following hashing techniques uses the concept of linear probing?

Detailed Solution: Question 11

Linear probing is a technique used in open addressing, not separate chaining. Separate chaining uses linked lists to handle collisions.

Test: Hashmaps - 1 - Question 12

Which of the following statements about open addressing is false?

Detailed Solution: Question 12

Open addressing can handle a limited number of elements due to the need to find the next available slot. Separate chaining can handle more elements by using linked lists.

Test: Hashmaps - 1 - Question 13

The Rabin-Karp algorithm uses which of the following concepts?

Detailed Solution: Question 13

The Rabin-Karp algorithm uses a rolling hash function to efficiently compare the pattern string with substrings of the text string.

Test: Hashmaps - 1 - Question 14

Which of the following collision resolution techniques is used in open addressing?

Detailed Solution: Question 14

Linear probing is a collision resolution technique used in open addressing. It probes the next slot in a linear fashion until an available slot is found.

Test: Hashmaps - 1 - Question 15

Which of the following is a drawback of using separate chaining for collision resolution?

Detailed Solution: Question 15

Separate chaining requires additional memory to store linked lists for collisions, leading to increased memory usage compared to open addressing.

152 videos|118 docs|24 tests
Information about Test: Hashmaps - 1 Page
In this test you can find the Exam questions for Test: Hashmaps - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Hashmaps - 1, EduRev gives you an ample number of Online tests for practice
152 videos|118 docs|24 tests
Download as PDF