0% found this document useful (0 votes)
30 views

CSE 373 Lecture 14: Midterm Review Today's Topics:: Hashing: Applications

The document summarizes key topics for an upcoming midterm exam, including hashing applications, math background on Big-Oh notation, and data structures like lists, stacks, queues, trees, heaps, and binomial queues. It provides details on the midterm format which will be closed book, closed notes, with 5 questions in 50 minutes. Students are advised to review definitions and algorithms related to these topics.

Uploaded by

Tawsif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

CSE 373 Lecture 14: Midterm Review Today's Topics:: Hashing: Applications

The document summarizes key topics for an upcoming midterm exam, including hashing applications, math background on Big-Oh notation, and data structures like lists, stacks, queues, trees, heaps, and binomial queues. It provides details on the midterm format which will be closed book, closed notes, with 5 questions in 50 minutes. Students are advised to review definitions and algorithms related to these topics.

Uploaded by

Tawsif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSE 373 Lecture 14: Midterm Review Hashing: Applications

✦ Today’s Topics: ✦ Hash tables are used in many real-word applications:


➭ Wrap-up of hashing ➭ As symbol tables in compilers – store and access info
➭ Review of topics for midterm exam about variables & functions each time their name appears
in program being compiled
✦ Midterm details: ➭ In game programs: Avoid recomputing moves by storing
➭ Chapters 1-6 in the textbook each board configuration encountered with corresponding
➭ Closed book, closed notes best move in a hash table
➭ Format: 5 questions, 100 points total ➭ In spelling checkers: prehash entire dictionary and check
➭ Time: Monday, class time 11:30-12:20 (50 minutes) if words in a document are in dictionary in constant time
➭ Blank sheets will be provided
➭ Bring pens/sharpened pencils (and sharpened minds)

R. Rao, CSE 373 1 R. Rao, CSE 373 2

Summary of Hashing Midterm Review: Math Background


✦ Main reason to use hashing: speed! ✦ Know the definitions of Big-Oh, little-oh, big-omega, and theta:
➭ O(1) access time (at the cost of using space O(TableSize)) ➭ T(N) = O(f(N)) if there are positive constants c and n0 such
➭ Only supports Insert/Find/Delete (no ordering of items) that T(N) ≤ cf(N) for N ≥ n0.

✦ Components: TableSize (prime), hash function, collision strategy ✦ Think of O(f(N)) as “less than or equal to” f(N) ! Upper bound

✦ Think of Ω(f(N)) as “greater than or equal to” f(N) ! Lower


✦ Chaining collisions allows λ > 1 but uses space for pointers
bound
✦ Probing requires λ < 1 but avoids the time and space needed for
✦ Think of Θ(f(N)) as “equal to” f(N) ! “Tight” bound, same
allocating pointers growth rate
✦ Think of o(f(N)) as “strictly less than” f(N) ! Strict upper bound
➭ T(N) = o(f(N)) means f(N) has faster growth rate than T(N)

R. Rao, CSE 373 3 R. Rao, CSE 373 4


Summations Recurrences
Run time of program segment: ✦ Used to analyze run time T(N) of recursive function for input
N
N ( N + 1)
∑i =
i =1 2
for (i = 1; i <= N; i++)
size N
➭ Write down cost of each line of function
for (j = 1; j <= i; j++) ➭ For recursive calls, write cost in terms of T and new input size N’
➭ E.g. T(N) = (cost for non-recursive lines) + T(N-1)
printf(“Hello\n”);
int sum ( int v[ ], int num)
N
N k +1

i =1
i ≈ k

| k +1|
for large N and k ≠ -1 { if (num == 0) return 0;
else return v[num-1] + sum(v,num-1); }

• T(num) = constant + T(num-1)


A N +1 − 1
N N

∑ A = i

A −1
∑2
i =0
i
=2 N +1
−1 = 2*constant + T(num-2) =…= num*constant + constant
= Θ(num)
i =0

R. Rao, CSE 373 5 R. Rao, CSE 373 6

Lists, Stacks, and Queues Trees


