Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms

Size: px
Start display at page:

Download "Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms"

Transcription

1 Algorithms and Theory of Computation Lecture 2: Big-O Notation Graph Algorithms Xiaohui Bei MAS 714 August 14, 2018 Nanyang Technological University MAS 714 August 14, / 20

2 O, Ω, and Θ Nanyang Technological University MAS 714 August 14, / 20

3 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Nanyang Technological University MAS 714 August 14, / 20

4 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n Nanyang Technological University MAS 714 August 14, / 20

5 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n = T(n) = O(n) Nanyang Technological University MAS 714 August 14, / 20

6 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n = T(n) = O(n) set c = 1001 and n0 = 100 Nanyang Technological University MAS 714 August 14, / 20

7 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n = T(n) = O(n) set c = 1001 and n0 = 100 T(n) = pn 2 + qn + r for constants p, q, r > 0 Nanyang Technological University MAS 714 August 14, / 20

8 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n = T(n) = O(n) set c = 1001 and n0 = 100 T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = O(n 2 ) Nanyang Technological University MAS 714 August 14, / 20

9 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Upper Bounds We say T(n) = O(f(n)) if there exists constants c > 0 and n 0 0, such that for all n n 0, we have T(n) c f(n). Examples T(n) = 1000n = T(n) = O(n) set c = 1001 and n0 = 100 T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = O(n 2 ) set c = p + q + r and n0 = 1 also correct to say T(n) = O(n 3 ) Nanyang Technological University MAS 714 August 14, / 20

10 Some Remarks Equals sign. O(f(n)) is a set of functions, but computer scientists often write T(n) = O(f(n)) instead of T(n) O(f(n)). Consider f(n) = 5n 3 and g(n) = 3n 2, we write f(n) = O(n 3 ) = g(n), but it does not mean f(n) = g(n). Domain. The domain of f(n) is typically the natural numbers {0, 1, 2,...}. Sometimes we restrict to a subset of the natural numbers. Other times we extend to the reals. Nonnegative functions. When using big-o notation, we assume that the functions involved are (asymptotically) nonnegative. Nanyang Technological University MAS 714 August 14, / 20

11 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Nanyang Technological University MAS 714 August 14, / 20

12 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 Nanyang Technological University MAS 714 August 14, / 20

13 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Ω(n 2 ) Nanyang Technological University MAS 714 August 14, / 20

14 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Ω(n 2 ) set ɛ = p and n0 = 1 also correct to say T(n) = Ω(n) Nanyang Technological University MAS 714 August 14, / 20

15 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Ω(n 2 ) set ɛ = p and n0 = 1 also correct to say T(n) = Ω(n) Meaningful Statement. Any compare-based sorting algorithm requires Ω(n log n) compares in the worst case. Nanyang Technological University MAS 714 August 14, / 20

16 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Lower Bounds We say T(n) = Ω(f(n)) if there exists constants ɛ > 0 and n 0 0, such that for all n n 0, we have T(n) ɛ f(n). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Ω(n 2 ) set ɛ = p and n0 = 1 also correct to say T(n) = Ω(n) Meaningful Statement. Any compare-based sorting algorithm requires Ω(n log n) compares in the worst case. Meaningless Statement. Any compare-based sorting algorithm requires O(n log n) compares in the worst case. Nanyang Technological University MAS 714 August 14, / 20

17 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Tight Bounds We say T(n) = Θ(f(n)) if there exists constants c 1, c 2 > 0 and n 0 0, such that for all n n 0, we have c 1 f(n) T(n) c 2 f(n). Nanyang Technological University MAS 714 August 14, / 20

18 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Tight Bounds We say T(n) = Θ(f(n)) if there exists constants c 1, c 2 > 0 and n 0 0, such that for all n n 0, we have c 1 f(n) T(n) c 2 f(n). Alternative definition T(n) = Θ(f(n)) if T(n) is both O(f(n)) and also Ω(f(n)). Nanyang Technological University MAS 714 August 14, / 20

19 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Tight Bounds We say T(n) = Θ(f(n)) if there exists constants c 1, c 2 > 0 and n 0 0, such that for all n n 0, we have c 1 f(n) T(n) c 2 f(n). Alternative definition T(n) = Θ(f(n)) if T(n) is both O(f(n)) and also Ω(f(n)). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 Nanyang Technological University MAS 714 August 14, / 20

20 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Tight Bounds We say T(n) = Θ(f(n)) if there exists constants c 1, c 2 > 0 and n 0 0, such that for all n n 0, we have c 1 f(n) T(n) c 2 f(n). Alternative definition T(n) = Θ(f(n)) if T(n) is both O(f(n)) and also Ω(f(n)). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Θ(n 2 ) Nanyang Technological University MAS 714 August 14, / 20

