ECOM Discrete Mathematics

Size: px
Start display at page:

Download "ECOM Discrete Mathematics"

Transcription

1 ECOM Discrete Mathematics Chapter # 3 : Algorithms Fall, 2013/2014 ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 1 / 41

2 Outline 1 Algorithms 2 The Growth of Functions 3 Complexity of Algorithms ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 2 / 41

3 Algorithms Introduction The term algorithm is a corruption of the name Al-Khowarizmi, ABU JA FAR MOHAMMED IBN MUSA AL-KHOWARIZMI. Al-Khowarizmi, an astronomer and mathematician, was a member of the House of Wisdom, an academy of scientists in Baghdad. The word algebra comes from al-jabr, part of the title of his book Kitab al-jabr w al muquabala. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 3 / 41

4 An Algorithm Algorithms Introduction is a finite sequence of precise instructions for performing a computation or for solving a problem. Given a sequence of integers, find the largest one; Given a set, list all its subsets; Given a set of integers, put them in increasing order; Given a network, find the shortest path between two vertices. Solution Methodology Construct a model that translates the problem into a mathematical context. To complete the solution, a method is needed that will solve the general problem using the model. Ideally, what is required is a procedure that follows a sequence of steps that leads to the desired answer. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 4 / 41

5 Algorithms Introduction Example: Describe an algorithm for finding the maximum (largest) value in a finite sequence of integers. Solution: We perform the following steps Set the temporary maximum equal to the first integer in the sequence. Compare the next integer in the sequence to the temporary maximum, and if it is larger than the temporary maximum, set the temporary maximum equal to this integer. Repeat the previous step if there are more integers in the sequence. Stop when there are no integers left in the sequence. The temporary maximum at this point is the largest integer in the sequence. An algorithm can also be described using a computer language. However, when that is done, only those instructions permitted in the language can be used. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 5 / 41

6 Algorithms Introduction Pseudocode Pseudocode provides an intermediate step between an English language description of an algorithm and an implementation of this algorithm in a programming language. A pseudocode description of the algorithm for finding the maximum element in a finite sequence is as follows. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 6 / 41

7 Algorithms Introduction PROPERTIES OF ALGORITHMS Input. An algorithm has input values from a specified set. Output. From each set of input values an algorithm produces output values from a specified set. The output values are the solution to the problem. Definiteness. The steps of an algorithm must be defined precisely. Correctness. An algorithm should produce the correct output values for each set of input values. Finiteness. An algorithm should produce the desired output after a finite (but perhaps large) number of steps for any input in the set. Effectiveness. It must be possible to perform each step of an algorithm exactly and in a finite amount of time. Generality. The procedure should be applicable for all problems of the desired form, not just for a particular set of input values. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 7 / 41

8 Algorithms Searching Algorithms Problem: locate an element x in a list of distinct elements a 1, a 2,, a n, or determine that it is not in the list. Solution: the location of the term in the list that equals x (that is, i is the solution if x = ai ) and is 0 if x is not in the list. Procedures of the Linear Search (sequential search): Compare x and a 1. When x = a 1, the solution is the location of a 1, namely, 1. When x a 1, compare x with a 2. If x = a 2, the solution is the location of a 2, namely, 2. When x a 2, compare x with a 3. Continue this process, comparing x successively with each term of the list until a match is found, where the solution is the location of that term, unless no match occurs. If the entire list has been searched without locating x, the solution is 0. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 8 / 41

9 Algorithms Searching Algorithms The pseudocode for the linear search algorithm is displayed as Algorithm 2. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 9 / 41

10 Algorithms Searching Algorithms THE BINARY SEARCH: can be used when the list has terms occurring in order of increasing size (for instance: if the terms are numbers, they are listed from smallest to largest; if they are words, they are listed in alphabetic order). Procedures of the Binary search algorithm: Compare the element to be located to the middle term of the list. The list is then split into two smaller sublists of the same size, or where one of these smaller lists has one fewer term than the other. The search continues by restricting the search to the appropriate sublist based on the comparison of the element to be located and the middle term. The binary search algorithm is much more efficient than the linear search algorithm. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 10 / 41

11 Algorithms Searching Algorithms Example: Search 19 in the list Split the list into 2 subsets with 8 terms each { } { } Compare 19 with the largest element of the first set 19 > 10 search 19 in the second set Split the second subset into 2 smaller subsets { } { } Compare 19 with > 16 search 19 in the second set Split the second subset as: { 18 19} {20 22} Compare 19 > 19 is false search 19 in {18 19} Split the subset as : {18} {19} Since 19 > 18 search restricted to the second list. Finally 19 is located at the 14th element of the original list ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 11 / 41

12 Algorithms Searching Algorithms The pseudocode for the binary search algorithm is displayed as Algorithm 3. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 12 / 41

