GATE / CS ARCHIVE

SUBJECT COLLECTION

Algorithms · Hashing & Randomized Algorithms

2 questions, newest first

GATE CSE has asked 2 questions on Hashing & Randomized Algorithms (Algorithms) from 2006 to 2023, in 2 of the 46 papers; the most recent is in GATE CSE 2023. In the last five years it carried 0.1 marks per 100-mark paper on average, against 0.1 since 2003. Since 2014 the questions have been 1 MCQ.

Browse topics
1 mark · MCQ
Report issue

Hashing & Randomized Algorithms

Question 20, GATE 2023: An adversary chooses k keys for m hash slots, k>m, to maximize collisions. Which strategy best counters a malicious fixed key set: A division with a fixed modulus; B multiplication with a fixed constant; C universal hashing; D choose division or multiplication based on whether k is prime?
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Universal hashing chooses a hash function randomly from a family with a bounded collision probability for distinct fixed keys, preventing an adversary from exploiting one known deterministic mapping. Division and multiplication with fixed constants can be targeted. Thus C under the standard model in which the selected random function is hidden or chosen independently of the adversary’s key set; unrestricted adaptive knowledge would require additional assumptions.

Teaching detail. For a universal family H, each distinct fixed pair x,y has collision probability at most 1/m when h is selected randomly from H. With chaining, the expected number of other keys colliding with a particular key is consequently bounded by (k−1)/m by linearity of expectation. Since k>m, some collisions are unavoidable by the pigeonhole principle: the goal is controlling concentrated collisions, not eliminating them. Random selection must be independent of the malicious fixed keys for this standard guarantee to apply.

Original paper, page 18 · Answer key

2 marks · MCQ
Report issue

Longest equal-sum span of binary arrays

Hashing & Randomized Algorithms

Question 54, GATE 2006: Given two length-n binary arrays a,b, find the longest interval [i,j] on which Σₖ₌ᵢʲaₖ=Σₖ₌ᵢʲbₖ, or report none. Which complexity describes the fastest method?
Options:
(A) O(3^n) and Ω(2^n) time if hashing is allowed
(B) O(n³) and Ω(n^2.5) time in the key-comparison model
(C) Θ(n) time and space
(D) O(√n) time only if the sum of all 2n entries is even
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Set prefix differences D[0]=0 and D[k]=sum(a[1..k])−sum(b[1..k]). A span (i,j) has equal sums iff D[i−1]=D[j].

2. Every D[k] lies in [−n,n], so an array of 2n+1 entries can store the earliest index of each difference. Scan once and maximize the distance to its first occurrence.

3. Time and space are Θ(n), option C; hashing is unnecessary. Reading the inputs already takes Ω(n) time.

4. Teaching check: Store the earliest occurrence of each prefix difference because that maximizes the length to a later equal difference. A binary-array prefix difference stays between −n and n, so direct indexing gives worst-case linear performance rather than relying on average-case hash-table behavior.

Original paper, page 8