21 O, Ω, and Θ Let T, f are two monotone increasing functions that maps from N to R +. Asymptotic Tight Bounds We say T(n) = Θ(f(n)) if there exists constants c 1, c 2 > 0 and n 0 0, such that for all n n 0, we have c 1 f(n) T(n) c 2 f(n). Alternative definition T(n) = Θ(f(n)) if T(n) is both O(f(n)) and also Ω(f(n)). Examples T(n) = pn 2 + qn + r for constants p, q, r > 0 = T(n) = Θ(n 2 ) set c1 = p, c 2 = p + q + r and n 0 = 1 T(n) is neither Θ(n) nor Θ(n 3 ) Nanyang Technological University MAS 714 August 14, / 20

22 Properties of Asymptotic Growth Rates Nanyang Technological University MAS 714 August 14, / 20

23 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). Nanyang Technological University MAS 714 August 14, / 20

24 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). 2 If f = Ω(g) and g = Ω(h), then f = Ω(h). Nanyang Technological University MAS 714 August 14, / 20

25 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). 2 If f = Ω(g) and g = Ω(h), then f = Ω(h). 3 If f = Θ(g) and g = Θ(h), then f = Θ(h). Nanyang Technological University MAS 714 August 14, / 20

26 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). 2 If f = Ω(g) and g = Ω(h), then f = Ω(h). 3 If f = Θ(g) and g = Θ(h), then f = Θ(h). 4 If f = O(h) and g = O(h), then f + g = O(h). Nanyang Technological University MAS 714 August 14, / 20

27 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). 2 If f = Ω(g) and g = Ω(h), then f = Ω(h). 3 If f = Θ(g) and g = Θ(h), then f = Θ(h). 4 If f = O(h) and g = O(h), then f + g = O(h). 5 If g = O(f), then f + g = Θ(f). Nanyang Technological University MAS 714 August 14, / 20

28 Properties of Asymptotic Growth Rates 1 If f = O(g) and g = O(h), then f = O(h). 2 If f = Ω(g) and g = Ω(h), then f = Ω(h). 3 If f = Θ(g) and g = Θ(h), then f = Θ(h). 4 If f = O(h) and g = O(h), then f + g = O(h). 5 If g = O(f), then f + g = Θ(f). f(n) 6 If lim = c > 0, then f = Θ(g). n g(n) Nanyang Technological University MAS 714 August 14, / 20

29 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Nanyang Technological University MAS 714 August 14, / 20

30 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Polynomial-Time Algorithm A polynomial-time algorithm is one with running time O(n d ) for some constant d. Nanyang Technological University MAS 714 August 14, / 20

31 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Polynomial-Time Algorithm A polynomial-time algorithm is one with running time O(n d ) for some constant d. 2 Logarithms. For every a, b > 1 and every x > 0, we have log a n = Θ(log b n) = O(n x ). Nanyang Technological University MAS 714 August 14, / 20

32 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Polynomial-Time Algorithm A polynomial-time algorithm is one with running time O(n d ) for some constant d. 2 Logarithms. For every a, b > 1 and every x > 0, we have log a n = Θ(log b n) = O(n x ). No need to specify base (assuming it s a constant). Logarithms are always better than polynomials. Nanyang Technological University MAS 714 August 14, / 20

33 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Polynomial-Time Algorithm A polynomial-time algorithm is one with running time O(n d ) for some constant d. 2 Logarithms. For every a, b > 1 and every x > 0, we have log a n = Θ(log b n) = O(n x ). No need to specify base (assuming it s a constant). Logarithms are always better than polynomials. 3 Exponentials. For every r > 1 and every d > 0, we have n d = O(r n ). Nanyang Technological University MAS 714 August 14, / 20

34 Some Common Functions 1 Polynomials. Let f be a polynomial of degree d, in which the coefficient a d is positive. Then f = O(n d ). Asymptotic rate of growth is determined by their high-order term. Polynomial-Time Algorithm A polynomial-time algorithm is one with running time O(n d ) for some constant d. 2 Logarithms. For every a, b > 1 and every x > 0, we have log a n = Θ(log b n) = O(n x ). No need to specify base (assuming it s a constant). Logarithms are always better than polynomials. 3 Exponentials. For every r > 1 and every d > 0, we have n d = O(r n ). Polynomials are always better than exponentials. Nanyang Technological University MAS 714 August 14, / 20

35 More Notations Asymptotic Smaller T(n) We say T(n) = o(f(n)) if lim n f(n) = 0. Asymptotic Larger f(n) We say T(n) = ω(f(n)) if lim n T(n) = 0. Nanyang Technological University MAS 714 August 14, / 20

36 O, Ω, and Θ with multiple variables Asymptotic Upper Bounds We say T(m, n) = O(f(m, n)) if there exists constants c > 0, m 0 0 and n 0 0, such that for all m m 0 and n n 0, we have T(m, n) c f(m, n). Similar definitions for Ω and Θ. Nanyang Technological University MAS 714 August 14, / 20

37 O, Ω, and Θ with multiple variables Asymptotic Upper Bounds We say T(m, n) = O(f(m, n)) if there exists constants c > 0, m 0 0 and n 0 0, such that for all m m 0 and n n 0, we have T(m, n) c f(m, n). Similar definitions for Ω and Θ. Examples T(m, n) = 32mn mn + 32n 3 Nanyang Technological University MAS 714 August 14, / 20

