Foundations II: Data Structures and Algorithms

Similar documents
with the size of the input in the limit, as the size of the misused.

CS473 - Algorithms I

Growth of Functions (CLRS 2.3,3)

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Growth Functions

Big-O Notation and Complexity Analysis

Algorithms and Programming I. Lecture#1 Spring 2015

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Data Structures and Algorithms CSE 465

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

3.1 Asymptotic notation

Lecture 2: Asymptotic Notation CSCI Algorithms I

Principles of Algorithm Analysis

CSC Design and Analysis of Algorithms. Lecture 1

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Computational Complexity

Introduction to Algorithms 6.046J/18.401J

Introduction to Algorithms

data structures and algorithms lecture 2

Agenda. We ve discussed

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23

Algorithms Design & Analysis. Analysis of Algorithm

Intro to Theory of Computation

Time complexity analysis

The Time Complexity of an Algorithm

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

The Time Complexity of an Algorithm

Algorithms, CSE, OSU. Introduction, complexity of algorithms, asymptotic growth of functions. Instructor: Anastasios Sidiropoulos

Data Structures and Algorithms. Asymptotic notation

Ch01. Analysis of Algorithms

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

Introduction to Algorithms: Asymptotic Notation

Data Structures and Algorithms Running time and growth functions January 18, 2018

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

Introduction to Algorithms and Asymptotic analysis

Analysis of Algorithms

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. January 16, 2019

CS F-01 Algorithm Analysis 1

Asymptotic Analysis 1

CS 380 ALGORITHM DESIGN AND ANALYSIS

P, NP, NP-Complete, and NPhard

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

CS684 Graph Algorithms

Analysis of Algorithms

CSE332: Data Abstrac0ons Sec%on 2. HyeIn Kim Spring 2014

CS Non-recursive and Recursive Algorithm Analysis

CSE 548: (Design and) Analysis of Algorithms

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004

Welcome to CSci Algorithms and Data Structures

How many hours would you estimate that you spent on this assignment?

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0

Analysis of Algorithms

Course Structure. Computer Science 2300: Data Structures and Algorithms. What is this class about? Textbooks

Asymptotic Analysis of Algorithms. Chapter 4

COMP Analysis of Algorithms & Data Structures

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Ch 01. Analysis of Algorithms

Cpt S 223. School of EECS, WSU

COMP Analysis of Algorithms & Data Structures

CS Data Structures and Algorithm Analysis

An analogy from Calculus: limits

CS483 Design and Analysis of Algorithms

Big O (Asymptotic Upper Bound)

Omega notation. Transitivity etc.

Runtime Complexity. CS 331: Data Structures and Algorithms

Algorithms and Their Complexity

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College

Data Structures and Algorithms Chapter 2

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian School of Computer Science and Engineering

COMP 9024, Class notes, 11s2, Class 1

EECS 477: Introduction to algorithms. Lecture 5

IS 709/809: Computational Methods in IS Research Fall Exam Review

Asymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2

Design and Analysis of Algorithms

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours (Las/CSEB 3043): Tue 6-7 pm, Wed 4-6 pm or by appointment.

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo

Review Of Topics. Review: Induction

CSC236 Week 4. Larry Zhang

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Module 1: Analyzing the Efficiency of Algorithms

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 1: Introduction

COMPUTER ALGORITHMS. Athasit Surarerks.

CSE 417: Algorithms and Computational Complexity

Written Homework #1: Analysis of Algorithms

Submit Growable Array exercise Answer Q1-3 from today's in-class quiz.

Reminder of Asymptotic Notation. Inf 2B: Asymptotic notation and Algorithms. Asymptotic notation for Running-time

Given a sequence a 1, a 2,...of numbers, the finite sum a 1 + a 2 + +a n,wheren is an nonnegative integer, can be written

Introduction to Computer Science Lecture 5: Algorithms

Menu. Lecture 2: Orders of Growth. Predicting Running Time. Order Notation. Predicting Program Properties

Discrete Optimization 2010 Lecture 1 Introduction / Algorithms & Spanning Trees

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Define Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 417: Algorithms and Computational Complexity. Winter 2007 Larry Ruzzo

Transcription:

Foundations II: Data Structures and Algorithms Instructor : Yusu Wang Topic 1 : Introduction and Asymptotic notation

