l07-hash

# l07-hash - CS112: Data Structures Lecture 7 Hashing CS112:...

This preview shows pages 1–15. Sign up to view the full content.

CS112: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 7 CS112: Data Structures CS112: Data Structures Lecture 7 Hashing

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 7 Exam in 1 week Exam in 1 week Exam 1 will be held: Wednesday, June 29, 6 - 7:20 pm In our normal lecture room
CS112: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 7 Review: Trees Review: Trees Nodes (vertices) and arcs (edges) Relationships: Parent and Child D and B, D and E, B and A, etx. Root and Subtree B and {B, C, A}, D and {A, B, C, D, E, F}, etc. D A C B F E

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 7 Trees Trees Root (eg D) has no parents Leaf nodes have (A, C, and E) have no children All nodes except the root have a single parent There is exactly one path from root to any node D A C B F E
CS112: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 7 Trees Trees Height of tree Depth of a node P H Q R S I T 3 P H Q R S I T 0 1 2 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 7 Binary tree Binary tree each node has at most 2 subtrees left and right subtree Examples of binary trees 20 questions game (after animal/vegetable/mineral) Arithmetic expressions + 2 3 * + 1 4 Is it a mammal? Is it a bird? N Does it walk on 4 feet? Y It is a monkey ( 2*3 )+( 1 + 4 )
CS112: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 7 Family Tree Family Tree Source: Wikimedia Commons

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 7 Binary tree Binary tree Strict binary tree only 0 or 2 subtrees why not “only 2 subtrees”? Complete binary tree every level but last is full, last filled left-to-right + 2 3 * + 1 4 D A C B E D
CS112: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 7 Recursive Data Structures Recursive Data Structures Recursive definition of a binary tree empty (i.e. null) not empty the root a left subtree, which is a binary tree a right subtree, which is a binary tree

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 10 Lecture 7 Recursive functions Recursive functions Common form of function on a tree is recursive f(tree): if (tree = = null) return else return (data, f(tree.lst), f(tree.rst)) Where is a value and is a function
CS112: Slides for Prof. Steinberg ʼ s lecture 11 Lecture 7 Recursive functions Recursive functions height height height(tree): if (tree = = null) return -1 else return 1 + max ( height (tree.lst), height (tree.rst))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 12 Lecture 7 Recursive functions Recursive functions height height D A C B E F X 2 1 3
CS112: Slides for Prof. Steinberg ʼ s lecture 13 Lecture 7 Recursive functions Recursive functions nodeCount nodeCount nodeCount(tree): if (tree = = null) return 0 else return 1 + sum (nodeCount(tree.lst), nodeCount(tree.rst))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 14
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 11/01/2011 for the course 198 112 at Rutgers.

### Page1 / 49

l07-hash - CS112: Data Structures Lecture 7 Hashing CS112:...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online