CSE 241 Class 23
April 22 2013
An Amusing Graph Problem
You are catering a meeting with boxed lunches for four people
Youve made up boxes 1, 2, 3, 4 with various food items
Alice is vegetarian; Bob is vegan; Carol has a wheat allergy; D
CSE 241 Lecture 22
April 17 2013
Why Depth-First Search?
Previously, we saw BFS, which measured distance of each vertex from some
starting point. The opposite of BFS is DFS.
DFS visits every node in G
Purpose is to mark each vertex in G
CSE 241 Class 21
April 15 2013
A New Problem MST
For this class, let G be an undirected weighted graph.
Defn: a spanning tree on G is a subset of Gs edges that (1) forms a
tree (i.e. no cycles) and (2) touches every vertex of G.
CSE 241 Class 20
April 10 2013
Weighted Version of Shortest Paths
BFS solves unweighted shortest path problem
Every edge traversed adds one to path length
What if edges have nonuniform weights? Let w(u, v ) be weight of edge
(u, v )
CSE 241 Lecture 19
April 3 2013
Breadth-First Search: Motivation
Idea: From a start vertex s, try to reach any vertex of an unweighted graph
by a path traversing the fewest possible edges.
Example: airline travel planning
Starting from h
CSE 241 Class 18
April 1 2013
Graphs: a Spiy Abstraction
If you havent seen graphs in 240, youre in for a treat! Start with denitions.
A graph is a collection of nodes (vertices) connected by links (edges)
may not be fully conn
CSE 241 Class 17
March 27 2013
And now for something completely dierent!
A New Abstract Data Type
So far, weve described ordered and unordered collections.
Unordered collections didnt support ecient min or max
Ordered collections support
CSE 241 Class 16
March 20 2013
Today: B-Trees Part Deux
Finding a key in a B-tree is easy
Start at root
If current node contains desired key, return it.
Otherwise, determine which subtree would have key and recur on it
CSE 241 Class 15
March 18 2013
Today: the dreaded balanced tree!
Why Balanced Trees?
We just did skiplists specically to avoid balanced trees. Why am I subjecting you to this?
Sometimes, you need worst-case O(log n)
Youll encounter these
CSE 241 Class 14
March 5 2013
Today: skip list analysis!
Things to Show
Let H be the height of the tallest pillar in a skip list of size n.
Want to show that H is almost certainly O(log n).
Implies that likely cost of delete is O(log n)
CSE 241 Lecture 13
March 4 2013
Today: skip lists!
Why Skip Lists?
At this point, we traditionally talk about balanced binary trees
(e.g. red-black trees, AVL trees)
Idea : dynamically rebalance tree to keep height (log n) at all times
CSE 241 Class 12
February 27 2013
Onwards to trees!
Collection Types Revisited
A while back, we introduced the idea of collections.
abstract data types
support insert, remove, nd
examples: list, array, hash table
Where did we end up?
CSE 241 Class 11
February 20 2013
Today: sorting in linear time!
Counting sort is a correct (n) sort.
How is this possible?
Must not t the comparison sort model
Indeed, never actually compares two elements of array
CSE 241 Class 10
February 18 2013
Computational Model of Sorting
The world is full of sorting algorithms.
Quicksort: worst-case (n2 ), average (n log n)
Mergesort: worst-case (n log n)
Heapsort: worst-case (n log n)
CSE 241 Class 9
February 13 2013
Now for randomized QuickSort!
worst-case complexity is bad (n2 )
worst case may be common (array already sorted!)
yet it has benets (simple, in-place)
What could we do to x it?
CSE 241 Class 8
February 11 2013
Partitioning an Array
Partitioning is the basis of algorithms for
sorting (famous QuickSort algorithm)
order statistics (for example, nd the third largest element in this
CSE 241 Class 7
February 6 2013
Today: analysis of hashing
Constraints of Double Hashing
How does using OA w/double hashing constrain our hash function design?
Need to avoid bad behavior of slot sequences. For example, suppose
m = 6, but
CSE 241 Class 6
February 4 2013
Today: a new idea hashing!
Collection: a data structure that stores a bunch of objects (aka
each object has a key k that identies it (plus some other data maybe)
CSE 241 Class 5
January 30 20131
Today (dah da-da daaaaaah): the Master Method!
Recursion Trees Suck
Were all pretty tired of recursion trees.
Many recursions can be solved by same basic process.
Can we do one recursion tree analysis th
CSE 241 Class 4
January 28 2013
On tap for today: more recurrences, more recursion trees, one new algorithm
Recursion Trees: Two More Examples
Recursion trees are a general way to solve recurrences. I want
to make sure your
CSE 241 Class 3
January 23 2013
Time to stop playing fast and loose with asymptotic notation.
Previously, we said that (f (n) means roughly a constant times f (n).
How can we formalize this notion?
Let f (n) and g (n) be two func
CSE 241 Class 2
January 16 2013
The following three sections introduce the divide-and-conquer algorithm
for closest pair. Why? I want to show you an interesting, nontrivial algorithm and how we analyze it.
We compute distance only. Of course
CSE 241 Class 1
January 14, 2013
Before class, write URL on board:
Also: Jeremy Buhler, Oce: Bryan 509, 314-935-6132
Welcome and Introduction
Welcome to CSE 241: Algorithms and Data Structures!