Course Information Course webpage http://www.cse.ohio-state.edu/~yusu/courses/2331 Office hours Tu/Th 9:30 am 11:00 am Grading policy: homework: 20%, two midterms: 40%, final: 40%

Exams Midterm 1 Sept. 28 th : 8 10:00pm, Location: JR 251 Midterm 2 Nov. 2 th : 8 10:00pm, Location: JR 251 Final exam: Dec. 11 th (Monday), 12:00pm--1:45pm, Room DL369 Mark you calendar. Contact me within first two full weeks if any schedule conflict for any exam.

Notes All homework should be submitted before or in class on the due date. Late homework during the same day receives a 10% penalty. Late homework submitted the next day receives a 30% penalty. You may discuss homework with your classmates. It is very important that you write up your solutions individually, and acknowledge any collaboration / discussion with others.

More Information Textbook Introduction to Algorithms Others by Cormen, Leiserson, Rivest and Stein (third edition) CSE 2331 course notes By Dr. Rephael Wenger (SBX) The Art of Computer Programming By Donald Knuth

Introduction What is an algorithm? Step by step strategy to solve problems Should terminate Should return correct answer for any input instance

This Course Various issues involved in designing good algorithms What do we mean by good? Algorithm analysis, language used to measure performance How to design good algorithms Data structures, algorithm paradigms Fundamental problems Graph traversal, shortest path etc.

Asymptotic Notation

Sorting problem Input: a 1 Output: permutation of A that is sorted a 2 a n A = <,,. > Example: Input: < 3, 11, 6, 4, 2, 7, 9 > Output: < 2, 3, 4, 6, 7, 9, 11 >

Insertion Sort 1 i i+1 n 3, 11, 6, 4, 2, 7, 9 3, 6, 11, 4, 2, 7, 9 3, 4, 6, 11, 2, 7, 9 2, 3, 4, 6, 11, 7, 9

Pseudo-code InsertionSort(A, n) for i = 1 to n-1 do key = A[i+1] j = i while j > 0 and A[j] > key do A[j+1] = A[j] j = j - 1 A[j+1] = key

Analysis Termination Correctness beginning of for-loop: if A[1.. i] sorted, then end of for-loop: A[1.. i+1] sorted. when i = n-1, A[1.. i+1] is sorted. Efficiency: time/space Depends on input size n Space: roughly n

Running Time Depends on input size Depends on particular input Best case Worst case First Idea: Provide upper bound (as a guanrantee) Make it a function of n : T(n)

Running Time Worst case T(n) = max time of algorithm on any input of size n Average case T(n) = expected time of algorithm over all possible inputs of size n Need a statistical distribution model for input E.g, uniform distribution

Insertion Sort InsertionSort(A, n) for i = 1 to n-1 do key = A[i] j = i while j > 0 and A[j] > key A[j+1] = A[j] j = j - 1 A[j+1] = key do c 1 c 2 n T(n) = Σ ( + i ) = + n + i=2 c 1 c 2 c 3 n 2 c 4 c 5

Asymptotic Complexity Why shall we care about constants and lower order terms? Should focus on the relative growth w.r.t. n Especially when n becomes large! E.g: 0.2n 1.5 v.s 500n Second Idea: Ignore all constants and lower order terms Only order of growth --- Asymptotic time complexity

Illustration ff nn = OO gg nn

Big O Notation f(n) O(g(n)) if and only if c > 0, and n 0, so that 0 f(n) cg(n) for all n n 0 f(n) = O(g(n)) means f(n) O(g(n)) (i.e, at most) We say that g(n) is an asymptotic upper bound for f(n). It also means: lim n f(n) g(n) c E.g, f(n) = O(n 2 ) if there exists c, n 0 > 0 such that f(n) cn 2, for all n n 0.

More Examples 5nn 2 + 6nn + 8 = OO nn 3? 100nn 2 1000 nn = OO(nn 2 )? 6nn 3 + 7nn 2 + 3nn = OO(nn 1.5 )? 2 nn = OO nn 2? 3lg nn = OO(nn)? 3 nn = OO 2 nn? 3 nn = OO 2 2nn log 3 nn = OO log 2 nn? nn = OO(nn) lg nn

