Mid-Term STUDY GUIDE
Chapter 1
Multiple Choice Questions:
1) A Java program is best classified as
a) hardware
b) software
c) storage
d) processor
e) input
Answer: b. Explanation: Programs are classifi
Lecture 2, CSCI 3110
Analysis of Insertion Sort
To analyze algorithms in RAM, we first need understand that the running time of an algorithm is
expressed as a function of its input size. This is becau
Lecture 4, CSCI 3110
Solution 2
To improve the running time, we observe that in the previous solution, we perform a lot of recomputation
in the innermost loop. For the example given before, to compute
Lecture 17, CSCI 3110
So far we have shown that the above randomized algorithm uses O(n) expected time, which is efficient.
There are however some issues with this solution. First, this solution is no
Lecture 10, CSCI 3110
To design a better solution, we use divide and conquer.
DIVIDE: We split P into two subsets PL and PR of approximately equal size. That is, |PL| = |P|/2, and |
PR| = |P|/2. This
Lecture 9, CSCI 3110
Some experimental studies showed that Karatsuba's algorithm outperforms the pencil-and-paper
algorithm when n exceeds a certain threshold between 320 and 640. Thus it is good for
Lecture 1, CSCI 3110
Today I first handed out a course information sheet, and gave an introduction to this course.
RAM, Algorithm Analysis and Order Notation
At the beginning of this course, let us le
Lecture 5, CSCI 3110
Solution 2: Sort the n numbers, and then we walk through the sorted array, comparing each element with
the one immediately to its right. If we find any element that is equal to th
CSCI 3110 Algorithms I
Summer 2016, Dalhousie University
Course website: http:/web.cs.dal.ca/~mhe/csci3110/
Students are responsible for checking announcements posted on the course web page for
assign
Lecture 15, CSCI 3110
Making Change
In this problem, we are given an amount in cents. We are to make change using a system of
denominations, using the smallest number of coins possible to make change.
Lecture 14, CSCI 3110
Our previous algorithm computes the optimal cost of multiplying the given matrix chain. How do we
multiply the matrices optimally? This can be done using recursion.
Say, we wish
Lecture 16, CSCI 3110
Finck analyzed this algorithm in 1841. He proved the following theorem: Euclid's algorithm uses O(lg v)
steps on input (u, v), where u > v > 0.
Proof. Consider replacing (u, v) b
Lecture 8, CSCI 3110
Divide-and-Conquer
This is the 3rd algorithm design paradigm. We learned divide-and-conquer in previous courses, and we
will learn more about it in this course. The general steps
Lecture 3, CSCI 3110
Following this definition, we can determine that n, n2, 3n2 + 4n + 5 are all O(n2), while n3 is not.
When we say that the running time of insertion sort is O(n2), we mean that the
Lecture 19, CSCI 3110
We also claim that the resulting graph must be connected, for if it weren't, when we considered the edge
that connected two components, we would have added it, but we didn't.
Now
Lecture 11, CSCI 3110
Supporting Subrange Sum Under Updates
Now let's invent a data structure to solve the following problem: We would like to maintain an array
A[1.n] to support
Query a: Set A[i] A[i
Lecture 6, CSCI 3110
Jarvis's March (Gift Wrapping): A better algorithm of computing convex hull is Jarvis' march. It is also
called gift wrapping as its computational process is similar to the proces
Lecture 7, CSCI 3110
Recursion
Recursion is the second algorithm design paradigm that we discuss in this course. We all learned how to
do recursion in an introductory programming course, but now let's
Lecture 13, CSCI 3110
Dynamic Programming
Dynamic programming was popularized by Richard Bellman, who started to describe it in 1940s. It
typically applies to optimization problems. It typically reduc
Lecture 12, CSCI 3110
Pseudocode of the greedy algorithm:
Activity_Selection(s, f, n)
sort both s and f by f[i] in increasing order
A cfw_1
k 1
for i 2 to n do
if s[i] >= f[k] then
A A cfw_i
k i
retur
ure 18, CSCI 3110
Graph Algorithms
In previous lectures, we learned 8 algorithm design paradigms, which gives us a rich toolset for problem
solving. Now we use some of these paradigms to solve problem