Junior — Middle
Explain your experience with data structures like hash tables and in what cases you have used their implementation.
sobes.tech AI
Answer from AI
A hash table is a data structure that provides quick access to elements by key, usually in near O(1) time. In C/C++, it can be implemented using arrays and hash functions.
I have used hash tables for tasks where quick search, addition, or deletion of elements by a unique key is needed, such as caching results, counting word frequencies, or implementing dictionaries.
Example of usage in C++ with std::unordered_map:
#include <unordered_map>
#include <string>
#include <iostream>
int main() {
std::unordered_map<std::string, int> wordCount;
wordCount["apple"] = 2;
wordCount["banana"] = 3;
std::cout << "apple: " << wordCount["apple"] << std::endl;
return 0;
}