Omega Ω Notation f(n) Ω (g(n)) if and only if c > 0, and n 0, so that 0 cg(n) f(n) for all n n 0 f(n) = Ω (g(n)) means f(n) Ω (g(n)) (i.e, at least) We say g(n) is an asymptotic lower bound of f(n). It also means: lim n f(n) g(n) c

Illustration ff nn = Ω gg nn

More Examples 5nn 2 + 6nn + 8 = Ω nn 3? 5nn 2 + 6nn + 8 = Ω nn 2? 6nn 3 + 7nn 2 + 3nn = Ω(nn 1.5 )? 2 nn = Ω nn 2? 3lg nn = Ω(nn)? 3 nn = Ω 2 nn? log 3 nn = Ω log 2 nn? 2 log 3 nn = Ω(2 log 2 nn )

Theta Θ Notation Combine lower and upper bound Means tight: of the same order ff nn Θ gg nn if and only if cc 1, cc 2 > 0, and nn 0, such that cc 1 gg nn ff nn cc 2 gg nn for any nn nn 0 ff nn = ΘΘ gg nn means ff nn ΘΘ gg nn We say g(n) is an asymptotically tight bound for f(n). It also means: ff(nn) cc 1 lim cc nn gg(nn) 2

ff nn = OO(gg nn ) ff nn = Ω(gg nn ) ff nn = Θ(gg nn )

Remarks -- 1 ff nn = Θ(gg nn ) if and only if ff nn = OO(gg nn ), and ff nn = Ω gg nn. Insertion sort algorithm as described earlier has time complexity Θ(nn 2 ). Transpose symmetry: If ff nn = OO(gg nn ), if and only if gg nn = Ω ff nn Transitivity: If ff nn = OO(gg nn ) and gg nn = OO(h nn ), then ff nn = OO h nn. Same for Ω and Θ

Remarks -- 2 It is convenient to think that Big-O is smaller than or equal to Big-Ω is larger than or equal to Big-Θ is equal However, These relations are modulo constant factor scaling Not every pair of functions have such relations If ff nn OO(gg nn ), this does not imply that ff nn = Ω(gg nn ).

Remarks -- 3 Provide a unified language to measure the performance of algorithms Give us intuitive idea how fast we shall expect the alg. Can now compare various algorithms for the same problem Constants hidden! O( n lg lg n ), 2n lg n T(n) = n 2 + O (n) means T(n) = n 2 + h(n), and h(n) = O(n)

Pitfalls O(n) + O(n) = O(n) T(n) = n + Σ O(n) k i = 1 = n + O(n) OK? k should not depend on n! It can be an arbitrarily large constant

Yet Another Notation Small o notation: f(n) = o(g(n)) means for any cc > 0, nn 0 s.t. for all nn nn 0, 0 ff nn < cccc nn. In other words, Examples: lim = 0 n Is n - lg n = o(n)? Is n = o (n lg n)? f(n) g(n)

Yet Another Notation Small ω notation: f(n) = ω(g(n)) means for any cc > 0, nn 0 s.t. for all nn nn 0, 0 cccc nn < ff nn. In other words, lim n f(n) g(n) Examples: = Is n - lg n = ω(n)? Is n = ω(n / lg n)? or lim = 0 n g(n) f(n)

Review some basics Chapter 3.2 of CLRS See the board

Recall Asymptotic Notation

Another View

Some Special Cases

More Examples nn 3 vs. 1.0001 nn nn 3 vs. 1.0001 nn 2 nn aa vs. bb nn ln(nn 4 ) vs. log 3 2nn 2lg nn vs. nn lg nn vs. nn εε nn lg nn vs. nn lg nn nn vs. log 2 3 nn nn vs. 2 log 2 nn+4 nn log 2 nn vs. 2 2 log 2 nn

More Examples lg nn 2 vs. (lg nn) 2 100 lg nn 10 10 vs. ln nn 3 log 2 nn vs. 0.5nn lg 2nn 2 + nn lg nn vs lg (n 3 100n) nn nn lg nn vs. 2nn 2 + nn lg nn In general, we can safely ignore low order terms.

Hierarchy

More Example Rank the following functions by order of growth: 2 nn 4, nn + 3 lg(3nn 2 4nn), nn nn + 5, nn ln nn, 3 2 nn, 4nn lg nn, nn + lg nn

Summary Algorithms are useful Example: sorting problem Insertion sort Asymptotic complexity Focus on the growth of complexity w.r.t input size