38 O, Ω, and Θ with multiple variables Asymptotic Upper Bounds We say T(m, n) = O(f(m, n)) if there exists constants c > 0, m 0 0 and n 0 0, such that for all m m 0 and n n 0, we have T(m, n) c f(m, n). Similar definitions for Ω and Θ. Examples T(m, n) = 32mn mn + 32n 3 T(m, n) is both O(mn 2 + n 3 ) and O(mn 3 ). T(m, n) is neither O(n 3 ) nor O(mn 2 ). Nanyang Technological University MAS 714 August 14, / 20

39 Data Structures We discussed algorithms in peusdocode, but how the data will be represented in an actual implementation of the algorithm? Nanyang Technological University MAS 714 August 14, / 20

40 Data Structures We discussed algorithms in peusdocode, but how the data will be represented in an actual implementation of the algorithm? Data Structures: a particular way of organizing data such that it can be used efficiently in an algorithm. Appropriately designed data structures can help to give more efficient algorithms. Data structure in Number Addition : arrays. Nanyang Technological University MAS 714 August 14, / 20

41 Data Structures We discussed algorithms in peusdocode, but how the data will be represented in an actual implementation of the algorithm? Data Structures: a particular way of organizing data such that it can be used efficiently in an algorithm. Appropriately designed data structures can help to give more efficient algorithms. Data structure in Number Addition : arrays. Program = Algorithm + Data Structure Nanyang Technological University MAS 714 August 14, / 20

42 Common Data Structures Elementary Data Structures Arrays Linked Lists Stacks and Queues Priority Queues Hash Tables Binary Search Trees many others Nanyang Technological University MAS 714 August 14, / 20

43 Graph Algorithms Nanyang Technological University MAS 714 August 14, / 20

44 Graphs One of the most important combinatoric object in Computer Science, Optimization, Combinatorics. Figure: Seven Bridges of Königsberg Nanyang Technological University MAS 714 August 14, / 20

45 Graphs Graph A graph G consists of a set V of vertices and a set E of edges Directed Graph: Each edge e E is an ordered pair (u, v) for some u, v V. Undirected Graph: Each edge e E is an unordered pair {u, v} for some u, v V. Nanyang Technological University MAS 714 August 14, / 20

46 Graphs Graph 1 A graph G consists of a set V of vertices and a set E of edges Directed Graph: Each edge e E is an ordered pair (u, v) for some u, v V Undirected Graph: Each edge e E is an unordered pair {u, v} for some u, v V. 6 Example In the above undirected graph G = (V, E): V = {1, 2, 3, 4, 5, 6} E = {{1, 2}, {1, 3}, {2, 3}, {2, 4}, {3, 4}, {3, 5}, {4, 5}, {4, 6}} Nanyang Technological University MAS 714 August 14, / 20

47 Applications Transportation Networks The map of routes served by an airline carrier/railway company. vertices are airports/train stations; an edges from u to v if there is a flight/railway track between them. Nanyang Technological University MAS 714 August 14, / 20

48 Applications Transportation Networks The map of routes served by an airline carrier/railway company. vertices are airports/train stations; an edges from u to v if there is a flight/railway track between them. Information Networks The World Wide Web can be viewed as a directed graph. vertices are Web pages; an edge from u to v if u has a hyperlink to v. Nanyang Technological University MAS 714 August 14, / 20

49 Applications Transportation Networks The map of routes served by an airline carrier/railway company. vertices are airports/train stations; an edges from u to v if there is a flight/railway track between them. Information Networks The World Wide Web can be viewed as a directed graph. vertices are Web pages; an edge from u to v if u has a hyperlink to v. Social Networks A collection of people who interact with each other forms an undirected graph. vertices are people an edge joining u and v if they are friends. Nanyang Technological University MAS 714 August 14, / 20

50 Applications Transportation Networks The map of routes served by an airline carrier/railway company. vertices are airports/train stations; an edges from u to v if there is a flight/railway track between them. Social Networks A collection of people who interact with each other forms an undirected graph. vertices are people an edge joining u and v if they are friends. Information Networks The World Wide Web can be viewed as a directed graph. vertices are Web pages; an edge from u to v if u has a hyperlink to v. Dependency Networks A directed graph that captures the interdependencies among a collection of objects, e.g., in an university: vertices are courses offered an edge from u to v if u is a prerequisite for v. Nanyang Technological University MAS 714 August 14, / 20

51 Notation and Convention usually use n = V and m = E u and v are the end points of an edge e = {u, v} multi-graphs may have loops which are edges (u, u) multi-edges which are different edges between same pair of vertices in most of this class we only consider simple graphs Nanyang Technological University MAS 714 August 14, / 20

52 Graph Representation Nanyang Technological University MAS 714 August 14, / 20

53 Graph Representation Adjacency Matrix Represent a graph G = (V, E) by an n n adjacency matrix A, where A[u, v] = 1 if edge (u, v) E, and A[u, v] = 0 otherwise. The matrix is symmetric for undirected graphs. Nanyang Technological University MAS 714 August 14, / 20

