CSE 241 Class 23
Jeremy Buhler
April 22 2013
1
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
Jeremy Buhler
April 17 2013
1
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
Jeremy Buhler
April 15 2013
1
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.
Notice t
CSE 241 Class 20
Jeremy Buhler
April 10 2013
1
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 )
Som
CSE 241 Lecture 19
Jeremy Buhler
April 3 2013
1
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
Jeremy Buhler
April 1 2013
1
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)
Example:
may not be fully conn
CSE 241 Class 17
Jeremy Buhler
March 27 2013
And now for something completely dierent!
1
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
Jeremy Buhler
March 20 2013
Today: B-Trees Part Deux
1
B-Tree Search
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
Lo
CSE 241 Class 15
Jeremy Buhler
March 18 2013
Today: the dreaded balanced tree!
1
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
Jeremy Buhler
March 5 2013
Today: skip list analysis!
1
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
Jeremy Buhler
March 4 2013
Today: skip lists!
1
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
Jeremy Buhler
February 27 2013
Onwards to trees!
1
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?
c
CSE 241 Class 11
Jeremy Buhler
February 20 2013
Today: sorting in linear time!
1
Counting Sort
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
Input:
CSE 241 Class 10
Jeremy Buhler
February 18 2013
1
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)
Insertionsort: wors
CSE 241 Class 9
Jeremy Buhler
February 13 2013
Now for randomized QuickSort!
1
Fixing 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?
Choose s
CSE 241 Class 8
Jeremy Buhler
February 11 2013
Today: QuickSort!
1
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
array)
Partitio
CSE 241 Class 7
Jeremy Buhler
February 6 2013
Today: analysis of hashing
1
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
Jeremy Buhler
February 4 2013
Today: a new idea hashing!
1
Collections
Collection: a data structure that stores a bunch of objects (aka
records ).
each object has a key k that identies it (plus some other data maybe)
[draw picture]
The
CSE 241 Class 5
Jeremy Buhler
January 30 20131
Today (dah da-da daaaaaah): the Master Method!
1
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
Jeremy Buhler
January 28 2013
On tap for today: more recurrences, more recursion trees, one new algorithm
(binary search)
1
Recursion Trees: Two More Examples
Recursion trees are a general way to solve recurrences. I want
to make sure your
CSE 241 Class 3
Jeremy Buhler
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?
1
Denitions
Let f (n) and g (n) be two func
CSE 241 Class 2
Jeremy Buhler
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
Jeremy Buhler
January 14, 2013
Before class, write URL on board:
http:/classes.engineering.wustl.edu/cse241/.
Also: Jeremy Buhler, Oce: Bryan 509, 314-935-6132
1
Welcome and Introduction
Welcome to CSE 241: Algorithms and Data Structures!