Complete binary tree each node has exactly 2 children except bottom level
Heap: almost complete binary tree, bottom level filled from left to right on all
levels filled except possibly the bottom
Max heap: each node is the biggest value in is sub tree eac
Algorithms: Sorting
Amotz BarNoy
CUNY
Spring 2012
Amotz BarNoy (CUNY)
Algorithms: Sorting
Spring 2012
1 / 51
The Sorting Problem
Keys: Entities from a well ordered domain.
Comparison: For 2 keys K1 and K2
either K1 < K2
or K2 < K1
or K1 = K2 .
Input: An
NP completeness class p = set of decision problems for which we know a
polynomial time solution
Optimization of problem: doesnt have a yse ot no answer
Graph coloring > OP: what the minimum number of colors needed
DP : can I pack n items into k bins
Knap
Minimum spanning tree
Given weight, connected undirected, n nodes, n1 edges
A spanning tree of a graph G(V,E) is a sub graph of G that contains all vertices in a V
and its connected and acyclic a minimum spanning tree is a spanning tree with minimum
sum
Connected components outputting connected components ( undirected graph)
Counts the # of components add a cc_coun int and then add one trough loop of
commented components and print when you visit
Topological sorting( directed graph)
Acyclic graph DAG cant
Graph representation
Adjacency Matrix  2d array (n*n ) (0= no edge, 1= edge_
1
2
3
4
5
7
n
1
0
2
1
0
3
0
1
4
0
1
5
0
0
6
0
1
7
0
0
n
Can answer if there is an edge
if have a directed graph must fill in the whole matrix in an undirected graph
dont need t
Properties of a Decision tree: must contain n elements, path from root to any node
that represents the work done on a given input
Best case input: root
Worst case input: longest input
Proving a lower bound an height of a binary tree with n elements
 Prov
Section 1.5
Allowed to ignore anything that is not a constant ( multiple or additive)
Inside of an exponent is NOT! A constant
2n and 2n+1 there it is a constant
You are allowed to ignore constants because it doesnt affect the rate of growth
when looking
Complete graph of 1 node  Complete graph of 2 nodes  Complete graph of 3
nodes
Complete graph of 4 nodes  Complete graph of 5 nodes
Path: traveling in a graph from on node to another node, taking to the node you
want to go
Path: path from a vertex v to
Graphs
Graphs are made up of nodes and edges
Examples:


networks every network can be expressed as a graph , computers = nodes
and wires would = edges
Airline Flights  nodes = cities, edges = direct flights
Processes with dependencies
p2 cannot happen
Analysis of Algorithms: finding the best way to use time and space
Algorithm a sequence of instructions or steps to solve a specific
problem
Input > Algorithm > output
Which way is better? Is there a better way?
Better = less time, less space
1) Provi