Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CIS 2331 Homework 10
Note: These questions are just for your exercises. You dont need to submit your
solutions for grading.
Final exam: closedbook, opennotes
Date/Time: Wednesday Dec 12, 4:00pm5:45pm
Topics: DepthFirst Search, Minimum Spanning Trees,
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CIS 2331 Homework 9
Due: Friday, November 16 by class time
Note: use the definition of flow that includes the skewsymmetry condition.
1. The following figure shows a flow in a network. Construct the residual network.
(a)
(b)
(c)
(d)
Construct the residua
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 8
Due Friday, November 9 by class time
Autumn, 2012
1. Give the EDGES of the minimum spanning tree of the weighted graph in Figure 1 in the order they
would be output by Prims algorithm starting at vertex v1 .
?>=< 4 GFED 5 GFED 6 @ABC
8
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 7
Autumn, 2012
Due: Friday, November 3 by class time
1. Consider the following undirected graph:
?>=<
89:;
?>=<x
89:;
2b
1F x
FF xxxxx bbb
FF xxxx bb
xxxbbb
FF
xx
F
?>=<
89:;
?>=<
89:;
3
FFF
p4
ppp
FF
p
FF pp
ppppp
ppp F
?>=<p
89:;
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE2331 Homework 6
Due Wednesday, October 24, by class time
1. Let G = (V, E ) be an undirected graph. Modify the following algorithm
to determine if G is a tree. (A tree is a connected graph without cycles.)
Your modication must not increase the time com
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 5
Autumn, 2012
(Just for your practice; you dont need to submit anything)
Midterm II: Monday, October 8
Scope: Slides 51129, and notes on Divide and Conquer, Heapsort and Priority Queues, RedBlack Trees (up to insertion, inclusively)
1.
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 4 (part II)
Due: Wednesday, October 3rd by class time
Midterm Exam II: Monday, October 8.
Scopes: materials after the quiz to part of redblack trees.
1. (a) Draw the binary tree produced by inserting the following elements in a maxheap
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE2331 Homework 4
Due: Friday, September 28 by class time
(A headsup: HW5 will be due on Wednesday, October 3)
Midterm: Monday, October 8.
1. In the CovexHull algorithm, we assumed that no two points have the
same x or y coordinate. Now, suppose there
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 3
Due: Friday, September 21 by class time
Note: there are 10 problems. Write a recurrence relation describing the worst case
running time of each of the following algorithms and determine the asymptotic complexity of
the function dened b
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE 2331 Homework 2
Autumn, 2012
Due: Friday, September 7, by class time
Note: there are six questions.
1. Give the asymptotic running time of the following function in notation.
Justify your answer. (Show your work.)
1
2
3
4
5
6
7
8
9
Func1(n)
s 0;
i 1;
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
CSE2331 Homework 1
Autumn, 2012
Due: Wednesday, September 5, by class time
Give upper and lower bounds on the running time of each of the following
algorithms. Your upper and lower bounds should dier by only a constant
factor. (That is, express your answe
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Dynamic Programming
Reading: CLRS Chapter 15 & Section 25.2
CSE 2331 Algorithms
Steve Lai
Optimization Problems
Problems that can be solved by dynamic programming
are typically optimization problems.
Optimization problems: Construct a set or a sequence
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Sorting in Linear Time
CSE 2331
Suggested Reading: Sections 8.1, 8.2, 8.3
1
Lower Bounds for Sorting
Insertionsort, mergesort, heapsort, quicksort are all based on comparison. We sort by comparing elements in the array, and a sorting algorithms time com
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Maximum Flow
Reading: CLRS Sections 26.126.3
(skipping Lemma 26.8, Theorem 26.9 (2nd edtion)
or Lemma 26.7, Theorem 26.8 (3rd edition)
CSE 2331
Steve Lai
Flow Network
A flow network G = (V , E ) is a directed graph with
a source node s V ,
a sink node
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Minimum Spanning Trees
CSE 2331
Suggested Reading: Chapter 23.
1
Greedy Method
Optimization Problem:
Construct a sequence or a set of elements cfw_x1 , . . . , xk that satises some
given constraints and optimizes a given objective function.
The Greedy Me
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Heapsort and Priority Queues
CSE 680
Suggested reading: Chapter 6
1
Heaps
Complete binary tree: a binary tree with exactly 2h leaves, where
h is the height of the tree.
Nearly complete binary tree: a binary tree obtained from a complete binary tree by d
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
DivideandConquer
CSE 680
1
Introduction
Given an instance x of a problem, the divideandconquer method works as follows.
function DAQ(x)
if x is sufciently small or simple then
solve it directly
else
divide x into smaller subinstances x1 , . . . , xk ;
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
What is this functions time
complexity?
Sample for loops
Sample for loops
Sample for loops
Sample for loops
Sample for loops
Sample while loops
Sample while loops
Sample while loops
Sample while loops
Sample while loops
Sample while loops
Sample while loo
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Examples
For each of the following functions fi (n), express its asymptotic
complexity in a simplest form such as (1), (log2 n), (log2 log2 n),
(n), (n log n), (nk ), (2n ), etc.
1. f (n) = 45n+9 = (
2. f (n) = log3 (2n4 + 6n3 ) +
3. f (n) =
4. f (n) =
);
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
Mathematical Foundation
CSE 680
Suggested Reading: Sections 1.1, 1.2, 2.1, 2.2, 3.1, 3.2.
1
Running Time
Analysis of algorithm: to estimate the running time of an algorithm.
Elementary operations:
arithmetic and boolean operations: +, , , /, mod, div,
Introduction to Analysis of Algorithms and Data Structures
PHYSICS 2331

Fall 2013
RedBlack Trees
Source: wikipedia.org
RedBlack Tree Properties
(Definition of RB Trees)
A redblack tree is a BST with following properties:
1. Every node is either red or black.
2. The root is black.
3. Every leaf is NIL and black.
4. Both children of e