54 Graph Representation Adjacency Matrix Represent a graph G = (V, E) by an n n adjacency matrix A, where A[u, v] = 1 if edge (u, v) E, and A[u, v] = 0 otherwise. The matrix is symmetric for undirected graphs. Advantages: can check if an edge (u, v) E in O(1) time can do linear algebra on the matrix Nanyang Technological University MAS 714 August 14, / 20

55 Graph Representation Adjacency Matrix Represent a graph G = (V, E) by an n n adjacency matrix A, where A[u, v] = 1 if edge (u, v) E, and A[u, v] = 0 otherwise. The matrix is symmetric for undirected graphs. Advantages: can check if an edge (u, v) E in O(1) time can do linear algebra on the matrix Disadvantages: require Ω(n 2 ) space even when m = o(n 2 ) cannot examine all edges incident to a given node efficiently Nanyang Technological University MAS 714 August 14, / 20

56 Graph Representation Adjacency List Represent a graph G = (V, E) by adjacency lists, which is an array Adj of length n, where each entry Adj[v] is a list containing all vertices adjacent to vertex v Nanyang Technological University MAS 714 August 14, / 20

57 Graph Representation Adjacency List Represent a graph G = (V, E) by adjacency lists, which is an array Adj of length n, where each entry Adj[v] is a list containing all vertices adjacent to vertex v Advantages: take O(n + m) space, which is close to optimal can browse all edges incident to a given vertex efficiently Nanyang Technological University MAS 714 August 14, / 20

58 Graph Representation Adjacency List Represent a graph G = (V, E) by adjacency lists, which is an array Adj of length n, where each entry Adj[v] is a list containing all vertices adjacent to vertex v Advantages: take O(n + m) space, which is close to optimal can browse all edges incident to a given vertex efficiently Disadvantages: hard to find a specific edge Standard representation for graphs. Nanyang Technological University MAS 714 August 14, / 20

59 A Concrete Representation Linked List Linked lists are a data structure to represent sequence whose length is arbitrary and changeable. each entry in a linked list consists of a cell for data and a pointer that points to the next entry there is a pointer to the first element the last entry points to NIL Nanyang Technological University MAS 714 August 14, / 20

60 A Concrete Representation Linked List Linked lists are a data structure to represent sequence whose length is arbitrary and changeable. each entry in a linked list consists of a cell for data and a pointer that points to the next entry there is a pointer to the first element the last entry points to NIL Advantages: easy to add an element into a linked list, and to sequentially read the list. Disadvantages: no random access. Nanyang Technological University MAS 714 August 14, / 20

61 Adjacency List Example Example of a Linked List Nanyang Technological University MAS 714 August 14, / 20

62 Adjacency List Example Example of a Linked List Example of an Adjacency List Nanyang Technological University MAS 714 August 14, / 20

2.2 Asymptotic Order of Growth. definitions and notation (2.2) examples (2.4) properties (2.2)

2.2 Asymptotic Order of Growth. definitions and notation (2.2) examples (2.4) properties (2.2) 2.2 Asymptotic Order of Growth definitions and notation (2.2) examples (2.4) properties (2.2) Asymptotic Order of Growth Upper bounds. T(n) is O(f(n)) if there exist constants c > 0 and n 0 0 such that

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Chapter 2 2.1 Computational Tractability Basics of Algorithm Analysis "For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious.

More information

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information

Review Asympto&c Bounds

Review Asympto&c Bounds Objec&ves Review: Asympto&c running &mes Classes of running &mes Implemen&ng Gale-Shapley algorithm Office hours: Today, 2:35-2:55, 5-5:50 p.m. Thursday: 1 5 p.m. Faculty Candidate Talk - Today at 4 p.m.

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Based

More information

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

Asymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2 Asymptotic Analysis Slides by Carl Kingsford Jan. 27, 2014 AD Chapter 2 Independent Set Definition (Independent Set). Given a graph G = (V, E) an independent set is a set S V if no two nodes in S are joined

More information

Introduction to Algorithms: Asymptotic Notation

Introduction to Algorithms: Asymptotic Notation Introduction to Algorithms: Asymptotic Notation Why Should We Care? (Order of growth) CS 421 - Analysis of Algorithms 2 Asymptotic Notation O-notation (upper bounds): that 0 f(n) cg(n) for all n n. 0 CS

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 2 Asymptotic Notation 1 O-notation: Asymptotic upper bound f(n) = O(g(n)) if positive constants c, n 0 such that 0 f(n) cg(n), n n 0 f(n) = O(g(n)) cg(n) f(n) Asymptotic running

More information

Asymptotic Analysis 1

Asymptotic Analysis 1 Asymptotic Analysis 1 Last week, we discussed how to present algorithms using pseudocode. For example, we looked at an algorithm for singing the annoying song 99 Bottles of Beer on the Wall for arbitrary

