CS 3343: Analysis of Algorithms

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

1 ICS 353 Design and Analysis of Algorithms Spring Semester (062) King Fahd University of Petroleum & Minerals Information & Computer Science.
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.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
12.2: Analyze Arithmetic Sequences and Series HW: p (4, 10, 12, 14, 24, 26, 30, 34)
Geometric Sequences and Series
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
1 ©2008 DEEDS Group Introduction to Computer Science 2 - SS 08 Asymptotic Complexity Introduction in Computer Science 2 Asymptotic Complexity DEEDS Group.
Mathematics Review and Asymptotic Notation
CS 3343: Analysis of Algorithms
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
10/13/20151 CS 3343: Analysis of Algorithms Lecture 9: Review for midterm 1 Analysis of quick sort.
CS223 Advanced Data Structures and Algorithms 1 Sorting and Master Method Neil Tang 01/21/2009.
Analysis of Algorithms
Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
2-0 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 2 Theoretical.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
Arithmetic and Geometric Sequences. Determine whether each sequence is arithmetic, geometric, or neither. Explain your reasoning. 1. 7, 13, 19, 25, …2.
Lecture 4 Jianjun Hu Department of Computer Science and Engineerintg University of South Carolina CSCE350 Algorithms and Data Structure.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Algorithm Analysis 1.
CMPT 438 Algorithms.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Arithmetic and Geometric Sequences.
Theoretical analysis of time efficiency
Analysis of Algorithms
Analysis of Algorithms
Geometric Sequences and Series
CSC 427: Data Structures and Algorithm Analysis
CS 3343: Analysis of Algorithms
Introduction to the Design and Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Introduction to Algorithms
Introduction Algorithms Order Analysis of Algorithm
CS 3343: Analysis of Algorithms
Analysis of algorithms
Randomized Algorithms
CS 213: Data Structures and Algorithms
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Analysis of Algorithms
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Sequences and Series Arithmetic Sequences Alana Poz.
Randomized Algorithms
Introduction to Algorithms Analysis
Algorithms + Data Structures = Programs -Niklaus Wirth
CS 3343: Analysis of Algorithms
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
CSE 373 Data Structures Lecture 5
Mathematical Analysis of Non- recursive Algorithm PREPARED BY, DEEPA. B, AP/ CSE VANITHA. P, AP/ CSE.
CS 3343: Analysis of Algorithms
Mathematical Background 2
CS 332: Algorithms Quicksort David Luebke /9/2019.
At the end of this session, learner will be able to:
Analysis of algorithms
Module 3 Arithmetic and Geometric Sequences
Estimating Algorithm Performance
Warm Up Write the first 4 terms of each sequence:
Analysis of Algorithms
Presentation transcript:

CS 3343: Analysis of Algorithms Analyzing non-recursive algorithms 11/28/2018

True or false? 2n2 + 1 = O(n2) T (also ) Sqrt(n) = O(log n) F () log n = O(sqrt(n)) T (also o) n2(1 + sqrt(n)) = O(n2 log n) F () 3n2 + sqrt(n) = O(n2) T (also ) sqrt(n) log n = O(n) T (also o) 11/28/2018

True or false? 2n2 + 1 = O(n2) T (also ) Sqrt(n) = O(log n) F () log n = O(sqrt(n)) T (also o) n2(1 + sqrt(n)) = O(n2 log n) F () 3n2 + sqrt(n) = O(n2) T (also ) sqrt(n) log n = O(n) T (also o) 11/28/2018

Analyzing the complexity of an algorithm 11/28/2018

Kinds of analyses Worst case Provides an upper bound on running time Best case – not very useful, can always cheat Average case Provides the expected running time Very useful, but treat with care: what is “average”? 11/28/2018

General plan for analyzing time efficiency of a non-recursive algorithm Decide parameter (input size) Identify most executed line (basic operation) worst-case = average-case? T(n) = i ti T(n) = Θ (f(n)) 11/28/2018

Example repeatedElement (A, n) // determines whether all elements in a given // array are distinct for i = 1 to n-1 { for j = i+1 to n { if (A[i] == A[j]) return true; } return false; 11/28/2018

Example repeatedElement (A, n) // determines whether all elements in a given // array are distinct for i = 1 to n-1 { for j = i+1 to n { if (A[i] == A[j]) return true; } return false; 11/28/2018

Best case? Worst-case? Average case? 11/28/2018

Best case Worst-case Average case? A[1] = A[2] T(n) = Θ (1) No repeated elements T(n) = (n-1) + (n-2) + … + 1 = n (n-1) / 2 = Θ (n2) Average case? What do you mean by “average”? Need more assumptions about data distribution. How many possible repeats are in the data? Average-case analysis often involves probability. 11/28/2018

Find the order of growth for sums T(n) = i=1..n i = Θ (n2) T(n) = i=1..n log (i) = ? T(n) = i=1..n n / 2i = ? T(n) = i=1..n 2i = ? … How to find out the actual order of growth? Math… Textbook Appendix A.1 (page 1058-60) 11/28/2018

Closed form, or explicit formula Arithmetic series An arithmetic series is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. e.g.: 1, 2, 3, 4, 5 or 10, 12, 14, 16, 18, 20 In general: Recursive definition Closed form, or explicit formula Or: 11/28/2018

Sum of arithmetic series If a1, a2, …, an is an arithmetic series, then e.g. 1 + 3 + 5 + 7 + … + 99 = ? (series definition: ai = 2i-1) This is ∑ i = 1 to 50 (ai) = 50 * (1 + 99) / 2 = 2500 11/28/2018

Closed form, or explicit formula Geometric series A geometric series is a sequence of numbers such that the ratio between any two successive members of the sequence is a constant. e.g.: 1, 2, 4, 8, 16, 32 or 10, 20, 40, 80, 160 or 1, ½, ¼, 1/8, 1/16 In general: Recursive definition Closed form, or explicit formula Or: 11/28/2018

Sum of geometric series if r < 1 if r > 1 if r = 1 11/28/2018

Sum of geometric series if r < 1 if r > 1 if r = 1 11/28/2018

Important formulas 11/28/2018

Sum manipulation rules Example: 11/28/2018

Sum manipulation rules Example: 11/28/2018

using the formula for geometric series: i=1..n n / 2i = n * i=1..n (½)i = ? using the formula for geometric series: i=0..n (½)i = 1 + ½ + ¼ + … (½)n = 2 Application: algorithm for allocating dynamic memories 11/28/2018

Application: algorithm for selection sort using priority queue i=1..n log (i) = log 1 + log 2 + … + log n = log 1 x 2 x 3 x … x n = log n! = (n log n) Application: algorithm for selection sort using priority queue 11/28/2018

Recursive definition of sum of series T (n) = i=0..n i is equivalent to: T(n) = T(n-1) + n T(0) = 0 T(n) = i=0..n ai is equivalent to: T(n) = T(n-1) + an T(0) = 1 Recurrence Boundary condition Recursive definition is often intuitive and easy to obtain. It is very useful in analyzing recursive algorithms, and some non-recursive algorithms too. 11/28/2018

Recursive definition of sum of series How to solve such recurrence or more generally, recurrence in the form of: T(n) = aT(n-b) + f(n) or T(n) = aT(n/b) + f(n) 11/28/2018