li i D
Abd ll II
Depth First Search
G = (V, E) (No source vertex given!)
Explore the edges of G to discover every vertex in V starting
at the most current visited node
Search may be repeated from multiple sources
Minimum Spanning Tree
Minimum Spanning Trees
A connected, undirected graph:
Vertices = houses, Edges = roads
A weight w(u, v) on each edge (u, v) E
Find T E such that:
1. T connects all vertices
2. w(T) = (u,v)T w(u, v) is
Longest Common Subsequence
Denitions: Given a sequence/string X = ABCBDAB.
A subsequence is obtained by simply leaving out some letters from the sequence.
is a common subsequence of
Given two sequences
is a subsequence
Chapter 12: Binary Search Trees
A binary search tree is a binary tree with a
special property called the BST-property,
which is given as follows:
For all nodes x and y, if y belongs to the
left subtree of x, then the key at y is less
than the key at x, an
Chapter 13: Red-Black Trees
A red-black tree is a node-colored BST.
Each node is colored either black or red. The
following special rules apply:
1. The root is always black.
2. A nil is considered to be black. This
means that every non-NIL node has two
Binary Search Trees (BST)
Operations: All are
on average and
in the worst case.
left & right (child) ptrs.
Idea: like sorting a hand of playing cards
Start with an empty left hand and the cards facing
down on the table
Remove one card at a time from the table, and insert
it into the correct position in the left hand
High Level View of Quicksort
such that the left subarray
1. PARTITION step: Rearrange array
into two nonempty (why?) subarrays
2. RECURSIVE step: Sort the two subarrays recursively.
% ! !
4 Heaps and Heapsort
Complete binary tree (i.e., nodes are added to the binary tree one level at a time. Within a
level, nodes are added from left to right).
Value of each node
values in each of its children.
Similar to dynamic programming, but simpler approach
Also used for optimization problems
Idea: When we have a choice to make, make the one
that looks best right now
Make a locally optimal choice in the hope of getting a gl
# 0 1 ! 3#
d b b ! b3 )b #F 1 !b6
[email protected]#$1D!9&431q &@&(6P(#wEGS
3 F d ! )
f &[email protected]
d b b
y sr sr h
f ) 6 b f
"0 @# &c')$!e
'f $)@7#1(&'9 E
!3 ) nf
f3 ! f
q r p y sr q h
Make the choice that looks the best at the moment (i.e., the locally optimal choice). Then,
hope & pray (prove) that this results in a globally optimal solution.
Sometimes this works, sometimes it doesnt!
Greedy v/s DP
1. In DP, a cho
An algorithm design technique for optimization
problems (similar to divide and conquer)
Divide and conquer
Partition the problem into independent subproblems
Solve the subproblems recursively
Combine the solutions to so
Red black trees
A BST that guarantees that
Denition: A BST is a red-black tree if it satises the following properties.
Every node is either red or black.
Every leaf (external node) is black.
If a node is red, then both of its child
A problem-solving technique (like Divide & Conquer).
In D & C, break problem into independent subproblems and solve the subproblems recursively.
In DP, the sub-problems are not independent.
DP is used for optimization problems; i.e.
Prince Huseen Ibn Abdullah II Faculty for
Department of Software Engineering
First Semester 2011-2012
Course Title: Graphical User Interface (GUI)