More information

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Winter 2012 Larry Ruzzo 1 Efficiency Our correct TSP algorithm was incredibly slow Basically slow no matter what computer you have We want a general theory of efficiency

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computational tractability asymptotic order of growth survey of common running times Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Algorithm runtime analysis and computational tractability Time Complexity of an Algorithm How do we measure the complexity (time, space requirements) of an algorithm. 1 microsecond? Units of time As soon

More information

Growth of Functions (CLRS 2.3,3)

Growth of Functions (CLRS 2.3,3) Growth of Functions (CLRS 2.3,3) 1 Review Last time we discussed running time of algorithms and introduced the RAM model of computation. Best-case running time: the shortest running time for any input

More information

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

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms Taking Stock IE170: Algorithms in Systems Engineering: Lecture 3 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 19, 2007 Last Time Lots of funky math Playing

More information

Matching Residents to Hospitals

Matching Residents to Hospitals Midterm Review Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and

More information

EECS 477: Introduction to algorithms. Lecture 5

EECS 477: Introduction to algorithms. Lecture 5 EECS 477: Introduction to algorithms. Lecture 5 Prof. Igor Guskov guskov@eecs.umich.edu September 19, 2002 1 Lecture outline Asymptotic notation: applies to worst, best, average case performance, amortized

More information

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

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Summer 2007 Larry Ruzzo Defining Efficiency Runs fast on typical real problem instances Pro: sensible, bottom-line-oriented Con: moving target (diff computers, compilers,

More information

Analysis of Algorithms

Analysis of Algorithms October 1, 2015 Analysis of Algorithms CS 141, Fall 2015 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

More information

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

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College Why analysis? We want to predict how the algorithm will behave (e.g. running time) on arbitrary inputs, and how it will

More information

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

Define Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 417: Algorithms and Computational Complexity. Winter 2007 Larry Ruzzo CSE 417: Algorithms and Computational 2: Analysis Winter 2007 Larry Ruzzo Define Efficiency Runs fast on typical real problem instances Pro: sensible, bottom-line-oriented Con: moving target (diff computers,

More information

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency Lecture 2 Fundamentals of the Analysis of Algorithm Efficiency 1 Lecture Contents 1. Analysis Framework 2. Asymptotic Notations and Basic Efficiency Classes 3. Mathematical Analysis of Nonrecursive Algorithms

More information

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

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004 Asymptotic Analysis Thomas A. Anastasio January 7, 004 1 Introduction As a programmer, you often have a choice of data structures and algorithms. Choosing the best one for a particular job involves, among

More information

Harvard CS 121 and CSCI E-121 Lecture 20: Polynomial Time

Harvard CS 121 and CSCI E-121 Lecture 20: Polynomial Time Harvard CS 121 and CSCI E-121 Lecture 20: Polynomial Time Harry Lewis November 12, 20123 Review of Asymptotic Notation For f, g : N R + f = O(g): c > 0 s.t. f(n) c g(n) for all sufficiently large n. f

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 MA008 p.1/36 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/36 Content of lecture 2 Examples Review data structures Data types vs. data

More information

CS 4407 Algorithms Lecture 2: Growth Functions

CS 4407 Algorithms Lecture 2: Growth Functions CS 4407 Algorithms Lecture 2: Growth Functions Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline Growth Functions Mathematical specification of growth functions

More information

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

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2 1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,

More information

CSC Design and Analysis of Algorithms. Lecture 1

CSC Design and Analysis of Algorithms. Lecture 1 CSC 8301- Design and Analysis of Algorithms Lecture 1 Introduction Analysis framework and asymptotic notations What is an algorithm? An algorithm is a finite sequence of unambiguous instructions for solving

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 3: Growth of Functions (slides enhanced by N. Adlai A. DePano) Overview Order of growth of functions provides a simple

More information

CS 344 Design and Analysis of Algorithms. Tarek El-Gaaly Course website:

CS 344 Design and Analysis of Algorithms. Tarek El-Gaaly Course website: CS 344 Design and Analysis of Algorithms Tarek El-Gaaly tgaaly@cs.rutgers.edu Course website: www.cs.rutgers.edu/~tgaaly/cs344.html Course Outline Textbook: Algorithms by S. Dasgupta, C.H. Papadimitriou,

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity CSE 417: Algorithms and Computational Complexity Lecture 2: Analysis Larry Ruzzo 1 Why big-o: measuring algorithm efficiency outline What s big-o: definition and related concepts Reasoning with big-o:

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu What is an Algorithm?

More information

3.1 Asymptotic notation

3.1 Asymptotic notation 3.1 Asymptotic notation The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = {0, 1, 2,... Such

More information

Algorithms Design & Analysis. Analysis of Algorithm

Algorithms Design & Analysis. Analysis of Algorithm Algorithms Design & Analysis Analysis of Algorithm Review Internship Stable Matching Algorithm 2 Outline Time complexity Computation model Asymptotic notions Recurrence Master theorem 3 The problem of

More information

CS Non-recursive and Recursive Algorithm Analysis

CS Non-recursive and Recursive Algorithm Analysis CS483-04 Non-recursive and Recursive Algorithm Analysis Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm - 5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/

More information

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu Analysis of Algorithm Efficiency Dr. Yingwu Zhu Measure Algorithm Efficiency Time efficiency How fast the algorithm runs; amount of time required to accomplish the task Our focus! Space efficiency Amount

More information

Big O Notation. P. Danziger

Big O Notation. P. Danziger 1 Comparing Algorithms We have seen that in many cases we would like to compare two algorithms. Generally, the efficiency of an algorithm can be guaged by how long it takes to run as a function of the

More information

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012 Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012 Practicalities Code: 456314.0 intermediate and optional course Previous knowledge 456305.0 Datastrukturer II (Algoritmer) Period

More information

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

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0 Asymptotic Notation Asymptotic notation deals with the behaviour of a function in the limit, that is, for sufficiently large values of its parameter. Often, when analysing the run time of an algorithm,

More information

Running Time Evaluation

Running Time Evaluation Running Time Evaluation Quadratic Vs. Linear Time Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 19 1 Running time 2 Examples 3 Big-Oh, Big-Omega, and Big-Theta Tools 4 Time

More information

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

5 + 9(10) + 3(100) + 0(1000) + 2(10000) = Chapter 5 Analyzing Algorithms So far we have been proving statements about databases, mathematics and arithmetic, or sequences of numbers. Though these types of statements are common in computer science,

More information

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary Complexity Analysis Complexity Theory Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary Output TRUE or FALSE Time and Space

More information

Lecture 3. Big-O notation, more recurrences!!

Lecture 3. Big-O notation, more recurrences!! Lecture 3 Big-O notation, more recurrences!! Announcements! HW1 is posted! (Due Friday) See Piazza for a list of HW clarifications First recitation section was this morning, there s another tomorrow (same

More information

1 Substitution method

1 Substitution method Recurrence Relations we have discussed asymptotic analysis of algorithms and various properties associated with asymptotic notation. As many algorithms are recursive in nature, it is natural to analyze

More information

Principles of Algorithm Analysis

Principles of Algorithm Analysis C H A P T E R 3 Principles of Algorithm Analysis 3.1 Computer Programs The design of computer programs requires:- 1. An algorithm that is easy to understand, code and debug. This is the concern of software

More information

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University)

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University) CIS 121 Analysis of Algorithms & Computational Complexity Slides based on materials provided by Mary Wootters (Stanford University) Today Sorting: InsertionSort vs MergeSort Analyzing the correctness of

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

Big O Notation. P. Danziger

Big O Notation. P. Danziger 1 Comparing Algorithms We have seen that in many cases we would like to compare two algorithms. Generally, the efficiency of an algorithm can be guaged by how long it takes to run as a function of the

More information

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

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

Space Complexity of Algorithms

Space Complexity of Algorithms Space Complexity of Algorithms So far we have considered only the time necessary for a computation Sometimes the size of the memory necessary for the computation is more critical. The amount of memory

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 10, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 1 /

More information

CS Data Structures and Algorithm Analysis

CS Data Structures and Algorithm Analysis CS 483 - Data Structures and Algorithm Analysis Lecture II: Chapter 2 R. Paul Wiegand George Mason University, Department of Computer Science February 1, 2006 Outline 1 Analysis Framework 2 Asymptotic

More information

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

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

COMPUTER ALGORITHMS. Athasit Surarerks.

COMPUTER ALGORITHMS. Athasit Surarerks. COMPUTER ALGORITHMS Athasit Surarerks. Introduction EUCLID s GAME Two players move in turn. On each move, a player has to write on the board a positive integer equal to the different from two numbers already

More information

Combinatorial Optimization

Combinatorial Optimization Combinatorial Optimization Problem set 8: solutions 1. Fix constants a R and b > 1. For n N, let f(n) = n a and g(n) = b n. Prove that f(n) = o ( g(n) ). Solution. First we observe that g(n) 0 for all

More information

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

How many hours would you estimate that you spent on this assignment? The first page of your homework submission must be a cover sheet answering the following questions. Do not leave it until the last minute; it s fine to fill out the cover sheet before you have completely

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 14, 2019 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. COMP

More information

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

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms Analysis Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms analysis tends to focus on time: Techniques for measuring

More information

Computational Complexity

Computational Complexity Computational Complexity S. V. N. Vishwanathan, Pinar Yanardag January 8, 016 1 Computational Complexity: What, Why, and How? Intuitively an algorithm is a well defined computational procedure that takes

More information

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

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23 CIS 11 Data Structures and Algorithms with Java Spring 018 Big-Oh Notation Monday, January /Tuesday, January 3 Learning Goals Review Big-Oh and learn big/small omega/theta notations Discuss running time

More information

CSE 531 Homework 1 Solution. Jiayi Xian

CSE 531 Homework 1 Solution. Jiayi Xian CSE 53 Homework Solution Jiayi Xian Fall 08 . (a) True. Since f(n) O(f(n)), clearly we have O(f(n)) O(O(f(n))). For the opposite, suppose g(n) O(O(f(n))), that is c > 0, h(n) O(f(n)), s.t g(n) c h(n) as

More information

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Limitations of Algorithms We conclude with a discussion of the limitations of the power of algorithms. That is, what kinds

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Algorithm Analysis 1 Purpose Why bother analyzing code; isn t getting it to work enough? Estimate time and memory in the average case and worst case Identify bottlenecks, i.e., where to reduce time Compare

More information

Algorithm efficiency analysis

Algorithm efficiency analysis Algorithm efficiency analysis Mădălina Răschip, Cristian Gaţu Faculty of Computer Science Alexandru Ioan Cuza University of Iaşi, Romania DS 2017/2018 Content Algorithm efficiency analysis Recursive function

More information

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA   === Homework submission instructions === Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA email: dsa1@csie.ntu.edu.tw === Homework submission instructions === For Problem 1, submit your source code, a Makefile

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning

More information

Math 391: Midterm 1.0 Spring 2016

Math 391: Midterm 1.0 Spring 2016 Math 391: Midterm 1.0 Spring 2016 James Skon skonjp@kenyon.edu Test date: October 5 Submission Instructions: Give all your assumptions. Show all your work. Be as complete as possible. Grading Problem 1

More information

Divide-and-Conquer Algorithms Part Two

Divide-and-Conquer Algorithms Part Two Divide-and-Conquer Algorithms Part Two Recap from Last Time Divide-and-Conquer Algorithms A divide-and-conquer algorithm is one that works as follows: (Divide) Split the input apart into multiple smaller

More information

Order Notation and the Mathematics for Analysis of Algorithms

Order Notation and the Mathematics for Analysis of Algorithms Elementary Data Structures and Algorithms Order Notation and the Mathematics for Analysis of Algorithms Name: Email: Code: 19704 Always choose the best or most general answer, unless otherwise instructed.

More information

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

with the size of the input in the limit, as the size of the misused. Chapter 3. Growth of Functions Outline Study the asymptotic efficiency of algorithms Give several standard methods for simplifying the asymptotic analysis of algorithms Present several notational conventions

More information

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming Algorithms and Theory of Computation Lecture 9: Dynamic Programming Xiaohui Bei MAS 714 September 10, 2018 Nanyang Technological University MAS 714 September 10, 2018 1 / 21 Recursion in Algorithm Design

More information

2.1 Computational Tractability. Chapter 2. Basics of Algorithm Analysis. Computational Tractability. Polynomial-Time

2.1 Computational Tractability. Chapter 2. Basics of Algorithm Analysis. Computational Tractability. Polynomial-Time Chapter 2 2.1 Computational Tractability Basics of Algorithm Analysis "For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious.

More information

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3 Banner ID: Name: Midterm Exam CS 3110: Design and Analysis of Algorithms June 20, 2006 Group 1 Group 2 Group 3 Question 1.1 Question 2.1 Question 3.1 Question 1.2 Question 2.2 Question 3.2 Question 3.3

More information

Advanced Algorithmics (6EAP)

Advanced Algorithmics (6EAP) Advanced Algorithmics (6EAP) MTAT.03.238 Order of growth maths Jaak Vilo 2017 fall Jaak Vilo 1 Program execution on input of size n How many steps/cycles a processor would need to do How to relate algorithm

More information

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

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Reading 10 : Asymptotic Analysis

Reading 10 : Asymptotic Analysis CS/Math 240: Introduction to Discrete Mathematics Fall 201 Instructor: Beck Hasti and Gautam Prakriya Reading 10 : Asymptotic Analysis In the last reading, we analyzed the running times of various algorithms.

More information

Lecture 2: Asymptotic Notation CSCI Algorithms I

Lecture 2: Asymptotic Notation CSCI Algorithms I Lecture 2: Asymptotic Notation CSCI 700 - Algorithms I Andrew Rosenberg September 2, 2010 Last Time Review Insertion Sort Analysis of Runtime Proof of Correctness Today Asymptotic Notation Its use in analyzing

More information

Big , and Definition Definition

Big , and Definition Definition Big O, Ω, and Θ Big-O gives us only a one-way comparison; if f is O(g) then g eventually is bigger than f from that point on, but in fact f could be very small in comparison. Example; 3n is O(2 2n ). We

More information

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 3 Asymptotic Notation O-, Ω-, Θ-, o-, ω-notation Divide and Conquer Merge Sort Binary Search Sofya Raskhodnikova and Adam Smith /5/0 Review Questions If input

More information

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

IS 709/809: Computational Methods in IS Research Fall Exam Review IS 709/809: Computational Methods in IS Research Fall 2017 Exam Review Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Exam When: Tuesday (11/28) 7:10pm

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Autumn 2018-2019 Outline 1 Algorithm Analysis (contd.) Outline Algorithm Analysis (contd.) 1 Algorithm Analysis (contd.) Growth Rates of Some Commonly Occurring Functions

More information

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

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

The Growth of Functions and Big-O Notation

The Growth of Functions and Big-O Notation The Growth of Functions and Big-O Notation Big-O Notation Big-O notation allows us to describe the aymptotic growth of a function without concern for i) constant multiplicative factors, and ii) lower-order

