2/27/2015
AlgorithmCourse
Fall2014
Lecture1
Coursedetails
Thiscourseisdesignedforthirdyearundergraduatestudentsat
ComputerScienceandapplicationDepartmentinPrinceAbdallaII
C
S i
d
li i D
i Pi
Abd ll II
forInformationTechnologyattheHashemiteUniversity.
Cour

Depth First Search
Depth-First Search
1
2
Input:
3
G = (V, E) (No source vertex given!)
5
4
Goal:
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
Output:
2

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
minimized
8
b
4
7
d
9
2
11
a
c

13
Longest Common Subsequence
Denitions: Given a sequence/string X = ABCBDAB.
A subsequence is obtained by simply leaving out some letters from the sequence.
Example
.
and
both
&
,
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
ch

Binary Search Trees (BST)
Preliminaries
Operations: All are
10.1
on average and
10
in the worst case.
Search.
Insert/Delete.
Minimum/Maximum.
Predecessor/ Successor.
Representation:
Use pointers.
Node contains
left & right (child) ptrs.
key eld.
pa

3/28/2015
Algorithm
Insertion Sort
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
compa

5 Quicksort
High Level View of Quicksort
such that the left subarray
1. PARTITION step: Rearrange array
into two nonempty (why?) subarrays
right subarray.
2. RECURSIVE step: Sort the two subarrays recursively.
Algorithm
'
)(
if (
% ! !
&$#"
QUICKSO

4 Heaps and Heapsort
4.1
Preliminaries
Denition: Maxheap
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.
Example: (

Algorithms
Greedy Algorithms
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

W&$6D!24&$6(ek!P5
# 0 1 ! 3#
$('&@PP20%$#7B&t&(@PIte
d b b ! b3 )b #F 1 !b6
f@4#$1D!9&431q &@&(6P(#wEGS
3 F d ! )
f &P8P@GS
d b b
y sr sr h
xq&Gr&W5 gcg
f ) 6 b f
"0 @# &c')$!e
'f $)@7#1(&'9 E
!3 ) nf
f3 ! f
P7#$1E$4!(1!&e @
q r p y sr q h
5t x

14
Greedy Algorithms
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

Algorithms
Dynamic Programming
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
11.1
Preliminaries
A BST that guarantees that
11
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

12
Dynamic Programming
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.

Hashemite University
Prince Huseen Ibn Abdullah II Faculty for
Information Technology
Department of Software Engineering
Final Exam
:
First Semester 2011-2012
:
Course Title: Graphical User Interface (GUI)
Course Number:1003412
:
Instructor Nam