13 Algorithms Sorting Sorting Problem: putting these elements into a list in which the elements are in increasing order. For instance, sorting the list 7, 2, 1, 4, 5, 9 produces the list 1, 2, 4, 5, 7, 9. Sorting the list d, h, c, a, f (using alphabetical order) produces the list a, c, d, f, h. The bubble sort: is one of the simplest sorting algorithms. It puts a list into increasing order by successively comparing adjacent elements, interchanging them if they are in the wrong order. Procedures of the bubble sort algorithm: Perform the basic operation, that is, interchanging a larger element with a smaller one following it, starting at the beginning of the list, for a full pass. Iterate this procedure until the sort is complete. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 13 / 41

14 Algorithms Sorting Example: Use the bubble sort to put 3, 2, 4, 1, 5 into increasing order. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 14 / 41

15 Algorithms Sorting The insertion sort: is a simple sorting algorithm, but it is usually not the most efficient. Procedures of the insertion sort algorithm: The insertion sort begins with the second element and compares this second element with the first element. The insertion sort inserts it before the first element if it does not exceed the first element and after the first element if it exceeds the first element. At this point, the first two elements are in the correct order. The third element is then compared with the first element, and if it is larger than the first element, it is compared with the second element; it is inserted into the correct position among the first three elements. In general, in the jth step of the insertion sort, the jth element of the list is inserted into the correct position in the list of the previously sorted j - 1 elements. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 15 / 41

16 Algorithms Sorting Example: Use the insertion sort to put 3, 2, 4, 1, 5 into increasing order. First, compare 2 and 3. As 2 is lower, we get 2,3,4,1,5. Insert the third element 4 in the comparison. Because 2 < 4 and 3 < 4, 4 remains in the third place to get 2,3,4,1,5. To find the place of 1, we put it in the 1st place because 1 < 2 to get 1,2,3,4,5 Compare the last element 5 to the rest of the elements successively, we put it in the last order as 5 > 4. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 16 / 41

17 Algorithms Greedy Algorithms Greedy Algorithm: goals to solve optimization problems by finding a solution to the given problem that either minimizes or maximizes the value of some parameter. The algorithm make what seems to be the best choice at each step. Finding a route between two cities with smallest total mileage Determining a way to encode messages using the fewest bits possible Finding a set of fiber links between network nodes using the least amount of fiber. You have to prove that a greedy algorithm always finds an optimal solution. (we call the algorithm greedy whether or not it finds an optimal solution.) To do this, we either prove that the solution is optimal or we show that there is a counterexample where the algorithm yields a nonoptimal solution. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 17 / 41

18 Algorithms Greedy Algorithms Example: Consider the problem of making n cents (67 cents for example) change with quarters [25 cents], dimes [10 cents], nickels [5 cents] and pennies [1 cent], and using the least total number of coins. Select a quarter, leaving 42 cents. Select a second quarter, leaving 17 cents. Select a dime, leaving 7 cents. Select a nickel, leaving 2 cents. Select a penny, leaving 1 cent Select a penny. Remark: if we have only quarters, dimes and pennies the change for 30 cents would be made using 6 coins = 1 quarter + 5 pennies. Whereas a better solution is equal to 3 coins = 3 dimes! ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 18 / 41

19 Algorithms Greedy Algorithms Example: Suppose we have a group of proposed talks with preset start and end times. Devise a greedy algorithm to schedule as many of these talks as possible in a lecture hall, under the assumptions that once a talk starts, it continues until it ends, no two talks can proceed at the same time, and a talk can begin at the same time another one ends. Assume that talk j begins at time s j (where s stands for start) and ends at time e j (where e stands for end). ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 19 / 41

20 Algorithms Greedy Algorithms Homework [due 29th of Oct]. From the text book, Section 3.1, page 202 Questions: Q2,Q10, Q14, Q20, Q34, and Q38. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 20 / 41

21 The Growth of Functions Big-O Notation Big-O Notation Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers.we say that f (x) is O(g(x)) if there are constants C and k such that f (x) C g(x) whenever x > k. [This is read as f (x) is big-oh of g(x). ] C and k are called witnesses to the relationship f (x) is O(g(x)). Approach to work with the definition of big O Notation Select a value of k for which the size of f (x) can be readily estimated when x > k. Find a value of C for which f (x) C g(x) for x > k. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 21 / 41

22 The Growth of Functions Big-O Notation Example: Show that f (x) = x 2 + 2x + 1 is O(x 2 ). Choose k = 1 x > 1. When x > 1 x 2 + 2x + 1 x 2 + 2x 2 + x 2 = 4x 2. Consequently, we can take C = 4 and k = 1 as witnesses to show that f (x) is O(x 2 ). [What if k=2?] Note that it is not necessary to use absolute values here because all functions in these equalities are positive when x is positive. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 22 / 41

23 The Growth of Functions Big-O Notation Observe that in the relationship f (x) is O(x 2 ), x 2 can be replaced by any function with larger values than x 2. For example, f (x) is O(x 3 ), f (x) is O(x 2 + x + 7), and so on. Note that in Example 1 we have two functions, f (x) = x 2 + 2x + 1 and g(x) = x 2, such that f (x) is O(g(x)) and g(x) is O(f (x)). We say that two functions f (x) and g(x) that satisfy both of these big-o relationships are of the same order. It is acceptable to write f (x) O(g(x)) because O(g(x)) represents the set of functions that are O(g(x)). When big-o notation is used, the function g in the relationship f (x) is O(g(x)) is chosen to be as small as possible. In subsequent discussions, we will almost always deal with functions that take on only positive values. All references to absolute values can be dropped when working with big-o estimates for such functions. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 23 / 41

