CMPS 101 Summer 2009 Homework Assignment 3
Solutions
1. (1 Point) The last exercise in the handout entitled Some Common Functions. 4n 2n Use Stirling's formula to prove that = n n . Proof: By Stirlings formula
2n 2 2n (1 + (1 / 2n) ) 2n (2n)! (2n)! e = 2
CMPS 101 Algorithms and Abstract Data Types
ADTs and Modules in Java and ANSI C
Introduction This document introduces the concepts of Modules and ADTs, and describes how to implement them in both Java and ANSI C. Informally, an Abstract Data Type (ADT) is
CMPS 101 Summer 2009 Homework Assignment 5
Solutions
1. (3 Points) p. 538: 22.2-2 Show the d and values that result from running breadth-first search on the undirected graph below using the following vertices as source. For each source, show the order in
CMPS 101 Summer 2009 Homework Assignment 8
(practice only, do not turn in)
1. (1 Point) 12.2-1 Suppose that we have numbers between 1 and 1000 in a binary search tree and want to search for the number 363. Which of the following sequences could not be the
CMPS 101 Summer 2009 Homework Assignment 7
1. (1 Point) Let x V (G ) and suppose that after INITIALIZE-SINGLE-SOURCE(G, s) is executed, some sequence of calls to Relax( ) causes d [ x ] to be set to a finite value. Then G contains an s-x path of weight d
CMPS 101 Summer 2009 Homework Assignment 6
Solutions
1. (1 Point) p.551: 22.4-1 Show the ordering of vertices produced by TOPOLOGICAL-SORT when it is run on the dag of Figure 22.8, under the assumption of Exercise 22.3-2. Solution:
m n o p
q
r
s
t
u
v
w
x
CMPS 101 Summer 2009 Homework Assignment 6
1. (1 Point) p.551: 22.4-1 Show the ordering of vertices produced by TOPOLOGICAL-SORT when it is run on the dag of Figure 22.8, under the assumption of Exercise 22.3-2. 2. (1 Point) p.557: 22.5-2 Show how the pro
CMPS 101 Summer 2009 Homework Assignment 5
1. (3 Points) p. 538: 22.2-2 Show the d and values that result from running breadth-first search on the undirected graph below using the following vertices as source. For each source, show the order in which vert
CMPS 101 Summer 2009 Homework Assignment 4
Solutions
1. (3 Points) Consider the function T (n) defined by the recurrence formula
1 n < 3 6 T ( n) = n3 2T ( n / 3 ) + n a. (1 Points) Use the iteration method to write a summation formula for T (n) . Solutio
CMPS 101 Summer 2009
Homework Assignment 4
1. (3 Points) Consider the function T (n) defined by the recurrence formula
1 n < 3 6 T ( n) = n3 2T ( n / 3 ) + n a. (1 Point) Use the iteration method to write a summation formula for T (n) . b. (1 Point) Use t
CMPS 101 Summer 2009 Homework Assignment 3
1. (1 Point) The last exercise in the handout entitled Some Common Functions. 4n 2n Use Stirling's formula to prove that = n n . 2. (2 Points) (Exercise 1 from the induction handout)
n(n + 1) i 3 = 2 . Do this t
CMPS 101 Summer 2009 Homework Assignment 2
Solutions
1. (1 Point) p.50: 3.1-1 Let f (n) and g (n) be asymptotically non-negative functions. Using the basic definition of notation, prove that f (n) + g (n) = (max( f (n), g (n) . Proof: Since f (n) and g (n
CMPS 101 Summer 2009 Homework Assignment 2
1. (1 Point) p.50: 3.1-1 Let f (n) and g (n) be asymptotically non-negative functions. Using the basic definition of notation, prove that f (n) + g (n) = (max( f (n), g (n) .
2. (1 Point) p.50: 3.1-3 Explain why
CMPS 101 Summer 2009 Homework Assignment 1
Solutions
1. (1 Point) p.27: 2.2-2 Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1] . Then find the second smallest element of A a
CMPS 101 Summer 2009 Homework Assignment 1
1. (1 Point) p.27: 2.2-2 Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1] . Then find the second smallest element of A and exchang
CMPS 101 Midterm 2 review One solution
Problem 7 from the review sheet: Let G be a directed graph. Prove that if G contains a directed cycle, then G contains a back edge. (Hint: use the white path theorem.) Proof: Suppose G contains a directed cycle, call
CMPS 101 Midterm 1 Some solutions to review problems and one additional problem
Problem 2 from the Midterm 1 review sheet State whether the following assertions are true or false. If any statements are false, give a related statement which is true. a. f (
CMPS 101 Algorithms and Abstract Data Types
Recurrence Relations
Iteration Method Recall the following example from the induction handout.
0 T ( n) = T ( n / 2 ) + 1 n =1 n2
We begin by illustrating a solution technique called Iteration, which consists of
CMPS 101 Summer 2009 Midterm Exam 2
Solutions
1. (20 Points) Let G be a directed graph. Determine whether, at any point during a Depth First Search of G, there can exist an edge of the following kind. No justification is required. (See last page for DFS p
CMPS 101 Algorithms and Abstract Data Types Summer 2009 Midterm Exam 1 Solutions
1. (20 Points) Prove that ( f (n) ( g (n) = ( f (n) g (n) . In other words, if h1 (n) = ( f (n) and h2 (n) = ( g (n) , then h1 (n) h2 (n) = ( f (n) g (n) . Proof: Assume h1 (
CMPS 101
Midterm 1
Review Problems
1. Let f (n) and g (n) be asymptotically non-negative functions which are defined on the positive integers. a. State the definition of f (n) = O ( g (n) . b. State the definition of f (n) = ( g (n)
2. State whether the f
CMPS 101 Algorithms and Abstract Data Types Introduction to Algorithm Analysis Summary of the Theory Side of this Course
Mathematical Preliminaries o Asymptotic growth rates of functions o Some common functions and their properties o Induction Proofs o R
CMPS 101 Algorithms and Abstract Data Types
Induction Proofs
Let P(n) be a propositional function, i.e. P is a function whose domain is (some subset of) the set of integers and whose codomain is the set cfw_True, False. Informally, this means P(n) is a se
CMPS 101 Algorithms and Abstract Data Types Graph Theory
Graphs A graph G consists of an ordered pair of sets G = (V , E ) where V , and E V ( 2) = cfw_2 - subsets of V , i.e. E consists of unordered pairs of elements of V. We call V = V (G ) the vertex
CMPS 101 Final Review Problems
1. Let T be a binary tree, and let n(T ) and h(T ) denote its number of nodes and height, respectively. Show that h(T ) lg( n(T ) . (Hint: this was proved in the solutions to hw6.)
2. Trace HeapSort on the following arrays a
CMPS 201 Algorithms and Abstract Data Types
Some Common Functions
We present several common functions and estimates which occur frequently in the analysis of algorithms. Floors and Ceilings Given x R , we denote by x and x the floor of x and the ceiling o
CMPS 101 Algorithms and Abstract Data Types
Asymptotic Growth of Functions
We introduce several types of asymptotic notation which are used to compare the relative performance and efficiency of algorithms. As we shall see, the asymptotic run time of an al
CMPS 101 Algorithms and Abstract Data Types
Some Additional Remarks on ADTs and Modules in ANSI C
Suppose you wish to implement an ADT in C. The particular ADT is unimportant, so lets just call it a Blah. You should create the following files at minimum: