Solution of Assignment 2
Csc 220 C
March 27, 2012
1
1.1
2
Assignment 2
Chapter 22, 23, 24, 25, 26
Chapter 22
1. 22-1. pp 621
A depth-rst forest classiers the edges of a graph into tree, back, forward, and cross edges. A breadthfrist tree can also be used
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 19
Binary Search Tree
Search trees are data structures that
support many dynamic-set operations
SEARCH, MINIMUM, MAXIMUM, PREDESCESSOR, SUCCESSOR,
INSERT and DELETE
Can be used as both a dictio
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 11
Greedy Methods
Similar to dynamic programming
Used for optimization problems
The idea is to choose the choice that
looks the best RIGHT NOW.
Make a locally optimal choice in hope
of getting
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 2
Algorithm Complexity
The complexity of a problem equals the
worst case running time of the best
algorithm to solve that problem.
Algorithm Complexity
Running time of an algorithm generally
inc
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 6
The Hiring Problem
You need to hire a person via an
employment agency.
Each day, a new candidate arrived.
You have to make a decision
immediately to hire this person or
not. If you do, you fi
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 9
Order Statistics
The i-th order statistic in a set of n
elements is the i-th smallest element
The minimum is thus the 1-st order
statistic
The maximum is the n-th order
statistic
The median
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Bio
Office
Email
Office Hour
NAC 8/209
[email protected]
TuTh 3:15pm to 4:45pm
in NAC 7/118 or NAC 7/107
or NAC 7/105
CSc 22000 Algorithm
Prerequisites: CSc 21200 and [CSc 21700 or EE 31100]
T
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 12
HW1
Rand() only goes up to 2^15
All the keys should not be in the
search arrays
Each trial should have different keys
Same trial, for the different arrays,
should used the same keys
Size s
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 8
Chapter 6.1-1
What are the minimum and maximum
numbers of elements in a heap of height
h?
Height of a tree number of edges on
the longest simple downward path from
node to a leaf
Chapter 6.11
Wh
This report presents the results of a
channel advertisement picker using a
self-implemented greedy method.
Greedy
Algorithm
Ayushya Amitabh
CSC 22000 ALGORITHMS
PROF. CHI HIM TIMMY LIU
Table of Contents
THEORY.2
IN THIS REPORT.2
AFTER READING DATA.2
Varia
This report presents the Big-O comparison
of different search algorithms. This report
compares and analyzes the results of a BigO study focusing on Sequential Search
(various kinds) and Binary Search.
BIG-O NOTATION
HOMEWORK # 1
Ayushya Amitabh
CSC 22000
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 14
Shortest Paths
Given a weighted, directed graph G = (V, E) with
weight function
p = (v0, v1, , vk)
= =1 (1 , )
Shortest path weight (u, v)
, = mincfw_ :
Shortest path from u to v (p)
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 13
Directed Acyclic Graph
(DAG)
A directed graph with no cycles.
Good for modeling processes and
structures with a partial order
a > b and b > c implies that a > c
But we may have a and b such
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 7
Practice
http:/a.co/iPVySaP
Practice
https:/www.coderbyte.com/
https:/www.hackerrank.com/
Test
Test-driven development (TDD)
Comparison Sorts
Sort
Best
Worst
Average
Selection Sort O(n2)
O(n
Chapter 1 to 9 Review
Csc 220 C
February 28, 2012
1
1.1
Chapter 1, 2
Insertion sort
1. The algorithm
IN SERT ION SORT (A, n)
A is an array and n is the size of A
for j 2 to n
do key A[ j]
ij1
while i > 0 & A[i] > key
do A[i + 1] A[i]
ii1
A[i + 1] = key
Chapter 22 to 26 Review
Csc 220 C
March 26, 2012
1
Chapter 22
Elementary graph algorithms
1.1
Graph Representation
1. Adjacency lists
Array Adj of |V | lists, one per vertex
Vertex u s list has all vertices u, s.t. (u, v) E or cfw_u, vinE
Space:
(V + E
Solution of Assignment 1
Csc 220 C
February 28, 2012
1
1.1
Assignment 1
Chapter 1, 2
1. 1-1, pp 15
1 second
1 minute
1 106 = lg n
6
7
n = 2110
2610
12
n
n = 1 10
3.6 1015
6
n
n = 1 10
6 107
4
n lg n
6.3 10
2.8 106
2
3
n
n = 10
7746
n3
n = 102
391
2n
n = l
Solution of Assignment 3
Csc 220 C
May 11, 2012
1
Assignment 3
1.1
Chapter 15
15.1-5, pp 370. The Fibonacci numbers are dened by 1. Give an O(n) time dynamic programming
algorithm to compute the nth Fibonacci number. Draw the subproblem graph. How many v
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 17
Fractional Knapsack
Problem
Max unit 25
Want to minimize the weight
Unit
Weight
12
18
6
15
17
28
32
50
23
47
Fractional Knapsack
Problem
Max unit 25
Want to minimize
the weight
Unit
Weight
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 15
Flow Networks
A directed graph G = (V, E), such that
if (u, v) E, then (v, u) E
A capacity c that maps ordered pairs
of vertices into nonnegative real
numbers, with c(u, v) = 0 if (u, v)
E
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 16
Polynomials
Straightforward method of adding two
polynomials of degree n takes (n)
Straightforward method of multiplying
two polynomials of degree n takes
(n2)
Polynomials and the FFT
Fast F
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 5
C1S1Q1
Give a real-world example that requires:
sorting.
computing a convex hull.
Convex hull Smallest convex set of containing the
point(s)
C1S1Q2
Other than speed, what other measures of
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 18
Hash Table
Many applications require a dynamic
set that supports only the dictionary
operations (INSERT, SEARCH, and
DELETE), such as a set is called a
dictionary
A hash table is effective fo
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 3
Sequential Search
Search(list, key)
while(i < n) / n comparison
if (list[i] = key) / n comparisons
return true
else i = i+1 / n assignment
return false
Sequential Search
Best Case: O(1)
Worst Ca
CSc 22000
Algorithm
Chi Him Timmy Liu
Spring 2017
Lecture 10
Dynamic Programming
A technique to solve big problems,
similar to divide-and-conquer.
The word programming is historical
and predates computer programming
Use when problem breaks down into
r
This report presents the comparison of
different sorting algorithms. This report
compares and analyzes the results of a
focusing on Insertion, Merge, Quick,
and Heap Sort.
Sorting Algorithms
HOMEWORK # 2
Ayushya Amitabh
CSC 22000 ALGORITHMS
PROF. CHI HIM