Garrett's Journal

My journal entries for the “Algorithm Design” textbook by Jon Kleinberg and Éva Tardos.

"Algorithm Design" Journal Entries

Week 8

Chapter Scores

  • Readability Score: 4 / 10
  • Interest Score: 7 / 10

Readings

Chapter 5: Divide and Conquer
5.3: Counting Inversions
5.4: Finding the Closest Pair of Points

Problem: Given n points on an X,Y coordinate plane, find the two points that are the smallest distance away from each other than to any other two points.

The initial solution to this problem is obvious:

This algorithm, however, is inefficient because it is . An optimization can be found with a divide and conquer algorithm in which we divide the plane in half and recursively find the closest pair of points. In this algorithm, a problem with boundary cases of points near the dividing line quickly arises but is squelched when we realize that points beyond a distance of half of the smallest distance so far don't have to be examined.

5.5: Integer Multiplication

Problem: Given an n-digit number A and an n-digit number B, find the product A x B.

The initial solution to this problem is obvious:

Naturally, this algorithm is inefficient because its nested for loop makes it . By using a divide and conquer algorithm, we can divide up the problem and remove unnecessary operations to discover an algorithm that is .

2012/03/13 23:44 · garrettheath4 · 0 Comments

Week 7

Chapter Scores

  • Readability Score: 7/10
  • Interest Score: 4/101)

Readings

Chapter 5: Divide and Conquer
5.1: A First Recurrence - The Mergesort Algorithm

This section of the reading describes mergesort as the most canonical divide-and-conquer algorithm. A divide-and-conquer algorithm is an algorithm that divides the input into multiple pieces (usually 2), solves each subproblem using recursion, and then combines the results of those recursive calls into a solution. As with all recursion, the recursive calls in a divide-and-conquer algorithm need to have a base case so that the algorithm has a point at which it stops dividing and starts conquering. Usually this “bottom out” point is when the recursive method is called on an input of some predefined constant size, such as 1.

Divide-and-conquer algorithms are a little less straightforward in computing an algorithm's time complexity, but their efficiency can be expressed as a recurrence relation. Mergesort can be measured by the number of comparisons based on the input size. This measurment can be expressed as a function that computes the number of comparisons (or “time”) based on the input size n:

T(n) ≤ 2T(n/2) + cn if n > 2
T(2) ≤ c if n = 2
5.2: Further Recurrence Relations

A generalized form of the recurrence relation equation mentioned above is:

T(n) ≤ qT(n/2) + cn if n > 2
T(2) ≤ c if n = 2

where q is the number of subproblems per step in the recursive algorithm. This gives us a few cases depending on what q is…

Case q > 2

Case q = 1

Quadratic Split and Reduce

5.3: Counting Inversions

A good way to quantify the differences between two comparable sets of data is to determine the degrees of difference between the two. A generalized way to do this is to calculate the number of inversions between the two. Assuming the data in question is organized like two lists of the same set of elements, an inversion is the minimum number of times that two elements need to trade places in the first list to become the second list. For example, if you have the following list:

24135

and you are comparing it to:

12345

you could quantify the differences between them by saying that it would take 3 inversions to get from the first list of data to the second list of data:

24135
14235
12435
12345

We can use the algorithm on Pages 224-225 to count inversions. This algorithm has a time complexity of: , meaning that that is the the time it would take to find the number of inversions and perform them.

2012/03/07 01:12 · garrettheath4 · 0 Comments

Discussion

Week 72023/02/05 16:59Garrett Koller0 Comments
Week 32023/01/27 15:29Garrett Koller0 Comments
Week 42023/01/27 03:55Garrett Koller0 Comments
Week 82023/01/26 17:32Garrett Koller0 Comments
Week 5-62023/01/26 15:42Garrett Koller0 Comments
Week 92023/01/15 19:47Garrett Koller0 Comments
Week 102023/01/15 19:47Garrett Koller0 Comments
Week 12023/01/15 19:47Garrett Koller0 Comments
Week 22023/01/13 17:26Garrett Koller0 Comments
1)
Everyone knows recursions and mergesort, so why are we beating it with yet another dead horse?
courses/cs211/winter2012/journals/garrett/home.txt · Last modified: 2012/03/07 03:47 by garrettheath4
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0