Domain: Computer Systems & Operating Systems

A Count-Min Sketch (CMS) is used to estimate frequencies over a stream of integer keys.

-----------------------------------
SKETCH CONFIGURATION
-----------------------------------

- Depth: d = 4 rows  
- Width: w = 11 columns  
- Counters are indexed from 0 to 10  
- All counters are initialized to 0  
- No pre-warming is applied  

-----------------------------------
HASH FUNCTIONS
-----------------------------------

For any non-negative integer x:

g₁(x) = (3x + 2) mod 11  
g₂(x) = (5x + 7) mod 11  
g₃(x) = (7x + 1) mod 11  
g₄(x) = (9x + 4) mod 11  

-----------------------------------
UPDATE RULE (STANDARD CMS)
-----------------------------------

For each update (x, Δ):

- If Δ ≤ 0, ignore the update  
- Otherwise, for each row i = 1..4:
  - Increment counter[i][gᵢ(x)] by Δ  

-----------------------------------
QUERY RULE
-----------------------------------

To query key x:

- Compute the 4 counters addressed by g₁(x), g₂(x), g₃(x), g₄(x)
- Return the minimum of these 4 values  

-----------------------------------
UPDATES (IN ORDER)
-----------------------------------

(4, 6)  
(9, 3)  
(20, 5)  
(1, 4)  
(31, 2)  
(9, 7)  
(2, -3)  
(13, 1)  
(20, 4)  
(0, 2)  
(9, -2)  
(22, 8)  
(31, 5)  
(20, 1)  

-----------------------------------
TASK
-----------------------------------

After processing all updates, determine the final CMS state relevant to querying key x = 20.

Use row numbers 1 through 4.

-----------------------------------
OUTPUT FORMAT

Output exactly the following 7 lines, with no extra text:

ignored_updates: <integer>
hashes_20: <g1>,<g2>,<g3>,<g4>
counter_1_7: <integer>
counter_2_8: <integer>
counter_3_9: <integer>
counter_4_8: <integer>
query_20: <integer>

For `hashes_20`, list the four hash results for x = 20 in the order g1, g2, g3, g4, separated by commas and with no spaces.


Grading rubric:
criterion: The response states `ignored_updates: 2`.
weight: 5
criterion: The response states `hashes_20: 7,8,9,8`.
weight: 15
criterion: The response states `counter_1_7: 27`.
weight: 10
criterion: The response states `counter_2_8: 27`.
weight: 10
criterion: The response states `counter_3_9: 27`.
weight: 10
criterion: The response states `counter_4_8: 27`.
weight: 10
criterion: The response states `query_20: 27`.
weight: 20

Answer:
Reasoning

Only updates with positive delta are applied. Therefore `(2, -3)` and `(9, -2)` are ignored, so the number of ignored updates is 2.

For the query key `x = 20`, the four hash locations are:

- `g1(20) = (3*20 + 2) mod 11 = 62 mod 11 = 7`
- `g2(20) = (5*20 + 7) mod 11 = 107 mod 11 = 8`
- `g3(20) = (7*20 + 1) mod 11 = 141 mod 11 = 9`
- `g4(20) = (9*20 + 4) mod 11 = 184 mod 11 = 8`

So `hashes_20 = 7,8,9,8`.

To determine the final values of those four counters, sum the positive updates from every key that lands in the same bucket in each row.

For key `20`, the positive updates are `(20,5)`, `(20,4)`, and `(20,1)`, for a total contribution of `10`.

Key `9` hashes to the same four positions:

- `g1(9) = (27 + 2) mod 11 = 29 mod 11 = 7`
- `g2(9) = (45 + 7) mod 11 = 52 mod 11 = 8`
- `g3(9) = (63 + 1) mod 11 = 64 mod 11 = 9`
- `g4(9) = (81 + 4) mod 11 = 85 mod 11 = 8`

Its positive updates are `(9,3)` and `(9,7)`, for a total of `10`.

Key `31` also hashes to the same four positions:

- `g1(31) = (93 + 2) mod 11 = 95 mod 11 = 7`
- `g2(31) = (155 + 7) mod 11 = 162 mod 11 = 8`
- `g3(31) = (217 + 1) mod 11 = 218 mod 11 = 9`
- `g4(31) = (279 + 4) mod 11 = 283 mod 11 = 8`

Its positive updates are `(31,2)` and `(31,5)`, for a total of `7`.

The remaining keys do not change the queried counters for `x = 20`, because at least one of their row positions differs from the needed counter in each row. Therefore each queried counter receives exactly:

- `10` from key `20`
- `10` from key `9`
- `7` from key `31`

That gives:

- `counter_1_7 = 27`
- `counter_2_8 = 27`
- `counter_3_9 = 27`
- `counter_4_8 = 27`

The CMS query returns the minimum of these four addressed counters, so:

- `query_20 = min(27, 27, 27, 27) = 27`

Required final output

ignored_updates: 2
hashes_20: 7,8,9,8
counter_1_7: 27
counter_2_8: 27
counter_3_9: 27
counter_4_8: 27
query_20: 27