CSS 342 Data Structures, Algorithms, and Discrete Mathematics I

Slides:



Advertisements
Similar presentations
CSE Lecture 3 – Algorithms I
Advertisements

Discrete Structures CISC 2315
Lecture: Algorithmic complexity
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 10 Algorithm Efficiency
Complexity Analysis (Part II)
Cmpt-225 Algorithm Efficiency.
1 Algorithm Efficiency, Big O Notation, and Role of Data Structures/ADTs Algorithm Efficiency Big O Notation Role of Data Structures Abstract Data Types.
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Analysis of Algorithms
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms Analysis of algorithms.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Asymptotic Analysis-Ch. 3
CSS342: Algorithm Analysis1 Professor: Munehiro Fukuda.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
3.3 Complexity of Algorithms
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Foundations of Algorithms, Fourth Edition
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CHAPTER 11.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
CS 302 Data Structures Algorithm Efficiency.
Chapter 2 Algorithm Analysis
Mathematical Foundation
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Introduction to Algorithms
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Big-Oh and Execution Time: A Review
Algorithm design and Analysis
Programming and Data Structure
Algorithm Efficiency and Sorting
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Discrete Mathematics CS 2610
Algorithm Efficiency: Searching and Sorting Algorithms
Chapter 2.
Algorithm Efficiency Chapter 10
Programming and Data Structure
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Searching, Sorting, and Asymptotic Complexity
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
8. Comparison of Algorithms
At the end of this session, learner will be able to:
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
Complexity Analysis (Part II)
Estimating Algorithm Performance
Analysis of Algorithms
Algorithm Efficiency and Sorting
Presentation transcript:

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I Lecture 13. 11/15/2016. CARRANO CHAPT 10

Agenda Big O notation. Lab4 Intro. Midterms Returned

Algorithm Efficiency BIG O

Analysis and Big O Notation 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 all sizes n ≥ n0 Big O is upper-bound, not tight upper bound Algorithm A grows no faster than O(n) Tight upper bound is Big Theta Θ However, it is often abused in CS to mean the tight upper bound

Proving an algorithm / code snippet is O( f(n) ) Determine a formula for the number of important operations in algorithm or snippet as a function of n. Express this as g(n). Show there is a constant, k, such that k * f(n) > g(n) for all n greater than some number. You have proven g(n) is O(f(n)) Rejoice!

BigO: pop quiz If func2() is O(1), what is the bigO of the code snippet? for (int i = -n; i < n; i++) { func(i); } int func(int a) { int b = 0; for (int i = 0; i < a; i++) b += func2(i*i); } return b;

Intuitive interpretation of growth-rate functions Constant Independent of problem size O(log2n) Logarithmic Increase slowly as size increases. Ex. Binary search O(n) Linear Increase directly with size. Searching an unsorted list or malformed tree. O(nlog2n) Increase more rapidly than a liner algorithm. Ex. Merge sort O(n2) Quadratic Ex. Two nested loops; bubble sort O(n3) Cubic Ex. Three nested loops O(2n) Exponential Increase too rapidly to be practical CSS342: Algorithm Analysis

Analysis and Big O Notation FIGURE 10-3 A comparison of growth-rate functions: (a) in tabular form Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Analysis and Big O Notation Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Empirical Overview of Efficiency* All algorithms take approximately same time for N = 10 Any algorithm with N! running time is useless for N ≥ 20 2N is intractable for n ≥ 40 O(N2) is usable for N = 10,000 but horrendous for N ≥ 1,000,000 O(N) and O(N log N) are practical for inputs of size 1,000,000,000 O(log N) was okay for any input size *From “The Algorithm Design Manual”

Big O Simplifications O(f(n)) + O(g(n)) = O(f(n) + g(n)) Focus on the dominant factor: Low-order terms can be ignored O(n3+4n) = O(n3) Multiplicative constant in the high-order term can be ignored. O(3n3+4) = O(n3) O(f(n)) + O(g(n)) = O(f(n) + g(n)) If f(n) = O(g(n)) and g(n) = O(h(n)) , then f(n)=O(h(n))

