1. -Divide the n elements into groups of 5 (leaving at most 4 elements)
-sort each group of 5 and find the median of 5 elements for a total of [n/5] medians
2. Select the median of these [n/5] elements which will end up in position [n+5/10] .regardless
of

Need a good hash function
quick to compute
good dispersion of hash values
Basic operations: Insert, Member, Delete
Insert x in A
1. C<=h(x)
2. Insert x at the head of the list in A[c]
Member x in A
1. C<=h(x)
2. Search for x in bucket A[c]
Delete
1. C<=h(

1. -Divide the n elements into groups of 5 (leaving at most 4 elements)
-sort each group of 5 and find the median of 5 elements for a total of [n/5] medians
2. Select the median of these [n/5] elements which will end up in position [n+5/10] .regardless
of

Depth first search (dfs)
G a digraph
initially all vertices are marked unvisited
Select some vertex V and mark it visited
Select each vertex W adjacent to V and process it recursively using Dfs
dfs_aux
given G = (V,E)
For V=1.n do
mark [V]=unvisited
For V

Edsgar Dijkstra
The shortest path from a vertex in a digraph to all other vertices
Single source shortest path
Output: D[1.n] containing shortest distance from 1 to vtx i. (D=distance vector)
Given digraph G=(V,E) => V=cfw_1,2,.,n where 1 is the source
C

Generalized Radix Sorting
Input: Array/list of n records with key field (fk,fk-1,.,f1)
Output: Sorted list of those n records
Need bins Bi [a.mi+] for each step i
eg: step i=1; a.9 .t1=dec
step i=3; a.z etc t3=char
For i=k down to 1 by -1
1. for each v of

A[1.n] of keys ( a <= k <= n ) value
no duplication
no key missing
B[1.n]
for i from 1 to n by 1 do
while A[i].key!=i do
swap(A[i],A[A[i].key])
Binsort
Create m bins, where each bin holds all records with a certain key value. In the general case
m<n
Pr

Choice of Pivot so that Recursion Depth is O(lgn)
not O(n)
1. Pick leftmost or rightmost
2. Median of 3
3. Use insertion sort of <3?
Can we do better than O(nlgn)? yes.
Suppose we have A[1.n] of records each with a key field and keys are not duplicated an

QuickSort.
W.C. O(n2)
ArgC. O(nlgn)
const. is small
T(n) = cnlgn+.
QuickSort.
Input: a1,a2,.an in some array A[ ]
Output: the elements in sorted order
Method: Recursive Procedure
QuickSort(S)
1. if S contains at most 1 element then return S
else
2. choose

Building Heap:
Lemma:
If vertices i+1, i+2,.,n are the roots of heaps, then after a call to Heapify(i,n) the vertices i,
i+1,.n are roots of heaps
Once a heap is built, we may use it as a priority queue or a sorting mechanism the largest
element is at the

Lemma1:
A binary tree of height h has at most 2h leaves.
Lemma2:
A binary tree with n leaves has at least [log2n]
A tree that sorts n distinct elements has height at least log2n!
Heapsort
Heap property:
binary tree where
1. every leaf is at level d or d-1

Divide and Conquer:
Partition the problem into smaller pieces; find solutions to those pieces, combine those solutions
into one solution for the original.
Find the maximum and minimum elements of a set S
begin
max any element in S
for all other elements x

candidate solution - a particular solution that works i.e. feasible
feasible solution space FS(I) where I=solution
value function (V(x) that measures goodness i.e. a way to quantify a solution
the optimal solution is the solution x in the feasible solutio

Given G=(V,E) let Q be undirect hamiltonian cycle
show Q is NP complete
1. show Q is in NP
1. Guess a permutation of V
w1,w2,.wn where wi = vji
2. Check
that (w1,w2),(w2,w3),.,(wi,wi+1) where 1<=i<n is an edge and (wn,w1) is an edge
2. Pick a known NP com

input: a[0.N-1], sorted in descending order, key k
task: return position where k appeared in A or -1
strategy: find the middle elem in a[lo.hi] (lo=0 initially, Hi=N-1). If k= mid element return
position, otherwise if k<midterm search search A[lo.mid-1] o

Non deterministic
1. Guess a string S
2. Use S and encoding of Problem to check if the solution has been found. If so, return yes (else
go back to 1)
NP
Q
NP-Complete (http:/en.wikipedia.org/wiki/NP-complete)
other reading,
hamiltonian cycle (http:/en.wik

A nondeterministic time algorithm is polynomially bounded if there is a fixed polynomial p(x)
such that for every input of size n where the answer is yes the algorithm produces the answer in
no more than p(n) steps.
NP: the class of problems for each of w

Bin Packing
instance: Given an unlimited supply of bins each of capacity 1 and n objects of size s1,s2,.sn
where 0<=s1<=1 and an integer k.
q: is there some ordering of objects so that they all fit in k bins
satisfiability SAT
instance: a set of boolean v

Path Matrix P[i,j]
P[i,j] = k
mean k appears on the shortest path from vi to vj
or P[i,j] = 0
To recover the s. paths
print path (i,j,p)
1. k=P[i,j]
2. if k=0 return
3. print path (i,k,p)
4. print k
5. print (k,j,p)
if C[i,j] = infinity
else C[i,j]=0
else

Kruskal (similar to prim)
Formulation as decision problem
Instance: given an undirected graph G=(V,E)
Question: is there a clique of single? in G
Ans: y/n
pi: Gwen G: (V,E) and an int k
Q: is there a coloring of G using k or fewer colors
Class P of polyno

minimum spanning tree
no loops, every vertex is only connected by one path and every vertex is connected
prims algorithm for a mst g=(v,e)
spanning tree for g: [ie unique path between two vertices, no cycles]
a tree that connects all the vertices of g
cos