1 CS 177 Week 12 Recitation Slides Running Time and Performance.

Slides:



Advertisements
Similar presentations
Data Structures Static and Dynamic.
Advertisements

Announcements You survived midterm 2! No Class / No Office hours Friday.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Fundamentals of Python: From First Programs Through Data Structures
Complexity Theory  Complexity theory is a problem can be solved? Given: ◦ Limited resources: processor time and memory space.
CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Algorithm Analysis (Big O) CS-341 Dick Steflik. Complexity In examining algorithm efficiency we must understand the idea of complexity –Space complexity.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Heapsort. 2 Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n) Quicksort.
Data Structures Performance Analysis.
Cmpt-225 Algorithm Efficiency.
CS503: First Lecture, Fall 2008 Michael Barnathan.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
1 Algorithms and Analysis CS 2308 Foundations of CS II.
Sorting Algorithms and Analysis Robert Duncan. Refresher on Big-O  O(2^N)Exponential  O(N^2)Quadratic  O(N log N)Linear/Log  O(N)Linear  O(log N)Log.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CIS 068 Welcome to CIS 068 ! Lesson 9: Sorting. CIS 068 Overview Algorithmic Description and Analysis of Selection Sort Bubble Sort Insertion Sort Merge.
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Lecture 2 Computational Complexity
Oct 29, 2001CSE 373, Autumn External Storage For large data sets, the computer will have to access the disk. Disk access can take 200,000 times longer.
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Heapsort CSC Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n)
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Sorting with Heaps Observation: Removal of the largest item from a heap can be performed in O(log n) time Another observation: Nodes are removed in order.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
CSC 205 Java Programming II Algorithm Efficiency.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
1 CS 350 Data Structures Chaminade University of Honolulu.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
MA/CSSE 473 Day 27 Hash table review Intro to string searching.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Apr 17, 2013 Persistent Data Structures. Definitions An immutable data structure is one that, once created, cannot be modified Immutable data structures.
1 Week 9 A little more GUI, and threads. Objectives: Discuss the Swing set of classes. Incorporate animation into applets. Define the term thread. Explain.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
MS 101: Algorithms Instructor Neelima Gupta
1 Today’s Material Iterative Sorting Algorithms –Sorting - Definitions –Bubble Sort –Selection Sort –Insertion Sort.
Sorting – Insertion and Selection. Sorting Arranging data into ascending or descending order Influences the speed and complexity of algorithms that use.
Chapter 12 Binary Search and QuickSort Fundamentals of Java.
MA/CSSE 473 Day 23 Student questions Space-time tradeoffs Hash tables review String search algorithms intro.
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Week 12 - Friday.  What did we talk about last time?  Finished hunters and prey  Class variables  Constants  Class constants  Started Big Oh notation.
CS321 Data Structures Jan Lecture 2 Introduction.
Static block can be used to check conditions before execution of main begin, Suppose we have developed an application which runs only on Windows operating.
Data Structures and Algorithms in Java AlaaEddin 2012.
CS321 Spring 2016 Lecture 3 Jan Admin A1 Due this Friday – 11:00PM Thursday = Recurrence Equations – Important. Everyone Should be added to class.
21-Feb-16 Analysis of Algorithms II. 2 Basics Before we attempt to analyze an algorithm, we need to define two things: How we measure the size of the.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Applied Discrete Mathematics Week 2: Functions and Sequences
Introduction to Analysis of Algorithms
Data Searching and Sorting algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
Comparing Algorithms Unit 1.2.
CS 201 Fundamental Structures of Computer Science
Applied Discrete Mathematics Week 6: Computation
Searching CLRS, Sections 9.1 – 9.3.
Algorithmic Complexity
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Searching, Sorting, and Asymptotic Complexity
The Study of Computer Science
Presentation transcript:

1 CS 177 Week 12 Recitation Slides Running Time and Performance

2 Announcements Project 5 is due Thursday, April 29

3 QUESTIONS???

Algorithm Design Get the right answer  Obviously, the most important thing Use a reasonable amount of memory  Not so important because of the rapidly growing memory sizes  But we still only have limited resources, esp. small electronic devices like cell phones have very limited memory Run as quickly as possible  0.1 sec and 0.3 sec make little difference  What about 10 min and 30 min?  10 years and 30 years?

Data Structure In early days, algorithm + data structure = program Although not really these days, they are still the most important parts of programs The graph is a typical and extremely useful data structure Actually data structures are everywhere: strings, arrays, linked lists, classes There are more complicated data structures like trees and hash tables which you will learn later

O Big Oh analysis is not precise estimation It only gives an idea how slow the program will become when n is larger and larger A simple way to determine the Big Oh value is to check the number of embedded loops for x = 1..n for y = 1..n O(n 2 ) for x = for y = O(1) for x = 1..n 3 for y = 1..n 0.5 for z = 1..n O(n 4.5 )

Sorting In general, sorting algorithms are O(n 2 ) because they typically involve comparing each value to each other value (a loop inside a loop) to get each value into the proper position. (like bubble sort) But the best sorting algorithms are O(n logn). (like quick sort) It makes difference when n is large enough. For example, 1 million.

Runtime Analysis It’s also possible to test your program’s performance by running it many times. It’s hard to get the exact Big Oh value (why?) but you can get a curve about how rapidly your program slows down when the data size increases  Because Big Oh is not precise, especially when n is not big enough You can learn more sophisticated ways to do run time analysis in algorithm courses

Space Analysis Usually, the memory sizes nowadays are sufficient for you program. However, sometimes, the space cost is extremely large.  What about sorting all bytes in your hard drive? Before you start designing “fast” algorithms, please consider the space cost first Java is convenient for its garbage collector, which saves you a lot of effort by helping clean useless objects, arrays, etc. Sometimes, there’s a tradeoff between time and space.

Example for Algorithm Design Search an integer in a sorted array of integers with ascending order Obvious solution: check the integers one by one until you find the wanted one  Time cost: O(n)  Space cost: O(n) Better solution: binary search  Time cost: O(log n) (why?)  Space cost: O(n)

11 Final QUESTIONS???