Worst, Best, and Average-case Analysis Worst-case analysis: Algorithm A requires no more than k * f(n) time units. It might happen rarely, if at all, in practice. Best-case analysis: Like worst-case analysis, it might happen rarely. Average-case analysis: A requires no more than k * f(n) time units for all but a finite number of values of n Difficulties: determining probability and distribution of size n and input data

Efficiency of Sequential Search 29 10 14 37 13 52 46 75 5 43 21 69 88 1 Hit! Best case O(1) Hit! Worst case O(n) Hit! Average case O(n/2) = O(n)

Lab4 Sorting

Complexity of Binary Search low =0 mid = (15 + 0)/2 = 7 high=15 10 a 1 5 10 13 14 21 29 37 43 46 52 69 75 88 91 99 new high=7–1=6 int binarySearch( const vector<int> &a, const int x ) { int low = 0; int high = a.size( ) – 1; int mid; while ( low <= high ) { mid = ( low + high ) / 2; if ( a[mid] < x ) low = mid + 1; else if ( a[mid] > x ) high = mid – 1; else return mid; } return NOT_FOUND; // NOT_FOUND = -1 Write code for binary search

1 5 10 13 14 21 29 37 43 46 52 69 75 88 91 99 1st step 2nd step 3rd step Hit! DATA SIZE #Recursive Calls N = 2 1 N = 4 2 N = 8 3 N = 16 4 N = 2k K 2K < N < 2K+1 K+1 K < log2N < K+1 O(log2N) 4th step

Big-O complexity. Lab3 + operator on two lists Merge operator What was your efficiency? Call insert on each element? One list after the other? Merge operator BuildList Operator

Minimum Element in an Array Given an array of N items, find the smallest item. What order (in big O) will this problem be bound to? 1 N 3 9 1 8 5 2 7 4 6 -1 10 -2

Closest Points in the Plane Given N points in a plane (that is, an x-y coordinate system), find the pair of points that are closest together. What order (in big O) will this problem be bound to? y sqrt( (x2 – x1)2 + (y2 – y1)2 ) 2,1 1,4 1,6 4,5 4,7 5,4 5,6 6,3 6,7 7,1 x 8,4

nlogn solution Sort input array by x cords Find the middle point P[n/2] Divide array into two halves: PL and PR Recursively find the min in each array, distL and distR. Let dist = min(distL, distR)

Nlogn solution dist is an upper bound on distance. Need to consider pairs of points one in PL and one in PR . But we do not need to consider points outside this . Build array s whose x coord is close to middle line at P[n/2] Sort the array s by y coord; for each point in strip we need to check only 7 points (beyond scope, but see this: http://people.csail.mit.edu/indyk/6.838-old/handouts/lec17.pdf

Computer Scientist of the week (very difficult…. possibly NP-Complete) Stephen Cook Forefather of computational complexity theory Theory of NP-Completeness Prof. at University of Toronto Proposed P = NP problem 1982: Turing award winner

Intractable, Unsolvable, and NP problems Tractable problems Their worst-case time is proportional to a polynomial (class P) on a deterministic machine However, sometimes this can take a long time Intractable problems Their worst-case time cannot be bounded to a polynomial. Unsolvable algorithms: They have no algorithms at all. Example: Turing’s Halting problem NP(Non-Deterministic Polynomial Time) problems No solution with Polynomial worst-case performance (on a deterministic machine), but when solved can be checked polynomial time There is a solution on a non-deterministic machine Traveling Salesperson problem NP-Complete Problems Class of problems that are NP Poly-time reducible to another NP complete problem Ex, Traveling salesperson problem https://en.wikipedia.org/wiki/List_of_NP-complete_problems

More BigO? http://courses.washington.edu/css342/dimpsey/ProgramExamples/BigOwAnswers.pdf

Midterm Median: 71

Grades Review Labs (5): 35% Exams/Quizzes: 65% http://www.uwb.edu/registration/policies/grading/grading-ug

Midterm SCORE GRADE 86-100 3.5-4 68-85 2.5-3.4 60-67 2.0-2.4 <60 <2.0