More information

Analysis of Algorithms

Analysis of Algorithms September 29, 2017 Analysis of Algorithms CS 141, Fall 2017 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

More information

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

Asymptotic Analysis Cont'd

Asymptotic Analysis Cont'd Cont'd Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Announcements We have class this Wednesday, Jan 18 at 12:30 That is, we have two sessions this Wednesday: at

More information

An analogy from Calculus: limits

An analogy from Calculus: limits COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm

More information

Lecture 7: The Subgraph Isomorphism Problem

Lecture 7: The Subgraph Isomorphism Problem CSC2429, MAT1304: Circuit Complexity October 25, 2016 Lecture 7: The Subgraph Isomorphism Problem Instructor: Benjamin Rossman 1 The Problem SUB(G) Convention 1 (Graphs). Graphs are finite simple graphs

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity 1 CS 350 Algorithms and Complexity Fall 2015 Lecture 15: Limitations of Algorithmic Power Introduction to complexity theory Andrew P. Black Department of Computer Science Portland State University Lower

More information

Data Structures and Algorithms. Asymptotic notation

Data Structures and Algorithms. Asymptotic notation Data Structures and Algorithms Asymptotic notation Estimating Running Time Algorithm arraymax executes 7n 1 primitive operations in the worst case. Define: a = Time taken by the fastest primitive operation

