CSC317 1 Recap: Oh, Omega, Theta Oh (like ≤) Omega (like ≥) Theta (like =) O(n) is asymptotic upper bound 0 ≤ f(n) ≤ cg(n) Ω(n) is asymptotic lower bound.

Slides:



Advertisements
Similar presentations
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Advertisements

Divide-and-Conquer CIS 606 Spring 2010.
Analysis of Algorithms
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
5/5/20151 Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Divide and Conquer Strategy
5/15/ Algorithms1 Algorithms – Ch4 - Divide & Conquer Recurrences: as we saw in another lecture, the Divide and Conquer approach leads to Recurrence.
CS4413 Divide-and-Conquer
A Basic Study on the Algorithm Analysis Chapter 2. Getting Started 한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님 1.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Spring 2015 Lecture 5: QuickSort & Selection
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Chapter 1 – Basic Concepts
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Asymptotic Growth Rate
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (1) Asymptotic Complexity 10/28/2008 Yang Song.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
1 Divide and Conquer Binary Search Mergesort Recurrence Relations CSE Lecture 4 – Algorithms II.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Asymptotic Notations Iterative Algorithms and their analysis
C. – C. Yao Data Structure. C. – C. Yao Chap 1 Basic Concepts.
David Luebke 1 10/3/2015 CS 332: Algorithms Solving Recurrences Continued The Master Theorem Introduction to heapsort.
CS 3343: Analysis of Algorithms
Iterative Algorithm Analysis & Asymptotic Notations
10/13/20151 CS 3343: Analysis of Algorithms Lecture 9: Review for midterm 1 Analysis of quick sort.
2IL50 Data Structures Fall 2015 Lecture 2: Analysis of Algorithms.
Project 2 due … Project 2 due … Project 2 Project 2.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
Asymptotic Analysis-Ch. 3
10/25/20151 CS 3343: Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
1 Chapter 4 Divide-and-Conquer. 2 About this lecture Recall the divide-and-conquer paradigm, which we used for merge sort: – Divide the problem into a.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Analysis of Algorithms1 O-notation (upper bound) Asymptotic running times of algorithms are usually defined by functions whose domain are N={0, 1, 2, …}
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Midterm Review 1. Midterm Exam Thursday, October 15 in classroom 75 minutes Exam structure: –TRUE/FALSE questions –short questions on the topics discussed.
CSC 413/513: Intro to Algorithms Solving Recurrences Continued The Master Theorem Introduction to heapsort.
2IS80 Fundamentals of Informatics Fall 2015 Lecture 5: Algorithms.
Spring 2015 Lecture 2: Analysis of Algorithms
Asymptotic Analysis CSE 331. Definition of Efficiency An algorithm is efficient if, when implemented, it runs quickly on real instances Implemented where?
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
2IL50 Data Structures Spring 2016 Lecture 2: Analysis of Algorithms.
Asymptotic Notation Faculty Name: Ruhi Fatima
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
1 Section 5.6 Comparing Rates of Growth We often need to compare functions ƒ and g to see whether ƒ(n) and g(n) are about the same or whether one grows.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Introduction to Algorithms: Asymptotic Notation
Analysis of Algorithms
Growth of functions CSC317.
CS 3343: Analysis of Algorithms
O-notation (upper bound)
CS 3343: Analysis of Algorithms
Analysis of Algorithms
Advanced Analysis of Algorithms
CS200: Algorithms Analysis
O-notation (upper bound)
David Kauchak cs161 Summer 2009
Advanced Analysis of Algorithms
Analysis of Algorithms
Presentation transcript:

CSC317 1 Recap: Oh, Omega, Theta Oh (like ≤) Omega (like ≥) Theta (like =) O(n) is asymptotic upper bound 0 ≤ f(n) ≤ cg(n) Ω(n) is asymptotic lower bound 0 ≤ cg(n) ≤ f(n) Θ(n) is asymptotic tight bound 0 ≤ c 1 g(n) ≤ f(n) ≤ c 2 g(n)

