+ All Categories
Home > Documents > csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional...

csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional...

Date post: 08-Jul-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
17
Week 5: Singly Linked List and Advanced C++ Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University CSCI 2100 Data Structures Fall 2019
Transcript
Page 1: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

Week 5: Singly Linked List and Advanced C++

Tae-Hyuk (Ted) AhnDepartment of Computer Science

Program of Bioinformatics and Computational BiologySaint Louis University

CSCI 2100 Data Structures Fall 2019

Page 2: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

2CSCI 2100

Student OutcomesAfter this lecture, students are expected to understand

● Constant time, complexity, and

Page 3: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

3CSCI 2100

Constant Time Operations● A constant time operation is an operation that, for a given processor, always operates

in the same amount of time, regardless of input values.

Page 4: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

4CSCI 2100

Identifying constant time operations

Page 5: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

5CSCI 2100

Growth of functions and complexity

Upper and lower bounds

An algorithm with runtime complexity T(N) has a lower bound and an upper bound.

● Lower bound: A function f(N) that is ≤ the best case T(N), for all values of N ≥ 1.

● Upper bound: A function f(N) that is ≥ the worst case T(N), for all values of N ≥ 1.

Page 6: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

6CSCI 2100

Growth of functions and complexity

Upper and lower bounds

● Proving an upper bound means you have proven that the algorithm will use no more than some limit on a resource.

● Proving a lower bound means you have proven that the algorithm will use no less than some limit on a resource.

Page 7: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

7CSCI 2100

Upper and lower bounds

Page 8: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

8CSCI 2100

Growth rates and asymptotic notations

● An additional simplification can factor out the constant from a bounding function, leaving a function that categorizes the algorithm's growth rate. Ex: Instead of saying that an algorithm's runtime function has an upper bound of 30N2, the algorithm could be described as having a worst case growth rate of N2. Asymptotic notation is the classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function. Three asymptotic notations are commonly used in complexity analysis:

● O notation provides a growth rate for an algorithm's upper bound.● ! notation provides a growth rate for an algorithm's lower bound.

● Θ notation provides a growth rate that is both an upper and lower bound.

Page 9: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

9CSCI 2100

Growth rates and asymptotic notations

Page 10: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

10CSCI 2100

Growth rates and asymptotic notations

Page 11: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

11CSCI 2100

Big O notationBig O notation is a mathematical way of describing how a function (running time of an algorithm) generally behaves in relation to the input size. In Big O notation, all functions that have the same growth rate (as determined by the highest order term of the function) are characterized using the same Big O notation. In essence, all functions that have the same growth rate are considered equivalent in Big O notation.Given a function that describes the running time of an algorithm, the Big O notation for that function can be determined using the following rules:● If f(N) is a sum of several terms, the highest order term (the one with the fastest growth

rate) is kept and others are discarded.● If f(N) has a term that is a product of several factors, all constants (those that are not in

terms of N) are omitted.

Page 12: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

12CSCI 2100

Big O notation

Page 13: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

13CSCI 2100

Big-Oh as an upper bound● The statement f(n) is O( g(n) ) indicates that g(n) is an upper bound for f(n)

● Which means it is also correct to make statements like:§ 3n+5 is O(n2)§ 3n+5 is O(2n)§ 3n+5 is O(5n + log n - 2)§ But the statement 3n+5 is O(n) is the “tightest” statement one can make

Page 14: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

14CSCI 2100 14

Function categories revisited

● The constant function: f(n) = 1

● The linear function: f(n) = n

● The quadratic function: f(n) = n2

● The cubic function: f(n) = n3

● The exponential function: f(n) = 2n

● The logarithm function: f(n) = log n

● The n log n function: f(n) = n log n

Page 15: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

15CSCI 2100

Runtime growth rate

Page 16: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

16CSCI 2100

Worst-case algorithm analysis

● To analyze how runtime of an algorithm scales as the input size increases, we first determine how many operations the algorithm executes for a specific input size, N. Then, the big-O notation for that function is determined.

● Algorithm runtime analysis often focuses on the worst-case runtime complexity. The worst-case runtime of an algorithm is the runtime complexity for an input that results in the longest execution.

● Other runtime analyses include best-case runtime and average-case runtime. Determining the average-case runtime requires knowledge of the statistical properties of the expected data inputs.

Page 17: csci2100 week5 3 - biohpc.github.io · Growth rates and asymptotic notations An additional simplification can factor out the constant from a bounding function, leaving a function

17CSCI 2100

Worst-case algorithm analysis


Recommended