03 Asymptotics and Recurrences

# 03 Asymptotics and Recurrences - Analyzing Algorithms:...

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

Analyzing Algorithms: Asymptotic Analysis and Recurrences 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 19 January 2010 Reading for today: Chapter 5 and 8.5

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

View Full Document
2 Announcements HW 0 theory questions due now Programming due tonight by 11:59 PM HW 1 should be out today Abstract Syntax Trees JUnit in recitation tomorrow Bring your laptops! Academic Development peer tutoring Mudge Library, Tuesdays and Thursdays from 8:30 - 11 p.m.
3 Last time…The Union-Find Problem Two operations for disjoint sets: Find(x) : Given item x find the set containing x Union(x,y) : Merge sets containing x and y Two tricks for good performance: Union-by-rank: Link smaller tree to other root Path compression: Redirect links to the root Amortized analysis O( m log n ) with Union-by- rank O( m* (m,n) ) with both Union-by-rank and path compression

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

View Full Document
4 Today: Analyzing algorithms Asymptotic analysis How is analyzing algorithms like Ghostbusters ? Recurrence relations Substitution method Iteration method Master method
5 Quantifying time complexity Suppose I want to find if an array A contains a certain item k : Consider: containsItem([4,2,6,3,9], 10) containsItem([11,2,25,2,8,7,3,1,9,33], 10) containsItem([10,24,5,9,1,78,23,31,99], 10) public boolean containsItem(int[] A, int k) { int n = A.length; for (int i = 0; i < n; i++) if (A[i] == k) return true; return false; }

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

View Full Document
6 Quantifying time complexity containsItem([a 0 , a 1 , …, a n-1 ], k) Worst-case for a particular problem size Counting steps, not wall-clock time Denoted T(n) , for inputs of size n public boolean containsItem(int[] A, int k) { int n = A.length; for (int i = 0; i < n; i++) if (A[i] == k) return true; return false; }
7 Selecting the best algorithm, part 1 Graph image source: wikipedia T 1 (n) = n 3 -1 2n 2 + 20n + 110 T 2 (n) = n 3 + n 2 + 5n + 5 Input size ( n ) T(n)

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

View Full Document
8 For larger inputs… Graph image source: wikipedia T 1 (n) = n 3 -1 2n 2 + 20n + 110 T 2 (n) = n 3 + n 2 + 5n + 5 Input size ( n ) T(n)
9 For even larger inputs… Graph image source: wikipedia T 1 (n) = n 3 -1 2n 2 + 20n + 110 T 2 (n) = n 3 + n 2 + 5n + 5 Input size ( n ) T(n)

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

View Full Document
10 Selecting the best algorithm, part 2
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 05/10/2011.

### Page1 / 50

03 Asymptotics and Recurrences - Analyzing Algorithms:...

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

View Full Document
Ask a homework question - tutors are online
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}