Maps

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/16

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

17 Terms

1
New cards

Map - Definition

  • Searchable collection of key-value pairs

  • Duplicate keys not allowed

2
New cards

Map - Operations

  • get(k)

  • put(k, v)

  • remove(k)

  • size()

  • isEmpty()

  • entrySet(), keySet(), values() Return collections of x

3
New cards

Map - Implementation Options

  • Unsorted list

  • Hash table

4
New cards

Maps - List Implementation

Stores entries in unsorted list

5
New cards

Maps - Hash Table Implementation

  • Bucket Array: Array of size N, each cell stores key-value pairs

  • Hash Function: Maps keys to integers in range [0, N-1]

6
New cards

Hash Code

keys → integers

7
New cards

Types of Hash Codes

Memory Address: Uses object's memory address (default in Java)

Integer Cast: Reinterprets key bits as integer

Component Sum: Partitions key bits into fixed-length components and sums them

8
New cards

Types of Compression Functions

Division: h₂(y) = y mod N (N typically prime)

MAD (Multiply, Add, Divide): h₂(y) = [(ay + b) mod p] mod N

  • p is prime > N; a,b are random integers in [0,p-1] with a > 0

9
New cards

Types of Collision Handling

  1. Seperate chaining

  2. Open addressing

    • Linear probing

    • Double hashing

    • Quadratic probing

10
New cards

Open Addressing - Implementation

  • All entries stored directly in bucket array

  • When collision occurs, use probing to find alternative cell

11
New cards

Linear Probing - Implementation

  • Try cells sequentially: (i+1) mod N, (i+2) mod N, etc

  • For deletion: mark cell as AVAILABLE, not empty

12
New cards

Double Hashing - Implementation

  • Uses secondary hash function h'(k) to determine step size

13
New cards

Performance of Hashing

Average case - O(1)

For all search, insert, delete.

14
New cards

Map Time Complexity

get(k), put(k, v), remove(k) - O(n)

15
New cards

Compression Function

maps integers → [0, N-1]

16
New cards

Seperate Chaining

  • Has one function

  • If collision occurs, store as a list within that cell

17
New cards

Quadratic Probing

When a collision occurs at the initial hash position h(k), apply the formula h(k, i) = (h(k) + i²) mod m for i = 1, 2, 3... until an empty slot is found.