24 The Growth of Functions Big-O Notation Example: Show that f (x) = 7x 2 is O(x 3 ). Choose k = 7 x > 7. Multiplying both sides of x > 7 by x 2, we have 7x 2 < x 3. Consequently, we can take C = 1 and k = 7 as witnesses to establish the relationship 7x 2 is O(x 3 ). Alternatively, when x > 1, we have 7x 2 < 7x 3, so that C = 7 and k = 1 are also witnesses to the relationship 7x 2 is O(x 3 ). Big-O Estimates for Some Important Functions Let f (x) = a n x n + a n 1 x n a 1 x + a 0, where a 0, a 1,, a n 1, a n are real numbers. Then f (x) is O(x n ). ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 24 / 41

25 The Growth of Functions Big-O Estimates for Some Important Functions Example: How can big-o notation be used to estimate the sum of the first n positive integers?. Because each of the integers in the sum of the first n positive integers does not exceed n, it follows that n n + n + + n = n.n = n 2. From this inequality it follows that n is O(n 2 ), taking C = 1 and k = 1 as witnesses. Example: Give big-o estimates for the factorial function and the logarithm of the factorial function. A big-o estimate for n! can be obtained by noting that each term in the product does not exceed n. n! = n n.n.n. n = n n From this inequality it follows that n! is O(n n ), taking C = 1 and k = 1 as witnesses. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 25 / 41

26 The Growth of Functions Big-O Estimates for Some Important Functions Taking logarithms of both sides of the inequality established for n!, we obtain log n! log n n = n log n. This implies that log n! is O(n log n), again taking C = 1 and k = 1 as witnesses. Example: use the inequality n < 2 n to show that log n is O(n).. n < 2 n log n < n From this inequality it follows that log n is O(n), taking C = 1 and k = 1 as witnesses. Big-O notation is used to estimate the number of operations needed to solve a problem using a specified procedure or algorithm. The functions used in these estimates often include the following: 1, log n, n, n log n, n 2, 2 n, n! ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 26 / 41

27 The Growth of Functions Big-O Estimates for Some Important Functions ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 27 / 41

28 The Growth of Functions The Growth of Combinations of Functions THEOREM 2 Suppose that f 1 (x) is O(g 1 (x)) and that f 2 (x) is O(g 2 (x)). Then (f 1 + f 2 )(x) is O(max( g 1 (x), g 2 (x) )). COROLLARY 1 Suppose that f 1 (x) and f 2 (x) are both O(g(x)). Then (f 1 + f 2 )(x) is O(g(x)). THEOREM 3 Suppose that f 1 (x) is O(g 1 (x)) and f 2 (x) is O(g 2 (x)). Then (f 1 f 2 )(x) is O(g 1 (x)g 2 (x)). ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 28 / 41

29 The Growth of Functions Big-O Estimates for Some Important Functions Example: Give a big-o estimate for f (n) = 3n log(n!) + (n 2 + 3) log n, where n is a positive integer.. For the first part 3n log(n!), we have two subparts 3n and log(n!). As we just mentioned, log(n!) is O(n log n) while 3n is O(n). The product of the two subparts implies that 3n log(n!) is O(n 2 log n). For the second part (n 2 + 3) log n, we have two subparts (n 2 + 3) and log n. As we mentioned, log(n) is O(n) while n is O(n 2 ). The product of the two subparts implies that (n 2 + 3) log n is O(n 2 log n). Therefore, the two big-o estimates for the products shows that f (n) = 3n log(n!) + (n 2 + 3) log n is O(n 2 log n). ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 29 / 41

30 The Growth of Functions Big-Omega and Big-Theta Notation Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers.we say that f (x) is Ω(g(x)) if there are positive constants C and k such that f (x) C g(x) whenever x > k. [This is read as f (x) is big-omega of g(x). ] There is a strong connection between big-o and big-omega notation. In particular, f (x) is Ω(g(x)) if and only if g(x) is O(f (x)). The function f (x) = 8x 3 + 5x is Ω(g(x)), where g(x) is the function g(x) = x 3. This is easy to see because f (x) = 8x 3 + 5x x 3 for all positive real numbers x. This is equivalent to saying that g(x) = x 3 is O(8x 3 + 5x 2 + 7) ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 30 / 41

31 The Growth of Functions Big-Omega and Big-Theta Notation Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f (x) is Θ(g(x)) if f (x) is O(g(x)) and f (x) is Ω(g(x)). When f (x) is Θ(g(x)) we say that f is big-theta of g(x), that f (x) and g(x) are of the same order. Example: Show that 3x 2 + 8x log x is Θ(x 2 ). Because 0 8x log x 8x 2, it follows that 3x 2 + 8x log x 11x 2 for x > 1. Consequently, 3x 2 + 8x log x is O(x 2 ). Clearly, x 2 is O(3x 2 + 8x log x). Consequently, 3x 2 + 8x log x is Θ(x 2 ). Homework [due 29th of Oct]. From the text book, Section 3.2, page 216 Questions: Q2,Q4, Q15, Q26, and Q30 [Parts: a,d]. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 31 / 41

