1 / 8

Algorithms CSCI 235 , Fall 2019 Lecture 12 Midterm I Review

Algorithms CSCI 235 , Fall 2019 Lecture 12 Midterm I Review. 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

steffes
Download Presentation

Algorithms CSCI 235 , Fall 2019 Lecture 12 Midterm I Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AlgorithmsCSCI 235, Fall 2019Lecture 12Midterm 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 i = 1 to n do 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?

More Related