FullStackCafe QAS 1712833162841

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

FullStack.

Cafe - Kill Your Tech Interview

FullStack.Cafe - Kill Your Tech Interview

Q1: What is Hash Table? ☆

Topics: Hash Tables Data Structures

Answer:

A hash table (hash map) is a data structure that implements an associative array abstract data type, a
structure that can map keys to values. Hash tables implement an associative array, which is indexed by
arbitrary objects (keys). A hash table uses a hash function to compute an index, also called a hash value, into
an array of buckets or slots, from which the desired value can be found.

Q2: What is Hashing? ☆☆

Topics: Hash Tables

Answer:

Hashing is the practice of using an algorithm (or hash function) to map data of any size to a fixed length.
This is called a hash value (or sometimes hash code or hash sums or even a hash digest if you’re feeling fancy).
In hashing, keys are converted into hash values or indexes by using hash functions. Hashing is a one-way
function.

Q3: Define what is a Hash Function? ☆☆

Topics: Hash Tables

Answer:

Page 1 of 3
FullStack.Cafe - Kill Your Tech Interview

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values
returned by a hash function are called hash values, hash codes, digests, or simply hashes. The values are used to
index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or
scatter storage addressing.

Mathematically speaking, a hash function is usually defined as a mapping from the universe of elements you
want to store in the hash table to the range {0, 1, 2, .., numBuckets - 1} .

Some properties of Hash Functions are:

Very fast to compute (nearly constant)


One way; can not be reversed
Output does not reveal information on input
Hard to find collisions (different data with same hash)
Implementation is based on parity-preserving bit operations (XOR and ADD), multiply, or divide.

Q4: Explain what is Hash Value? ☆☆

Topics: Hash Tables

Answer:

A Hash Value (also called as Hashes or Checksum) is a string value (of specific length), which is the result of
calculation of a Hashing Algorithm. Hash Values have different uses:

1. Indexing for Hash Tables


2. Determine the Integrity of any Data (which can be a file, folder, email, attachments, downloads etc).

Q5: What is the space complexity of a Hash Table? ☆☆

Topics: Hash Tables Data Structures

Answer:

The space complexity of a datastructure indicates how much space it occupies in relation to the amount of
elements it holds. For example a space complexity of O(1) would mean that the datastructure alway consumes
constant space no matter how many elements you put in there. O(n) would mean that the space consumption
grows linearly with the amount of elements in it.

A hashtable typically has a space complexity of O(n) .

Q6: What is the difference between Hashing and Hash Tables? ☆☆

Topics: Hash Tables

Answer:

Hashing is simply the act of turning a data chunk of arbitrary length into a fixed-width value (hereinafter
called a hash value) that can be used to represent that chunk in situations where dealing with the original
data chunk would be inconvenient.

A hash table is one of those situations; it simply stores references to such data chunks in a table indexed by
each chunk's hash value. This way, instead of potentially comparing your desired key chunk against a huge

Page 2 of 3
FullStack.Cafe - Kill Your Tech Interview

number of chunks, you simply compute the hash value of the key chunk and do a much faster lookup with
that hash value.

Q7: Provide a simple example of Hash Function ☆☆

Topics: Hash Tables

Answer:

A one-way function is not just a hash function - a function that loses information - but a function f for which,
given an image y , it is difficult to find a pre-image x such that f(x)=y .

A very simple example of a hash function that does not use any advanced math, is this simple** parity
function**:

def hash(n: Nat)


if n.even?
0
else
1
end
end

As you can see, it maps a large input space (the natural numbers) into a small output space (the set {0, 1} ).
And it is one-way: if I tell you that the result is 1 , you can't tell me what the input was.

This is why they are called one-way: you can compute an image but you can't find a pre-image for a given image.

Page 3 of 3

You might also like