Review - KSU Web Home

Review for Test 1 (Chapter 1 - 4)
Chapter 1: Introduction
1. What is an algorithm?
2. Algorithms can be specified in a natural language or pseudocode; they can also be
implemented as computer programs.
3. Algorithm efficiency
Exercises:
1) Design an algorithm to find all the common elements in two sorted lists of numbers. For
example, for the lists 2, 5, 5, 5 and 2, 2, 3, 5, 5, 7, the output should be 2, 5, 5. What is
the maximum number of comparisons your algorithm makes if the lengths of the two
given lists are m and n, respectively?
2) Consider the following algorithm for finding the distance between the two closest
element in an array of numbers.
Improve the efficiency of the algorithm.
Chapter 2: Algorithm efficiency analysis
1.
2.
3.
4.
5.
Analysis framework
Asymptotic notation
Non-recursive algorithm
Recursive algorithm
Solving recurrence relation
Exercises:
1) Order the following functions according to their order of growth (from the lowest to the
highest):
2) Consider the following algorithm:




What does this algorithm compute?
What is the basic operation?
How many times is the basic operation executed?
What is the efficiency of this algorithm?
3) Consider the following algorithm:





What does this algorithm compute?
What is the basic operation?
Set up and solve the recurrence relation for the number of times the algorithm’s basic
operation is executed?
What is the efficiency of this algorithm?
How does this algorithm compare with the straightforward non-recursive algorithm?
Chapter 3: Brute force and exhaustive search
1. Selection sort
2. Bubble sort
3. Sequential search
4. String matching
5. Traveling salesman problem
6. Knapsack problem
7. Assignment problem
8. Depth-first search
9. Breath-first search
10. Edge types
Exercises:
1) Consider the following graph


Starting at vertex a and resolving ties by the vertex alphabetical order, traverse the graph
by depth-first search and construct the corresponding depth-first search tree.
Starting at vertex a and resolving ties by the vertex alphabetical order, traverse the graph
by breath-first search and construct the corresponding breath-first search tree.
Chapter 4: Decrease-and-Conquer
1. Decrease-by-one
o Insertion sort
o Topological sorting
o Generate permutations
o Generate subsets
2. Decrease-by-constant factor
o Binary search
o Fake coin
o Russian peasant multiplication
3. Decrease-by-variable size
o Selection problem
o Partition problem
o Interpolation search
o Searching and insertion in a BST
o The game of Nim
Exercises:
1) Apply the DFS-based algorithm to solve the topological sorting problem for the
following graph.
2) Apply the Russian peasant algorithm to computer 26 * 47. From the standpoint of time
efficiency, does it matter whether we multiply n by m or m by n by the Russian peasant
algorithm?
3) Apply quickselect to find the median of the list of numbers 9, 12, 5, 17, 20, 30, 8.