l06-trees

# l06-trees - CS112 Data Structures Lecture 06 Add Delete...

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

CS112: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 6 CS112: Data Structures CS112: Data Structures Lecture 06 Add / Delete / Search Trees

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 6 Review: Add / Delete / Search Review: Add / Delete / Search Basic task: Set of data items E.g. “Al”, “Bob”, “Cindy” Operations: Add an item Delete an item Search for an item Goal: minimize worst case O(add + delete + search)
CS112: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 6 Unordered Array Unordered Array 0 Carol 1 Anne 2 Bob 3 4 numberOfNames 3 0 Carol 1 Anne 2 Bob 3 Alice 4 numberOfNames 4 Add Alice

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 6 Unordered Array Unordered Array 0 Carol 1 Anne 2 Bob 3 Alice 4 numberOfNames 4 0 Carol 1 Alice 2 Bob 3 Alice 4 numberOfNames 3 Remove Anne
CS112: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 6 Unordered Array Unordered Array Insert O(1) if there’s space Delete O(1) (move last element) Search O(n) where n is size of set Overall O(n)

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 6 Ordered Array Ordered Array 0 Anne 1 Bob 2 Carol 3 4 numberOfNames 3 Add Alice 0 Alice 1 Anne 2 Bob 3 Carol 4 numberOfNames 4
CS112: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 6 Ordered Array Ordered Array Remove Anne 0 Alice 1 Anne 2 Bob 3 Carol 4 numberOfNames 4 0 Alice 1 Bob 2 Carol 3 4 numberOfNames 3

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 6 Searching an ordered array Searching an ordered array Binary search Binary search requires sorted values each comparison rules out half of the remaining elements O(log(n)) - we will prove this later Find A, find R A D E F G H J M P T ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ 0 1 2 3 4 5 6 7 8 9
CS112: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 6 Searching an array Searching an array Performance Performance Search among 1 B illion entries Check 1 million entries per second Sequential search 1 billion operations needed Requires 1000 seconds - about 20 minutes Binary search 30 operations needed Requires 30 microseconds 30 million times faster

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 6 Searching an array Searching an array Performance Performance Search among 1 M illion entries Check 1 million entries per second Sequential search 1 million operations needed Requires 1 second Binary earch 20 operations needed Requires 20 microseconds 50,000 times faster
CS112: Slides for Prof. Steinberg ʼ s lecture 11 Lecture 6 Searching + Insert Searching + Insert Performance Performance 1 billion entries, process 1 million/sec Insert O(n) 1 billion operations needed Requires 1000 seconds - about 20 minutes Binary search O(log n) 30 operations needed Requires 30 microseconds Together: 1000.00003 seconds

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

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture
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 / 55

l06-trees - CS112 Data Structures Lecture 06 Add Delete...

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

View Full Document
Ask a homework question - tutors are online