Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 12
Midterm Exam
Wednesday, March 12 in classroom
75 minutes
Exam structure:
short questions on the topics discussed in class
TRUE/FALSE questions
homework-like problems
All topics disc
CS 477/677 Analysis of Algorithms
Homework 1
Due September 8, 2015
1. (U & G-required) [30 points] Arrange the following list of functions in ascending
order of growth rate. That is, if function g(n) immediately follows function f(n) in your
list, then f(
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 3
Recurrent Algorithms
BINARY SEARCH
for an ordered array A, finds if x is in the array A[lohi]
Alg.: BINARY-SEARCH (A, lo, hi, x)
1
2
3
4
5
if (lo > hi)
2 3 5 7
return FALSE
mid (lo+h
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 6
Merge Sort Approach
To sort an array A[p.r]:
Divide
Divide the n-element sequence to be sorted into two
subsequences of n/2 elements each
Conquer
Sort the subsequences recursively us
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 2
Algorithm Analysis
The amount of resources used by the algorithm
Running time:
Space
Computational time
The number of primitive operations (steps) executed
before termination
Order o
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 5
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
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 11
Interval Trees
Useful for representing a set of intervals
E.g.: time intervals of various events
Each interval ihas a low[i] and a high[i]
CS 477/677 - Lecture 11
2
Interval Trees
D
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 14
Dynamic Programming
Used for optimization problems
Find a solution with the optimal value (minimum or
maximum)
A set of choices must be made to get an optimal
solution
There may be
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 8
General Selection Problem
Select the i-th order statistic (i-th smallest element) form
a set of n distinct numbers
p
k=qp+1
r
A
i < k search
in this partition
q
i > k search
in this
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 9
Array Representation of Heaps
A heap can be stored as an
array A.
Right child of A[i]=A[2i+1]
Parent of A[i]=A[i/2]
Left child of A[i]=A[2i]
Root of tree is A[1]
Heapsize[A] length[A
Analysis of Algorithms
CS 477/677
Instructor: Monica
Nicolescu
Lecture 10
Red-Black Trees
Balanced binary trees guarantee an O(lgn)
running time on the basic dynamic-set
operations
Red-black tree
Binary tree with an additional attribute for its nodes:
col
CS 477/677 Analysis of Algorithms
Homework 2
Due September 15, 2015
1. (U & G-required) [30 points] Consider the following algorithm.
ALGORITHM Enigma(A[0.n 1])
/Input: An array A[0.n 1, 0.n 1] of integer numbers
for i 0 to n 2 do
for j i +1 to n 1 do
if