Download presentation
Presentation is loading. Please wait.
Published byBennett Dalton Modified over 9 years ago
1
1 Algorithms CSCI 235, Fall 2015 Lecture 39 Final Exam Review
2
2 Things to Review Asymptotic analysis There will be some short answer questions Algorithms covered Know basic algorithms Know running times Probability Review homework problems Recurrences Review examples from class and homework
3
3 Asymptotics 1. Consider the set S = {a, b, c, d, e} of five functions a through e, which are classified as follows: In the following table, for each row, indicate the result of the intersection R S. R (nlgn) O(n) o(lgn) (1) (n 2 )
4
4 More Asymptotics 2.Which of the following sets of functions are subsets of O(n 2 )? o(n)o(n 2 )o(n 3 ) O(n)O(n 2 )O(n 3 ) (n) (n 2 ) (n 3 ) (n) (n 2 ) (n 3 ) (n) (n 2 ) (n 3 ) 3. Which of the following sets are empty?
5
5 Greedy algorithms/Huffman codes 4.What is the total number of bits required to encode the word, "ABRACADABRA" using an optimal Huffman code? How many bits would be required to encode "ABRACADABRA" with a fixed length code?
6
6 Dynamic Programming and Recurrences 5. Given a numeric array A, the partial sum array PSA(A) is an array P that has the same length as A in which P[i] is the sum of all the elements in the array segment A[1..i]. For example, the following figure show an array A and its partial sum array P = PSA(A): A = 2 5 3 6 1 4 P = 2 7 10 16 17 21
7
7 Problem 5 continued PSA1(A) P <- makeArray(length[A]) for i <-1 to length[A] do P[i] <- Segment-Sum(A, 1, i) return P Segment-Sum(A, lo, hi) if lo > hi then return 0 else return A[hi] + Segment-Sum(A, lo, hi-1) a) What is the running time of PSA1?
8
8 More problem 5 b) The algorithm given is inefficient. Segment-sum(A, 1, i) is computed multiple times. Write a dynamic programming solution for PSA. What is the running time of this solution?
9
9 Graphs a)Draw a single graph with the following features: 5 vertices, 6 edges, 3 strongly connected components, 2 weakly connected components. b) Can you perform a topological sort on this graph? c) Show the tree from a Breadth First search of the graph. d) Show the tree from a depth first search of the graph. Label the edges (tree, back, forward or cross)
10
10 Complexity 7.For each of the following problems, indicate whether it is in P or NP (or neither or both): a)The traveling salesman problem b)Heap sort c)The equivalence problem (showing two programs are the same) d)What would you have to do to show that P does not equal NP?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.