32 Complexity of Algorithms Time Complexity How can the efficiency [computational complexity] of an algorithm be analyzed? The time used by a computer to solve a problem using the algorithm [time complexity]. The amount of computer memory required to implement the algorithm [space complexity]. The time complexity of an algorithm can be expressed in terms of the number of operations used by the algorithm when the input has a particular size. The operations used to measure time complexity can be the comparison of integers, the addition of integers, the multiplication of integers, the division of integers, or any other basic operation. Time complexity is described in terms of the number of operations required instead of actual computer time because of the difference in time needed for different computers to perform basic operations. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 32 / 41

33 Complexity of Algorithms Time Complexity Describe the time complexity of Algorithm 1 of Section 3.1 for finding the maximum element in a finite set of integers.? Exactly 2(n - 1) + 1 = 2n - 1 comparisons are used. Hence, the algorithm has time complexity O(n), measured in terms of the number of comparisons used. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 33 / 41

34 Complexity of Algorithms Time Complexity Describe the time complexity of Algorithm 2 of Section 3.1 for the linear search algorithm.? If x = a i 2i + 1 comparisons are used. The most comparisons, 2n + 2, are required when the element is not in the list [Worst case]. Hence, a linear search requires O(n) comparisons in the worst case, because 2n + 2 is O(n). ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 34 / 41

35 Complexity of Algorithms Time Complexity Describe the time complexity of Algorithm 3 of Section 3.1 for the binary search algorithm.? Assume that there are n = 2 k elements in the list k = log n. Each step we have i < j and x > a m comparisons. At every stage we have 2 k x elements where x is the number of the stage up to k x = 0. Hence, at most 2k + 2 = 2 log n + 2 comparisons are required which is O(log n) ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 35 / 41

36 Complexity of Algorithms Time Complexity AVERAGE-CASE COMPLEXITY The average number of operations used to solve the problem over all possible inputs of a given size is found in this type of analysis [See example 4 page 221]. Although we have counted the comparisons needed to determine whether we have reached the end of a loop, these comparisons are often not counted. From this point on we will ignore such comparisons. What is the worst-case complexity of the bubble sort in terms of the number of comparisons made? We need n-1 passes. In the i th pass, there are n i comparisons. Hence, the number of comparisons is n 1 (n 1)n i=1 (n i) = 2 as n k=1 k = n(n+1) 2 Consequently, it has O(n 2 ) complexity. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 36 / 41

37 Complexity of Algorithms Time Complexity What is the worst-case complexity of the insertion sort in terms of the number of comparisons made? In the worst case, j comparisons are required to insert the j th element into the correct position. j 1 with the ordered elements and one with itself to stop. Therefore, the number of comparisons is n = n (n+1)n i=2 (i) = 2 1 as n k=1 k = n(n+1) 2 Consequently, it has O(n 2 ) complexity. The most efficient sorting algorithms can sort n items in O(n log n) ECOM time, as Discrete we Mathematics will show- Ch.3 later. Dr. Musbah Shaat 37 / 41

38 Complexity of Algorithms Complexity of Matrix Multiplication How many additions of integers and multiplications of integers are used by Algorithm 1 to multiply two n n matrices with integer entries? There are n 2 entries in the product of A and B. To find each entry requires a total of n multiplications and n - 1 additions. Hence, a total of n 3 multiplications and n 2 (n 1) additions are used. Multiplying two n n matrices directly from the definition requires O(n 3 ) multiplications and additions. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 38 / 41

39 Complexity of Algorithms Complexity of Matrix Multiplication Example: In which order should the matrices A 1, A 2, and A 3 where A 1 is 30 20, A 2 is 20 40, and A 3 is 40 10, all with integer entries- be multiplied to use the least number of multiplications of integers? There are two possible ways to compute A 1, A 2, A 3. These are A 1 (A 2 A 3 ) and (A 1 A 2 )A 3. If A 2 and A 3 are first multiplied, a total of = 8000 multiplications of integers are used to obtain the matrix A 2 A 3. Then, to multiply A 1 and A 2 A 3 requires = 6000 multiplications. Hence, a total of = 14, 000 multiplications. if A 1 and A 2 are first multiplied, then = 24, 000 multiplications are used to obtain the matrix A 1 A 2. Then, to multiply A 1 A 2 and A 3 requires = 12, 000 multiplications. Hence, a total of 24, , 000 = 36, 000 multiplications. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 39 / 41

40 Complexity of Algorithms Complexity of Matrix Multiplication Brute-force algorithm, a problem is solved in the most straightforward manner based on the statement of the problem and the definitions of terms. Brute-force algorithms are designed to solve problems without regard to the computing resources required. ECOM Discrete Mathematics - Ch.3 Dr. Musbah Shaat 40 / 41

