Minimum Spanning Trees
A town has a set of houses and a set of
A road connects 2 and only 2 houses.
A road connecting houses u and v has a
repair cost w(u, v).
Goal: Repair enough (and no more) roads
Elementary Graph Algorithms
Given graph G = (V, E). In pseudocode,
represent vertex set by G.V and edge set
G may be either directed or undirected.
Two common ways to represent graphs for
Similar to dynamic programming.
Used for optimization problems.
When we have a choice to make, make the
one that looks best right now. Make a locally
optimal choice in hope of getting a globally
Not a specific algorithm, but a technique
Developed back in the day when
programming meant tabular method
(like linear programming).
Doesnt really refer to computer
A variation of binary search trees.
Balanced: height is O(lg n), where n is the
number of nodes.
Operations will take O(lg n) time in the
A red-black tree is a binary search t
Binary Search Trees
Data structures that support many
Can be used as both a dictionary and as a
Basic operations take time proportional to the
height of the tree.
For complete binary
Many applications require a dynamic set
that supports only the dictionary
operations INSERT, SEARCH, and
DELETE. Example: a symbol table in a
A hash table is effective for implementing
Worst-case running time: (n2).
Expected running time: (n lg n).
Constants hidden in (n lg n) are small.
Sorts in place.
Quicksort is based on the three-step
process of divide-and-conquer.
To sort the subar
Sorts in placelike insertion sort.
O(n lg n) worst caselike merge sort.
Combines the best of both algorithms.
To understand heapsort, well cover heaps
and heap operations, and then well take a
look at priorit
Use a recurrence to characterize the
running time of a divide-and-conquer
Solving the recurrence gives us the
asymptotic running time.
A recurrence is a function is
Growth of Functions
CIS 606 Spring 2010
O(g(n) = cfw_ f(n): there exist positive constants
c and n0 such that 0 f(n) c g(n) for all n
g(n) is an asymptotic upper bound for
If f(n) O(g(n), we wr
CIS 606 Spring 2010
The sorting problem
Input: A sequence of n numbers ? a1,
a2, , an ? .
Output: A permutation (reordering) ? a1,
a2, , an ? of the input sequence such
that a1 a2 an.
The sequences are typically stored in
We also refe