✦ Lists: Insert, Find, Delete ✦ Terminology: Root, children, parent, path, height, depth, etc.
➭ Singly-linked lists with header node ➭ Height of a node is maximum path length to any leaf
➭ Doubly-linked and Circularly-linked ➭ Height of tree is height of root
➭ Run time and space needed for array-based versus pointer-based ➭ Single node tree has height and depth 0

✦ Stacks: Push, Pop ✦ Recursive definition of tree


➭ Know what push and pop do ➭ Null or a root node with (sub)trees as children
➭ Pointer versus array implementation
➭ Use of stacks in balancing symbols and function calls ✦ Preorder, postorder and inorder traversal of a tree
➭ Implementation using recursion or a stack
✦ Queues: Enqueue and Dequeue
➭ Array-based implementation using Rear and Front, and modulo ✦ Minimum and maximum depth of a binary tree
arithmetic for wrap-around

R. Rao, CSE 373 7 R. Rao, CSE 373 8


Binary Search Trees B-Trees
✦ BSTs: What makes a binary tree a BST? ✦ Nodes have up to M children, with M-1 keys
➭ Know how to do Find, Insert, and Delete in example BSTs ➭ Children to the right of key k contain values ≥ k

✦ AVL tree: What makes a BST an AVL tree? ✦ All leaf nodes at same height
➭ Balanced due to restriction on heights of left/right subtrees
➭ Upper bound on height of AVL tree of N nodes ✦ Know how to do Find, Insert, and Delete in example B-trees
➭ Worst case run time for operations ➭ Insert may cause leaf node to overflow and split, causing parent to
➭ Know what happens when you do Inserts into an AVL tree split etc.
➭ Re-balancing tree using Single or Double rotation ➭ Deletion may cause leaf to become less than half full, causing a
merge with sibling, which may cause parent to merge etc.
✦ Splay trees: No explicit balance condition but accessing an
item causes splaying (rotations); item moves to root ✦ What is the depth of an N-node B-tree?
➭ Find: Run time is O(depth*log M) = O(log M/2 N*log M) = O(log N)
➭ Amortized/worst case running time for operations
➭ Know what happens when you do Find/Insert/Delete ➭ Insert and Delete: Run time is O(depth*M) = O((M/log M)*log N)

R. Rao, CSE 373 9 R. Rao, CSE 373 10

Priority Queues: Binary Heaps Binomial Queues


✦ What is a binary heap? ✦ Recursive definition of binomial trees
➭ Understand array implementation – parent and children in array ➭ Contains one or more trees Bi, each containing exactly 2i nodes
➭ d-heaps: d children per node
✦ Binomial queue = forest of binomial trees, each obeying heap
✦ Main operations: FindMin, Insert, DeleteMin property
➭ Know how to Insert/DeleteMin in example binary heaps
➭ Insert – add item to end of array, then percolate up ✦ Main operation: Merge two binomial queues
➭ DeleteMin – move item at end of array to top, then percolate down ➭ Start from i = 0 and attach pairs of Bi, creating Bi+1
✦ Other operations: DecreaseKey, IncreaseKey, Merge ✦ Insert item: Merge original BQ with new one-item BQ
✦ Depth and running time of operations for binary heap of N ✦ DeleteMin: Delete smallest root node and merge its subtrees
nodes with original BQ
✦ No need to know details of leftist or skew heaps ✦ First Child/Next Sibling implementation and run time analysis

R. Rao, CSE 373 11 R. Rao, CSE 373 12


Hashing
✦ Know how hash functions work:
➭ Hash(X) = X mod TableSize
➭ TableSize is chosen to be a prime number in real-world applications
✦ Know how the different collision resolution methods work: Next Class: Midterm exam
➭ Chaining: colliding values are stored in a linked list
➭ Open addressing with linear probing: look linearly (F(i) = i) for
empty slot starting from initial hash value; clustering problem
➭ Open addressing with quadratic probing: look using squares (F(i) = To Do:
i2) for empty slot starting from initial hash value; theorem guarantees
a slot if TableSize prime and array less than half full
➭ Rehashing: when probing is used and the table starts to get full 1. Hash everything into brain but minimize collisions
✦ Know what the load factor λ of a hash table means and how 2. Ace the midterm
the run time of Find/Insert is related to λ

R. Rao, CSE 373 13 R. Rao, CSE 373 14

You might also like