41 Homework [due 5th of Nov]. From the text book, Section 3.3, page 229 Questions: Q2, Q3, Q8 and Q22[Parts a,b]. End of Chapter # 3

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms CompSci 102 Discrete Math for Computer Science Announcements Read for next time Chap. 3.1-3.3 Homework 3 due Tuesday We ll finish Chapter 2 first today February 7, 2012 Prof. Rodger Chap. 3.1 Algorithms

More information

With Question/Answer Animations

With Question/Answer Animations Chapter 3 With Question/Answer Animations Copyright McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education. Chapter Summary

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

3. Algorithms. What matters? How fast do we solve the problem? How much computer resource do we need?

3. Algorithms. What matters? How fast do we solve the problem? How much computer resource do we need? 3. Algorithms We will study algorithms to solve many different types of problems such as finding the largest of a sequence of numbers sorting a sequence of numbers finding the shortest path between two

More information

Discrete Mathematics CS October 17, 2006

Discrete Mathematics CS October 17, 2006 Discrete Mathematics CS 2610 October 17, 2006 Uncountable sets Theorem: The set of real numbers is uncountable. If a subset of a set is uncountable, then the set is uncountable. The cardinality of a subset

More information

COMP 182 Algorithmic Thinking. Algorithm Efficiency. Luay Nakhleh Computer Science Rice University

COMP 182 Algorithmic Thinking. Algorithm Efficiency. Luay Nakhleh Computer Science Rice University COMP 182 Algorithmic Thinking Algorithm Efficiency Luay Nakhleh Computer Science Rice University Chapter 3, Sections 2-3 Reading Material Not All Correct Algorithms Are Created Equal We often choose the

More information

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2 CompSci 230 Discrete Math for Computer Science Announcements Read Chap. 3.1-3.3 No recitation Friday, Oct 11 or Mon Oct 14 October 8, 2013 Prof. Rodger Section 3.2 Big-O Notation Big-O Estimates for Important

More information

The Growth of Functions (2A) Young Won Lim 4/6/18

The Growth of Functions (2A) Young Won Lim 4/6/18 Copyright (c) 2015-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Lecture 4: Best, Worst, and Average Case Complexity. Wednesday, 30 Sept 2009

Lecture 4: Best, Worst, and Average Case Complexity. Wednesday, 30 Sept 2009 @? @? @? @? @? @? @? @? @? @ 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 0 0 0 0 0 0 0 0 0 0 ' ' ' ' ' ' ' ' ' ' Lecture 4: Best, Worst, and Average Case Complexity CS204/209 : Algorithms (and Scientific Computing)

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

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

CISC 235: Topic 1. Complexity of Iterative Algorithms

CISC 235: Topic 1. Complexity of Iterative Algorithms CISC 235: Topic 1 Complexity of Iterative Algorithms Outline Complexity Basics Big-Oh Notation Big-Ω and Big-θ Notation Summations Limitations of Big-Oh Analysis 2 Complexity Complexity is the study of

More information

3 The Fundamentals:Algorithms, the Integers, and Matrices

3 The Fundamentals:Algorithms, the Integers, and Matrices 3 The Fundamentals:Algorithms, the Integers, and Matrices 3.1 Algrithms Definition 1 An algorithm is a finite set of instructions for performing a computation or solving a problem. Dijkstra s mini language

More information

Describe an algorithm for finding the smallest integer in a finite sequence of natural numbers.

Describe an algorithm for finding the smallest integer in a finite sequence of natural numbers. Homework #4 Problem One (2.1.2) Determine which characteristics o f an algorithm the following procedures have and which they lack. a) procedure double(n: positive integer) while n > 0 n := 2n Since n

More information

Introduction. An Introduction to Algorithms and Data Structures

Introduction. An Introduction to Algorithms and Data Structures Introduction An Introduction to Algorithms and Data Structures Overview Aims This course is an introduction to the design, analysis and wide variety of algorithms (a topic often called Algorithmics ).

More information

CSCE 222 Discrete Structures for Computing

CSCE 222 Discrete Structures for Computing CSCE 222 Discrete Structures for Computing Algorithms Dr. Philip C. Ritchey Introduction An algorithm is a finite sequence of precise instructions for performing a computation or for solving a problem.

More information

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

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count Types of formulas for basic operation count Exact formula e.g., C(n) = n(n-1)/2 Algorithms, Design and Analysis Big-Oh analysis, Brute Force, Divide and conquer intro Formula indicating order of growth

More information

CS481: Bioinformatics Algorithms

CS481: Bioinformatics Algorithms CS481: Bioinformatics Algorithms Can Alkan EA224 calkan@cs.bilkent.edu.tr http://www.cs.bilkent.edu.tr/~calkan/teaching/cs481/ Reminder The TA will hold a few recitation sessions for the students from

More information

Algorithms 2/6/2018. Algorithms. Enough Mathematical Appetizers! Algorithm Examples. Algorithms. Algorithm Examples. Algorithm Examples

