Data Structure & Algorithm Lecture 3 –Algorithm Analysis JJCAO.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
HST 952 Computing for Biomedical Scientists Lecture 10.
2. Getting started Hsu, Lih-Hsing. Computer Theory Lab. Chapter 2P Insertion sort Example: Sorting problem Input: A sequence of n numbers Output:
ALGORITHMS Introduction. Definition Algorithm: Any well-defined computational procedure that takes some value or set of values as input and produces some.
25 May Quick Sort (11.2) CSE 2011 Winter 2011.
the fourth iteration of this loop is shown here
What is an Algorithm? (And how do we analyze one?)
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 3 Growth of Functions
Analysis of Algorithms intro.  What is “goodness”?  How to measure efficiency? ◦ Profiling, Big-Oh  Big-Oh: ◦ Motivation ◦ Informal examples ◦ Informal.
Introduction to Analysis of Algorithms
CSE 830: Design and Theory of Algorithms
CSE 830: Design and Theory of Algorithms
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
CSE 830: Design and Theory of Algorithms Dr. Eric Torng.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
CS Main Questions Given that the computer is the Great Symbol Manipulator, there are three main questions in the field of computer science: What kinds.
What is an Algorithm? (And how do we analyze one?) COMP 122, Spring 04.
Data Structure Algorithm Analysis TA: Abbas Sarraf
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Sorting Chapter 6 Chapter 6 –Insertion Sort 6.1 –Quicksort 6.2 Chapter 5 Chapter 5 –Mergesort 5.2 –Stable Sorts Divide & Conquer.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Algorithm Analysis (Big O)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
Lecture 2 Computational Complexity
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Jessie Zhao Course page: 1.
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.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Introduction to Analysis of Algorithms COMP171 Fall 2005.
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.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Time Complexity of Algorithms (Asymptotic Notations)
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Algorithm Analysis Part of slides are borrowed from UST.
Sorting.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Algorithm Analysis (Big O)
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
CMPT 438 Algorithms.
Algorithm Analysis CSE 2011 Winter September 2018.
Course Description Algorithms are: Recipes for solving problems.
CS 3343: Analysis of Algorithms
Algorithm Analysis (not included in any exams!)
Algorithm design and Analysis
CSC 413/513: Intro to Algorithms
Introduction to Algorithms Analysis
CS 201 Fundamental Structures of Computer Science
Ch. 2: Getting Started.
Course Description Algorithms are: Recipes for solving problems.
Presentation transcript:

Data Structure & Algorithm Lecture 3 –Algorithm Analysis JJCAO

Recitation - Dynamic Array Start with an array of size 1, and double its size from m to 2m each time we run out of space. How many times will we double for n elements? – Only … + 2^i =2^{i+1}=n => i = log(n) How many times of copy happened?

Recitation - Linked list 以下链表中,不存在 NULL 的是 (In linked lists there are no NULL links in): A. 单链表 Single linked list B. 双链表 Linear doubly linked list C. 循环链表 Circular linked list D. 以上皆否 None of above 3

Recitation - A Circular Queue 4 Write a pseudo code for any of the following operations:

Recitation - Bubble Sort 5 for i = 1:n, swapped = false for j = n:i+1, if a[j] < a[j-1], swap a[j,j-1] swapped = true break if not swapped end

Analyzing an Algorithm Predicting the resources the algorithm requires Resources: Memory Communication Bandwidth Logic Gates Computation Time 6

Evaluating an algorithm 7

Processing time is surely a bad measure!!! We need a ‘stable’ measure, independent of the implementation. 8

Insertion Sort 9 nnnnnnnn

Insertion Sort - Best Case 10

Insertion Sort - Worst Case 11

Insertion Sort – Average Case 12

Worst-Case Complexity The worst case complexity of an algorithm is the function defined by the maximum number of steps taken on any instance of size n. 13

Best-Case & Average-Case Complexity The best case complexity of an algorithm is the function defined by the minimum number of steps taken on any instance of size n. The average-case complexity of the algorithm is the function defined by an average number of steps taken on any instance of size n. Each of these complexities defines a numerical function: time vs. size! 14

Worst Case Running Time Gives upper bound on running time for any input. A guarantee that the algorithm never takes longer. For some applications, worst case happens often Example: Searching a data base for missing information Average case is often roughly as bad as w.c. Example: Insertion Sort, both O(n^2) 15

16

The RAM Model of Computation RAM: Random Access Machine 1.Each simple operation (+, -, =, if, call) takes 1 step. 2.Loops and subroutine calls are not simple operations. They depend upon the size of the data and the contents of a subroutine. “Sort” is not a single step operation. 3.Each memory access takes exactly 1 step. For a given problem instance: Running time of an algorithm = #RAM steps Useful abstraction => allow us to analyze algorithms in a machine-independent fashion. 17

Exact Analysis is Hard! 18

Order of Growth We are interested in the type of function the running time was, not the specific function (linear, quadratic,…) Really interested only in the leading terms Mostly interested only in the Rate of Growth of the leading terms ⇒ ignore constant coefficients 19

Which Function Grows Faster? 20

Which Function Grows Faster? 21

Which Function Grows Faster? 22

Big Oh notation Upper Bound on Running Time 23

Big-Oh - Example 24

25

26

27

28

Useful Properties 29

30

Proof by Induction Failure to find a counterexample to a given algorithm does not mean “it is obvious” that the algorithm is correct. Mathematical induction is a very useful method for proving the correctness of recursive algorithms. Recursion and induction are the same basic idea: 1.basis case 2.general assumption 3.general case. 31

Proof by Contradiction Lets assume that we would like to prove a claim, Claim1 Structure of proof: – Assume that Claim1 is incorrect – Show that this assumption leads to a contradiction – The contradiction should be either to assumptions made in the claim, or to well- known mathematical facts (e.g., 0=1) 32

Homework 2 Efficient Dynamic Array & Insertion Sort Deadline: 22:00, Sep. ?,