CSC317 2 More on Oh, Omega, Theta Theorem: f(n) = Θ(n) if and only if (iff) f(n) = O(n) and f(n) = Ω(n) Question: Is f(n) = n Ω(n 3 ) ? Answer: NO (why?)!

CSC317 3 Question: Is f(n) = n Ω(n 3 ) ? Answer: NO! Proof by contradiction Definition: Ω (g(n)) = f(n) : There exist positive constants c, such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n 0 If f(n) = Ω(n 3 ), then there exists n 0 ; c such that for all n ≥ n 0 Therefore: n ≥ cn 3 Remember from before: n 2 + 5n 2 ≥ n n 2 + 5n 2 ≥ cn 3 6 ≥ cn Can’t be true for all n ≥ n 0

CSC317 4 Some properties of Oh, Omega, Theta Transitivity: f(n) = Θ(g(n)) and g(n) = Θ(h(n)) then f(n) = Θ(h(n)) (same for O and Ω?) Reflexivity: f(n) = Θ(f(n)) (same for O and Ω?) Symmetry: f(n) = Θ(g(n)) iff g(n) = Θ(f(n)) (same for O and Ω?)

CSC317 5 Final thoughts: Oh, Omega, Theta Useful comparison formula of functions in book (section3.2)

CSC317 6 What kind of recurrences arise in algorithms and how do we solve more generally (than what we saw for merge sort)? More recurrence examples Run time not always intuitive, so need tools Divide and Conquer approach Max Subarray Problem: Can buy stock once, sell stock once. Want to maximize profit; allowed to look into the future

CSC317 7 Max Subarray Problem: Can buy stock once, sell stock once. Want to maximize profit; allowed to look into the future Buy low, sell high … Buy Sell

CSC317 8 Brute force: Try every possible pair of buy and sell dates Hmm, can we do better?

CSC317 9 Let’s reframe the problem as greatest sum of any contiguous array Efficiency? Still brute force Divide and conquer anybody?

CSC Where could max subarray be? middle lowhigh middle lowhigh iiijjj

CSC Where could max subarray be? middle lowhigh 1.DIVIDE chop subarray in two equal subarrays A[low,…,middle] and A[middle+1,..., high] 2. CONQUER find max of subarrays A[low,…,middle] and A[middle+1,..., high] 3. COMBINE find the best solution of: a. the two solutions found in conquer step b. solution of subarray crossing the midpoint

CSC DIVIDE chop subarray in two equal subarrays A[low,…,middle] and A[middle+1,..., high] 2. CONQUER find max of subarrays A[low,…,middle] and A[middle+1,..., high] 3. COMBINE find the best solution of: a. the two solutions found in conquer step b. solution of subarray crossing the midpoint Keep recursing until low=high (one element left) middle lowhigh ij

CSC middle lowhigh ij Start from the middle Go to the left until hit max sum. Go to the right until hit max sum. Return total left and right sum. COMPLEXITY? Θ(n)

CSC float recmax(int l, int u) if (l > u) /* zero elements */ return 0; if (l == u) /* one element */ return max(0, A[l]); m = (l+u) / 2; /* find max crossing to left */ lmax = sum = 0; for (i = m; i ≥ l; i--) { sum += A[i]; if (sum > lmax) lmax = sum; } /* find max crossing to right */ rmax = sum = 0; for (i = m+1; i ≤ u; i++) { sum += A[i]; if (sum > rmax) rmax = sum; } return max(max(recmax(l, m), recmax(m+1, u)), lmax + rmax);

CSC COSTS: 1.DIVIDE 2.CONQUER 3.COMBINE T = Θ(1) T = 2T(n/2) T = Θ(n)+Θ(1) Subarray crossing comparison TOTAL : T(n) = 2T(n/2) + Θ(n) = Θ(n log n) Merge sort anyone?

CSC CLASSICAL EXAMPLE: MATRIX MULTIPLICATION Run time: O(n 3 ) in the naïve implementation 1. n = A.rows 2. Let C be a new n by n matrix 3. for i=1 to n 4. for j=1 to n 5. cij = 0 6. for k=1 to n 7. cij = cij+ aik bkj 8. return C Can we do better?