Algorithms 2/6/2018. Algorithms. Enough Mathematical Appetizers! Algorithm Examples. Algorithms. Algorithm Examples. Algorithm Examples Enough Mathematical Appetizers! Algorithms What is an algorithm? Let us look at something more interesting: Algorithms An algorithm is a finite set of precise instructions for performing a computation

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

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

Divide and Conquer Problem Solving Method

Divide and Conquer Problem Solving Method Divide and Conquer Problem Solving Method 1. Problem Instances Let P be a problem that is amenable to the divide and conquer algorithm design method and let P 0, P 1, P 2, be distinct instances of the

More information

Algorithms: COMP3121/3821/9101/9801

Algorithms: COMP3121/3821/9101/9801 NEW SOUTH WALES Algorithms: COMP3121/3821/9101/9801 Aleks Ignjatović School of Computer Science and Engineering University of New South Wales TOPIC 4: THE GREEDY METHOD COMP3121/3821/9101/9801 1 / 23 The

More information

Theory of Computation

Theory of Computation Theory of Computation Unit 4-6: Turing Machines and Computability Decidability and Encoding Turing Machines Complexity and NP Completeness Syedur Rahman syedurrahman@gmail.com Turing Machines Q The set

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

CS Analysis of Recursive Algorithms and Brute Force

CS Analysis of Recursive Algorithms and Brute Force CS483-05 Analysis of Recursive Algorithms and Brute Force 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

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3 April 8, 2014 Contents 1 Overview 3 2 Principles of Counting 3 2.1 Pigeon-Hole Principle........................ 3 2.2 Permutations and Combinations.................. 3 2.3 Binomial Coefficients.........................

More information

Mat Week 6. Fall Mat Week 6. Algorithms. Properties. Examples. Searching. Sorting. Time Complexity. Example. Properties.

Mat Week 6. Fall Mat Week 6. Algorithms. Properties. Examples. Searching. Sorting. Time Complexity. Example. Properties. Fall 2013 Student Responsibilities Reading: Textbook, Section 3.1 3.2 Assignments: 1. for sections 3.1 and 3.2 2. Worksheet #4 on Execution s 3. Worksheet #5 on Growth Rates Attendance: Strongly Encouraged

More information

Student Responsibilities Week 6. Mat Properties of Algorithms. 3.1 Algorithms. Finding the Maximum Value in a Finite Sequence Pseudocode

Student Responsibilities Week 6. Mat Properties of Algorithms. 3.1 Algorithms. Finding the Maximum Value in a Finite Sequence Pseudocode Student Responsibilities Week 6 Mat 345 Week 6 Reading: Textbook, Section 3.1 3. Assignments: 1. for sections 3.1 and 3.. Worksheet #4 on Execution Times 3. Worksheet #5 on Growth Rates Attendance: Strongly

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

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 Computer Science Lecture 5: Algorithms

Introduction to Computer Science Lecture 5: Algorithms Introduction to Computer Science Lecture 5: Algorithms Tian-Li Yu Taiwan Evolutionary Intelligence Laboratory (TEIL) Department of Electrical Engineering National Taiwan University tianliyu@cc.ee.ntu.edu.tw

More information

LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS

LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS Department of Computer Science and Engineering 1 UNIT 1 Basic Concepts Algorithm An Algorithm is a finite

More information

CSCE 750, Spring 2001 Notes 1 Page 1 An outline of the book 1. Analyzing algorithms 2. Data abstraction 3. Recursion and induction 4. Sorting 5. Selec

CSCE 750, Spring 2001 Notes 1 Page 1 An outline of the book 1. Analyzing algorithms 2. Data abstraction 3. Recursion and induction 4. Sorting 5. Selec CSCE 750, Spring 2001 Notes 1 Page 1 An outline of the book 1. Analyzing algorithms 2. Data abstraction 3. Recursion and induction 4. Sorting 5. Selection and adversary arguments 6. Dynamic sets and searching

More information

Lecture 6: Introducing Complexity

Lecture 6: Introducing Complexity COMP26120: Algorithms and Imperative Programming Lecture 6: Introducing Complexity Ian Pratt-Hartmann Room KB2.38: email: ipratt@cs.man.ac.uk 2015 16 You need this book: Make sure you use the up-to-date

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

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 310 Advanced Data Structures and Algorithms Runtime Analysis May 31, 2017 Tong Wang UMass Boston CS 310 May 31, 2017 1 / 37 Topics Weiss chapter 5 What is algorithm analysis Big O, big, big notations

More information

Topic 17. Analysis of Algorithms

Topic 17. Analysis of Algorithms Topic 17 Analysis of Algorithms Analysis of Algorithms- Review Efficiency of an algorithm can be measured in terms of : Time complexity: a measure of the amount of time required to execute an algorithm

More information

2. (25%) Suppose you have an array of 1234 records in which only a few are out of order and they are not very far from their correct positions. Which

2. (25%) Suppose you have an array of 1234 records in which only a few are out of order and they are not very far from their correct positions. Which COT 6401 The Analysis of Algorithms Midterm Test Open books and notes Name - SSN - 1. (25%) Suppose that the function F is dened for all power of 2 and is described by the following recurrence equation