More information

COMP 555 Bioalgorithms. Fall Lecture 3: Algorithms and Complexity

COMP 555 Bioalgorithms. Fall Lecture 3: Algorithms and Complexity COMP 555 Bioalgorithms Fall 2014 Lecture 3: Algorithms and Complexity Study Chapter 2.1-2.8 Topics Algorithms Correctness Complexity Some algorithm design strategies Exhaustive Greedy Recursion Asymptotic

More information

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation:

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation: Data structures Exercise 1 solution Question 1 Let s start by writing all the functions in big O notation: f 1 (n) = 2017 = O(1), f 2 (n) = 2 log 2 n = O(n 2 ), f 3 (n) = 2 n = O(2 n ), f 4 (n) = 1 = O

More information

Growth of Functions. As an example for an estimate of computation time, let us consider the sequential search algorithm.

Growth of Functions. As an example for an estimate of computation time, let us consider the sequential search algorithm. Function Growth of Functions Subjects to be Learned Contents big oh max function big omega big theta little oh little omega Introduction One of the important criteria in evaluating algorithms is the time

More information

ICS 252 Introduction to Computer Design

ICS 252 Introduction to Computer Design ICS 252 fall 2006 Eli Bozorgzadeh Computer Science Department-UCI References and Copyright Textbooks referred [Mic94] G. De Micheli Synthesis and Optimization of Digital Circuits McGraw-Hill, 1994. [CLR90]

