



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Spring 2001;
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!
CS231 Algorithms Handout # Prof Lyn Turbak May 9, 2001 Wellesley College
CS231 JEOPARDY: THE HOME VERSION The game that turns CS231 into CS23 fun!
Asymptotics
------------------------------------------------------------------------------------------------------------ [1] Of the recurrence equations below, indicate
a. T(n) = 1 + T(n - a), a > 0 b. T(n) = 1 + T(an), 0 < a < 1 c. T(n) = n + T(n - a), a > 0 d. T(n) = n + T(an), 0 < a < 1 ------------------------------------------------------------------------------------------------------------ [2] In a graph G = (V, E), under what conditions is O(Vlg(E)) = O(Vlg(V))? ------------------------------------------------------------------------------------------------------------
[3] List all of the following sets that are subsets of O(n^2 )
a. o(n) f. o(n2 ) k. o(n3 )
b. O(n) g. O(n2 ) l. O(n3 )
c. Θ(n) h. Θ(n2 ) m. Θ(n3 )
d. Ω(n) i. Ω(n2 ) n. Ω(n3 )
e. ω(n) j. ω(n2 ) o. ω(n3 ) ------------------------------------------------------------------------------------------------------------ [4] List all of the following sets that are non-empty:
a. o(n) ∩ Ο(n) b. o(n) ∩ Θ(n) c. o(n) ∩ Ω(n) d. o(n) ∩ ω(n) e. Ο(n) – (o(n) ∪ Θ(n)) ------------------------------------------------------------------------------------------------------------ [5] Consider the recurrence T(n) = n + k(n/2). For each of the following sets, give a value of k ≥ 1 such that T(n) will have a solution in that set.
a. Θ(n) b. Θ(n lg(n)) c. Θ(n2 ) ------------------------------------------------------------------------------------------------------------
[1]** What is the best worst-case running time for a comparison-based sort of n numbers? ------------------------------------------------------------------------------------------------------------ [2] Consider sorting n numbers (not necessarily distinct) in the range [1..n]. List all of the following algorithms that have O(n lg(n)) worst-case running times on this problem:
a. selection sort b. insertion sort c. bubble sort d. merge sort e. quick sort (using two-finger partition with random pivot) f. heap sort g. tree sort (insert elements into binary search tree, and extract them via in-order traversal.) h. counting sort i. radix sort j. general bucket sort
Extra: Answer the question for (1) average-case; (2) best-case; (3) Θ(n lg(n)) ------------------------------------------------------------------------------------------------------------
[3] The quicksort algorithms we studied in class had Θ(n lg n) expected running time
but Θ(n2 ) worst-case running time. Describe a single simple modification to these algorithms
that makes them run in Θ(n lg n) worst-case time ------------------------------------------------------------------------------------------------------------ [4] Given a heap with n elements, what is the best-case running time for an algorithm that removes all the elements from the heap in sorted order? ------------------------------------------------------------------------------------------------------------ [5] Using an O(n) worst-case linear-time black-box subroutine for finding the median of a set of n numbers, describe a simple linear-time algorithm that solves the selection problem for an arbitrary order statistic. ------------------------------------------------------------------------------------------------------------
Graphs
------------------------------------------------------------------------------------------------------------ [1] What is the name of a directed graph
a. That has no back edges? b. That has no back edges, forward edges, or cross edges? ------------------------------------------------------------------------------------------------------------ [2] How many strongly connected components does a Hamiltonian graph have?
------------------------------------------------------------------------------------------------------------ [3] Suppose that G is a complete graph of cities whose edges indicate the distance between the cities. Match each of the following problems with the algorithms (there may be more than one) that can be used to solve it:
a. Find the smallest length of fiber-optic cable to connect all the cities. b. Find the shortest distance path between two cities. c. Find the path between two cities that visits the fewest cities in-between.
------------------------------------------------------------------------------------------------------------ [4] Draw the smallest graph for which depth-first search induces a different tree from breadth-first search. ------------------------------------------------------------------------------------------------------------ [5] Arrange 4 vertices in a DAG such that it has it has exactly four topological sorts.
Extra : one topological sort; two topological sorts; what is the maximum number of topological sorts?
Complexity
------------------------------------------------------------------------------------------------------------ [1] For each of the following statements, indicate whether (1) it is known to be true (2) it is known to be false or (3) its truth is unknown.
a. P ≠ NP b. P ⊆ NP c. P = co-NP d. P ⊆ co-NP e. NP = co-NP f. NP ⊆ co-NP ------------------------------------------------------------------------------------------------------------ [2] Suppose that A is a language in P. For each of the following conditions, indicate whether it is sufficient to prove that B is in P.
a. A ≤P B b. B ≤P A c. ≤P B d. B ≤P u ------------------------------------------------------------------------------------------------------------ [3] Suppose that A is an NP-complete language and B is in NP. For each of the following conditions, indicate whether it is sufficient to prove that B is NP complete.
a. A ≤P B b. B ≤P A c. For all L in NP, L ≤P B ------------------------------------------------------------------------------------------------------------ [4] Let L be the language {<A, k, n> | n is the kth smallest element of array A}. Using a black box algorithm AL that decides L in polynomial time, show that there is a
polynomial time algorithm that finds the kth order statistic of A in polynomial time. ------------------------------------------------------------------------------------------------------------ [5] A simple path between vertices a and b of a graph G is said to be hamiltonian if it includes all the vertices in G. In the following, assume that G is a complete, weighted graph, and that a and b are arbitrary vertices in G. For each of the following languages, indicate whether it is "obviously" in each of P, NP, or co-NP:
L1 = {<G, a, b, k> | there is a path between a and b whose weight is < k.} L2 = {<G, a, b, k> | there is a hamiltonian path between a and b whose weight is < k.} L3 = {<G, a, b, k> | all paths between a and b have weight < k.} L4 = {<G, a, b, k> | all hamiltonian paths between a and b have weight < k.} ------------------------------------------------------------------------------------------------------------