Document Sample

1 CompSci 105 SS 2005 Principles of Computer Science Test Tomorrow. Lecture 16: Searching and Sorting (Thursday) Lecturer: Santokh Singh 2 Array Implementation 0 1 2 3 4 5 6 7 items: 3 5 1 front: 0 back: 2 Textbook, pp. 306ff 3 “Circular Array” 7 0 items: 3 6 1 5 front: 0 1 back: 2 5 2 4 3 Java Code, Textbook, pp. 310ff 4 Linked List Implementation 3 5 1 firstNode lastNode Textbook, pp. 302ff, 5 Circular Linked List 3 5 1 lastNode Java code, textbook, pp. 305ff, 6 ADT List Implementation 1. 1 2. 5 3. 3 4. 5. 6. Java Code, Textbook, pp. 263ff 7 Algorithm Efficiency Challenges in Measuring Efficiency Counting Operations Growth Rates of Functions Big O Notation Examples General Rules 8 Algorithm Efficiency Challenges in Measuring Efficiency Counting Operations Growth Rates of Functions Big O Notation Examples General Rules 9 Node curr = head; while (curr != null ) { System.out.println( curr.getItem() ); curr = curr.getNext(); } Textbook, p. 374 10 Rate of Growth x+ny time n 11 for ( i=1 to n ) { for ( j=1 to n ) { for ( k=1 to 5 ) { Task T } } } 12 Rate of Growth n2 z time n 13 Rate of Growth n2 z x+ny time n 14 Algorithm Efficiency Challenges in Measuring Efficiency Counting Operations Growth Rates of Functions Big O Notation Examples General Rules 15 Big O Notation “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than k * f(n) time units to solve a problem of size n ≥ n0” - Textbook, p. 376 16 Big O Notation “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than k * f(n) time units to solve a problem of size n ≥ n0” - Textbook, p. 376 17 Big O Notation “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than k * f(n) time units to solve a problem of size n ≥ n0” - Textbook, p. 376 Worst Case 18 Big O Notation “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than k * f(n) time units to solve a problem of size n ≥ n0” - Textbook, p. 376 Worst Case Large Problems 19 “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than Rate of Growth k * f(n) time units to solve a problem of size n ≥ n0” n2 z x+ny time n Book Computes k and n0 exactly, p. 377 20 “An Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than Rate of Growth k * f(n) time units to solve a problem of size n ≥ n0” n2 z kn x+ny time n Book Computes k and n0 exactly, p. 377 21 for ( i=1 to n ) { for ( j=1 to n ) { for ( k=1 to 5 ) { Task T } } } 22 for ( i=1 to n ) { for ( j=1 to i ) { for ( k=1 to 5 ) { Task T } } } Textbook, p. 374-5, 377 23 O Notation Tricks • Ignore “low-order” terms • Ignore Constants • Can combine O()’s Textbook, p. 380 24 Comparing Growth Rates O(n2) Faster Faster Growth O(n) Code Textbook, p. 378 25 Comparing Growth Rates O(n2) Faster Faster Growth O(n) Code O(1) Textbook, p. 378 26 Comparing Growth Rates O(2n) O(n2) Faster Faster Growth O(n) Code O(log n) O(1) Textbook, p. 378 27 Comparing Growth Rates O(2n) O(n3) O(n2) Faster O(n log n) Faster Growth O(n) Code O(log n) O(1) Textbook, p. 378

DOCUMENT INFO

Shared By:

Categories:

Tags:

Stats:

views: | 1 |

posted: | 2/27/2012 |

language: | |

pages: | 27 |

OTHER DOCS BY gegeshandong

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.