DATA Hashing and Heaps Vocab

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

1/46

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

47 Terms

1
New cards

Hash Table ADT

Allows constant average time for insertion, deletion, and search; does not support ordered operations like findMin or findMax

2
New cards

Hash Table Basics

Fixed-size array; hash function maps keys to indices

3
New cards

Hash Table Structure & Collisions

Table size = TableSize; hash function maps keys to [0, TableSize

4
New cards

Hash Function Examples

Integer keys: key % TableSize (preferably prime); String keys: sum ASCII values mod TableSize

5
New cards

String Hash Function (Code)

Simple hash function sums ASCII values of characters in a string

6
New cards

ASCII Table

Reference for ASCII values of letters

7
New cards

Another String Hash Function

Weighted sum of first three characters; limited combinations in English

8
New cards

Collisions Introduction

Two main resolution methods: Separate Chaining and Open Addressing

9
New cards

Separate Chaining

Each table slot holds linked list of elements with same hash

10
New cards

Separate Chaining Diagram

Visual representation of separate chaining

11
New cards

Separate Chaining Analysis

Load factor λ = elements / TableSize; average unsuccessful search examines λ nodes; successful search examines 1 + λ/2 nodes

12
New cards

Open Addressing Intro

Alternative to separate chaining; no linked lists used

13
New cards

Open Addressing Definition

On collision, probe for next empty cell using f(i); load factor λ < 0.5

14
New cards

Open Addressing Strategies

Linear Probing, Quadratic Probing, Double Hashing

15
New cards

Linear Probing

f(i) = i; sequential probing; can cause primary clustering

16
New cards

Linear Probing Example

Step-by-step insertion with linear probing

17
New cards

Linear Probing Complexity

Insert & find: O(n) worst case; deletion requires lazy deletion

18
New cards

Deletion in Probing Tables

Standard deletion not allowed; use lazy deletion; cells marked active or deleted

19
New cards

Linear Probing Performance

Expected probes for unsuccessful search = 1/(1

20
New cards

Linear Probing Graph

Shows probe counts vs load factor; performance degrades when table > half full

21
New cards

Quadratic Probing

f(i) = i²; reduces primary clustering

22
New cards

Quadratic Probing Example

Step-by-step insertion with quadratic probing

23
New cards

Quadratic Probing Limitations

Requires prime TableSize and λ < 0.5; may fail to find empty slot if table > half full

24
New cards

Quadratic Probing Detailed Example

Inserting keys 76, 40, 48, 5, 55, 47 into size-7 table; shows failure to insert 47 due to limited probe sequence

25
New cards

Quadratic Probing Analysis

May not explore all slots; if TableSize prime and λ < 0.5, empty slot will be found

26
New cards

Secondary Clustering

Quadratic probing avoids primary clustering but can cause secondary clustering; double hashing suggested

27
New cards

Double Hashing

Uses second hash function f(i) = i * hash₂(x); example hash₂(x) = R

28
New cards

Double Hashing Example

Step-by-step insertion using double hashing

29
New cards

TableSize Should Be Prime

Prime TableSize improves distribution in double hashing; quadratic probing simpler/faster for expensive hash functions

30
New cards

Separate Chaining vs Open Addressing

Separate chaining: easier, predictable; Open addressing: less memory, clustering issues

31
New cards

Rehashing

When table too full, create larger table (usually double) and re-insert all elements; costly O(N) but infrequent

32
New cards

Hashing Wrap-Up

Efficient for insert/delete/find; requires good hash function, prime table size, proper load factor; widely used

33
New cards

Priority Queue ADT

Defines priority queue with insert(k, x) and removeMin(); applications: standby flyers, auctions, stock market

34
New cards

Priority Queue Sorting

Using priority queue to sort (PQ-Sort); unsorted sequence → selection sort (O(n²)); sorted sequence → insertion sort (O(n²))

35
New cards

Heap Definition

Binary tree with heap-order property and complete binary tree structure; visual example given

36
New cards

Height of a Heap

O(log n); proof based on complete binary tree property

37
New cards

Heaps and Priority Queues

Heaps can implement priority queues; each node stores (key, element); diagram shown

38
New cards

Insertion into a Heap

Steps: 1) find insertion node (last node), 2) store key, 3) restore heap-order via upheap

39
New cards

Upheap

Restores order after insertion by swapping upward; runs in O(log n) time

40
New cards

Removal from a Heap

removeMin removes root: 1) replace root with last node’s key, 2) remove last node, 3) restore heap-order via downheap

41
New cards

Downheap

Restores order after removal by swapping downward; runs in O(log n) time

42
New cards

Updating the Last Node

Finding new last node in O(log n) steps

43
New cards

Heap-Sort

Heap-based priority queue sort gives O(n log n), faster than insertion/selection sort

44
New cards

Vector-based Heap Implementation

Heap stored in array/vector; children at 2i and 2i+1; enables in-place heap-sort

45
New cards

Merging Two Heaps

Merge by making new root and performing downheap

46
New cards

Bottom-Up Heap Construction

Build heap in O(n) time by merging pairs bottom-up; step-by-step examples shown

47
New cards

Analysis of Bottom-Up Construction

Proxy path analysis shows O(n) time; faster than n insertions (O(n log n))