More information

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

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

Intro to Theory of Computation

Intro to Theory of Computation Intro to Theory of Computation LECTURE 22 Last time Review Today: Finish recursion theorem Complexity theory Exam 2 solutions out Homework 9 out Sofya Raskhodnikova L22.1 I-clicker question (frequency:

More information

CS 61B Asymptotic Analysis Fall 2017

CS 61B Asymptotic Analysis Fall 2017 CS 61B Asymptotic Analysis Fall 2017 1 More Running Time Give the worst case and best case running time in Θ( ) notation in terms of M and N. (a) Assume that slam() Θ(1) and returns a boolean. 1 public

More information

Lecture 1 - Preliminaries

Lecture 1 - Preliminaries Advanced Algorithms Floriano Zini Free University of Bozen-Bolzano Faculty of Computer Science Academic Year 2013-2014 Lecture 1 - Preliminaries 1 Typography vs algorithms Johann Gutenberg (c. 1398 February

More information

2 GRAPH AND NETWORK OPTIMIZATION. E. Amaldi Introduction to Operations Research Politecnico Milano 1

2 GRAPH AND NETWORK OPTIMIZATION. E. Amaldi Introduction to Operations Research Politecnico Milano 1 2 GRAPH AND NETWORK OPTIMIZATION E. Amaldi Introduction to Operations Research Politecnico Milano 1 A variety of decision-making problems can be formulated in terms of graphs and networks Examples: - transportation

More information

P, NP, NP-Complete, and NPhard

P, NP, NP-Complete, and NPhard P, NP, NP-Complete, and NPhard Problems Zhenjiang Li 21/09/2011 Outline Algorithm time complicity P and NP problems NP-Complete and NP-Hard problems Algorithm time complicity Outline What is this course

More information

Algorithms and Their Complexity

Algorithms and Their Complexity CSCE 222 Discrete Structures for Computing David Kebo Houngninou Algorithms and Their Complexity Chapter 3 Algorithm An algorithm is a finite sequence of steps that solves a problem. Computational complexity

More information