More information

csci 210: Data Structures Program Analysis

csci 210: Data Structures Program Analysis csci 210: Data Structures Program Analysis Summary Topics commonly used functions analysis of algorithms experimental asymptotic notation asymptotic analysis big-o big-omega big-theta READING: GT textbook

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

Introduction to Algorithms

Introduction to Algorithms What is an algorithm? Introduction to Algorithms Here are some definitions: An algorithm is a description of a procedure which terminates with a result. An algorithm is a step-by-step problem-solving procedure,

More information

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

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms (2017F) Lecture4: Analysis of Algorithms Daijin Kim CSE, POSTECH dkim@postech.ac.kr Running Time Most algorithms transform input objects into output objects. The running time of an algorithm typically

More information

CS325: Analysis of Algorithms, Fall Final Exam

CS325: Analysis of Algorithms, Fall Final Exam CS: Analysis of Algorithms, Fall 0 Final Exam I don t know policy: you may write I don t know and nothing else to answer a question and receive percent of the total points for that problem whereas a completely

More information

Introduction to Algorithms and Asymptotic analysis

Introduction to Algorithms and Asymptotic analysis Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India An Institute of National Importance COM 501 Advanced

More information

Divide and Conquer CPE 349. Theresa Migler-VonDollen

Divide and Conquer CPE 349. Theresa Migler-VonDollen Divide and Conquer CPE 349 Theresa Migler-VonDollen Divide and Conquer Divide and Conquer is a strategy that solves a problem by: 1 Breaking the problem into subproblems that are themselves smaller instances

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

csci 210: Data Structures Program Analysis

csci 210: Data Structures Program Analysis csci 210: Data Structures Program Analysis 1 Summary Summary analysis of algorithms asymptotic analysis big-o big-omega big-theta asymptotic notation commonly used functions discrete math refresher READING:

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

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

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan Lecture 2 More Algorithm Analysis, Math and MCSS By: Sarah Buchanan Announcements Assignment #1 is posted online It is directly related to MCSS which we will be talking about today or Monday. There are

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

CSE 20. Lecture 4: Introduction to Boolean algebra. CSE 20: Lecture4

CSE 20. Lecture 4: Introduction to Boolean algebra. CSE 20: Lecture4 CSE 20 Lecture 4: Introduction to Boolean algebra Reminder First quiz will be on Friday (17th January) in class. It is a paper quiz. Syllabus is all that has been done till Wednesday. If you want you may

More information

Analysis of Algorithms

Analysis of Algorithms Analysis of Algorithms Section 4.3 Prof. Nathan Wodarz Math 209 - Fall 2008 Contents 1 Analysis of Algorithms 2 1.1 Analysis of Algorithms....................... 2 2 Complexity Analysis 4 2.1 Notation

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

Limitations of Algorithm Power

Limitations of Algorithm Power Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying

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

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015 CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015 Today Registration should be done. Homework 1 due 11:59pm next Wednesday, April 8 th. Review math

More information

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: 2017 2018 Time Allowed 2 Hours INSTRUCTIONS TO STUDENTS 1. This assessment consists of Eight (8) questions and comprises

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

Matrix Multiplication

Matrix Multiplication Matrix Multiplication Given two vectors a = [a 1,..., a k ] and b = [b 1,..., b k ], their inner product (or dot product) is a b = k i=1 a ib i [1, 2, 3] [ 2, 4, 6] = (1 2) + (2 4) + (3 6) = 24. We can

More information

CS 350 Algorithms and Complexity

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

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

ECOM Discrete Mathematics

ECOM Discrete Mathematics ECOM 2311- Discrete Mathematics Chapter # 1 : The Foundations: Logic and Proofs Fall, 2013/2014 ECOM 2311- Discrete Mathematics - Ch.1 Dr. Musbah Shaat 1 / 85 Outline 1 Propositional Logic 2 Propositional

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

Analysis of Algorithms

Analysis of Algorithms Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Analysis of Algorithms Input Algorithm Analysis

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

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and

More information

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N,

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N, Algorithm and Growth of Functions Benchaporn Jantarakongkul 1 Algorithm (algorithm) ก ก ก ก ก : ก {a i }=a 1,,a n a i N, ก ก : 1. ก v ( v ก ก ก ก ) ก ก a 1 2. ก a i 3. a i >v, ก v ก a i 4. 2. 3. ก ก ก

More information

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms REVIEW QUESTIONS Chapter 1: Foundations: Sets, Logic, and Algorithms 1. Why can t a Venn diagram be used to prove a statement about sets? 2. Suppose S is a set with n elements. Explain why the power set

More information

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts) Introduction to Algorithms October 13, 2010 Massachusetts Institute of Technology 6.006 Fall 2010 Professors Konstantinos Daskalakis and Patrick Jaillet Quiz 1 Solutions Quiz 1 Solutions Problem 1. We

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

MATH 363: Discrete Mathematics

