Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms CSCI 235, Spring 2019 Lecture 12 Midterm I Review

Similar presentations


Presentation on theme: "Algorithms CSCI 235, Spring 2019 Lecture 12 Midterm I Review"— Presentation transcript:

1 Algorithms CSCI 235, Spring 2019 Lecture 12 Midterm I Review

2 Problem 1: Running time of iterative algorithms
1. Find the running time of the following algorithms: (a) sample(A, n) sum = 0 for i = 1 to n do for j = 1 to n do for k = 1 to n/2 do sum = sum + A[i, j, k] (b) foo(n) for j = 1 to i do print i*n + j

3 Problem 2: Recurrence Equations
Find the running time of the following algorithms: (a) fib(x) if x = 0 or x = 1 then return 1 else return fib(x-1) + fib(x -2) (b) review(n) exam(n) //assume this runs in Q(n) time review(n/3)

4 Analyzing algorithms Know how to find the running time of recursive algorithms. Know how to find the running time of iterative algorithms (e.g. Insertion sort from lecture 2). Find the number of times a comparison is executed. Be able to express the running time of algorithms using O notation.

5 Problem 3: Asymptotic notation
3. f(n) = 20/n g(n) = 1/lg(n) Is f(n) o, O, Q, W or w of g(n)? (list all that apply)

6 Problem 4: Asymptotic notation
4. f(n) = lg(n) for n even g(n) = 0.5n2 + 37 3n2 for n odd a) Graph f(n) b) Is f(n) o, O, Q, W or w of g(n)? (list all that apply)

7 Problem 5. Probability 5. Suppose you throw two 4-sided dice (e.g. tetrahedral dice) with values of 1, 2, 3, or 4 on each side. a) What is the Sample Space? b) If event A is all the throws in which the sum of values is less than or equal to 3, list all the outcomes in event A.

8 Problem 5 continued Suppose we define a discrete random variable, s, such that the value of s is the sum of the dice from a single throw. List the values of s for each outcome in the sample space. d) What is the expected value for the sum of the two dice?


Download ppt "Algorithms CSCI 235, Spring 2019 Lecture 12 Midterm I Review"

Similar presentations


Ads by Google