MATH 363: Discrete Mathematics MATH 363: Discrete Mathematics Learning Objectives by topic The levels of learning for this class are classified as follows. 1. Basic Knowledge: To recall and memorize - Assess by direct questions. The

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

Fall 2016 Test 1 with Solutions

Fall 2016 Test 1 with Solutions CS3510 Design & Analysis of Algorithms Fall 16 Section B Fall 2016 Test 1 with Solutions Instructor: Richard Peng In class, Friday, Sep 9, 2016 Do not open this quiz booklet until you are directed to do

More information

Algorithms CMSC Homework set #1 due January 14, 2015

Algorithms CMSC Homework set #1 due January 14, 2015 Algorithms CMSC-27200 http://alg15.cs.uchicago.edu Homework set #1 due January 14, 2015 Read the homework instructions on the website. The instructions that follow here are only an incomplete summary.

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

Advanced Counting Techniques. Chapter 8

Advanced Counting Techniques. Chapter 8 Advanced Counting Techniques Chapter 8 Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence Relations Nonhomogeneous Recurrence Relations Divide-and-Conquer

More information

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 380 ALGORITHM DESIGN AND ANALYSIS CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 2: Asymptotic Analysis, Insertion Sort Text Reference: Chapters 2, 3 Space and Time Complexity For a given problem, may be a variety of algorithms that you

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

Ch 01. Analysis of Algorithms

Ch 01. Analysis of Algorithms Ch 01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T.

More information

CS1210 Lecture 23 March 8, 2019

CS1210 Lecture 23 March 8, 2019 CS1210 Lecture 23 March 8, 2019 HW5 due today In-discussion exams next week Optional homework assignment next week can be used to replace a score from among HW 1 3. Will be posted some time before Monday

More information

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions Assignment 4 CSci 3110: Introduction to Algorithms Sample Solutions Question 1 Denote the points by p 1, p 2,..., p n, ordered by increasing x-coordinates. We start with a few observations about the structure

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26 Homework #2 ( Due: Nov 8 ) Task 1. [ 80 Points ] Average Case Analysis of Median-of-3 Quicksort Consider the median-of-3 quicksort algorithm

More information

Induction and recursion. Chapter 5

Induction and recursion. Chapter 5 Induction and recursion Chapter 5 Chapter Summary Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms Mathematical Induction Section 5.1

More information

CS 161: Design and Analysis of Algorithms

CS 161: Design and Analysis of Algorithms CS 161: Design and Analysis of Algorithms Greedy Algorithms 1: Shortest Paths In Weighted Graphs Greedy Algorithm BFS as a greedy algorithm Shortest Paths in Weighted Graphs Dijsktra s Algorithm Greedy

More information

Algorithm Design Strategies V

Algorithm Design Strategies V Algorithm Design Strategies V Joaquim Madeira Version 0.0 October 2016 U. Aveiro, October 2016 1 Overview The 0-1 Knapsack Problem Revisited The Fractional Knapsack Problem Greedy Algorithms Example Coin

More information

R ij = 2. Using all of these facts together, you can solve problem number 9.

R ij = 2. Using all of these facts together, you can solve problem number 9. Help for Homework Problem #9 Let G(V,E) be any undirected graph We want to calculate the travel time across the graph. Think of each edge as one resistor of 1 Ohm. Say we have two nodes: i and j Let the

More information

Ch01. Analysis of Algorithms

Ch01. Analysis of Algorithms Ch01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T. Goodrich

More information

NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty.

NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty. EXAM 2 solutions (COT3100, Sitharam, Spring 2017) NAME:last first: UF-ID Section NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty. (1) Are the following functions one-to-one

More information

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms 1 Chapter Summary Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms 2 Section 5.1 3 Section Summary Mathematical Induction Examples of

More information

Searching Algorithms. CSE21 Winter 2017, Day 3 (B00), Day 2 (A00) January 13, 2017

Searching Algorithms. CSE21 Winter 2017, Day 3 (B00), Day 2 (A00) January 13, 2017 Searching Algorithms CSE21 Winter 2017, Day 3 (B00), Day 2 (A00) January 13, 2017 Selection Sort (MinSort) Pseudocode Rosen page 203, exercises 41-42 procedure selection sort(a 1, a 2,..., a n : real numbers

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

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

Lecture 7: More Arithmetic and Fun With Primes

Lecture 7: More Arithmetic and Fun With Primes IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 7: More Arithmetic and Fun With Primes David Mix Barrington and Alexis Maciel July

More information

Fall 2017 November 10, Written Homework 5

Fall 2017 November 10, Written Homework 5 CS1800 Discrete Structures Profs. Aslam, Gold, & Pavlu Fall 2017 November 10, 2017 Assigned: Mon Nov 13 2017 Due: Wed Nov 29 2017 Instructions: Written Homework 5 The assignment has to be uploaded to blackboard

More information

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة Benha University Final Exam Class: 3 rd Year Students Subject: Design and analysis of Algorithms Faculty of Computers & Informatics Date: 10/1/2017 Time: 3 hours Examiner: Dr. El-Sayed Badr Answer the

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