User:Lokyung/sandbox
When analyzing algorithms, we only care about the asymptotic behavior. Rather than solving exactly the recurrence relation associated with the cost of an algorithm, it is sufficient to give an asymptotic characterization. The main tool for doing this is the Master Theorem.
Introduction
[edit]Let T(n) be a monotonically increasing function that satisfy:
In the application to the analysis of a recursive algorithm, the constants and function take on the following significance:
- n is the size of the problem.
- a is the number of subproblems in the recursion.
- n/b is the size of each subproblem. (Here it is assumed that all subproblems are essentially the same size.)
- f (n) is the cost of the work done outside the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions to the subproblems.
If is where then:
Master Theorem: Pitfalls
[edit]You cannot use the Master Theorem if
- is not monotone, example:
- is not a polynomial, example:
- cannot be expressed as a constant, example:
Note that the Master Theorem does not solve the recurrence equation.
Example
[edit]Case 1:
Let
What are the parameters?
Therefore, which condition applies?
- ;
We conclude that
- Now let's see if this make sense
- Assume
- Indeed,
Case 2:
Let
What are the parameters?
Therefore, which condition applies?
- ;
We conclude that
Case 3:
Let
What are the parameters?
Therefore, which condition applies?
- ;
We conclude that
Application to common algorithms
[edit]Algorithm | Recurrence Relationship | Run time | Comment |
---|---|---|---|
Binary search | Apply Master theorem case , where [1] | ||
Binary tree traversal | Apply Master theorem case where [1] | ||
Optimal Sorted Matrix Search | Apply Akra-Bazzi theorem for and to get | ||
Merge Sort | Apply Master theorem case , where |
Thomas H. Cormen
[edit]Thomas H. Cormen is the co-author of Introduction to Algorithms, along with Charles Leiserson, Ron Rivest, and Clifford Stein. He has a new book out called Algorithms Unlocked. He is a Full Professor of computer science at Dartmouth College and currently Chair of the Dartmouth College Department of Computer Science. Between 2004 and 2008 he directed the Dartmouth College Writing Program.
Thomas H. Cormen was born in New York City in 1956. He grew up in Oceanside, New York. He received his bachelor's degree in Electrical Engineering and Computer Science from Princeton University in June 1978. He then went to Massachusetts Institute of Technology, where he earned his master's degree in Electrical Engineering and Computer Science in May 1986 and his PhD in 1993.
Thomas's personal life ( off his website )
My wife, Nicole, and I took a Barbecue tour of the South in August 1998.
In July 2010, I rollerbladed the Trail of the Coeur D'Alenes, a 71.4-mile-long paved rail trail in the Idaho panhandle. Accompanied by my friend, Paul Daro, who also bladed, and Nicole, who biked, we went 42 miles the first day and the balance the second day. Here is a photo of the three of us at the start of the first day, at the western trailhead in Plummer, Idaho, (on the Coeur D'Alene reservation) and here is a photo of Paul and me at the start of the second day, at the eastern trailhead in Mullan, Idaho. We met this fellow on the trail during the first day. This page has some rough videos that Paul took.
My brother-in-law, Tony Pecora, is the first patient in the US to undergo the Edmonton Protocol for treatment of juvenile diabetes. Check out his website at http://www.isletsupporter.com.
I was the Ice Man for the Maryland State Barbecue Championship in 2003, 2004, and 2005. Here's a photo from the 2005 contest of me with a quad-runner full of 40-pound bags of ice. The photo was taken by the Dizzy Pigs, the 2005 and 2006 Grand Champions. Even with the megaphone, I was pretty hoarse by the end of the second day. The Dizzy Pigs, and all the other contestants, can explain why.
I was Kansas City Barbeque Society Certified Barbeque Judge number 62145. (I have purposely let my KCBS membership lapse.) My first contest as a certified judge was the 2011 Maryland State Championship in Bel Air. Here is a photo of me just starting to judge the first item, chicken. And here is a photo after judging five entries each of chicken, pork ribs, pork, and beef brisket. (Photos courtesy of Craig Ward, a.k.a. "Mr. Time To Go," a.k.a. "Large And In Charge," the contest organizer.)
In September 1997, Nicole and I finished hiking all 48 of the 4000-foot peaks in the White Mountains of New Hampshire.
A former student wrote an article for USA Hockey about the time I was "that guy." (The photo in the article is not of me. Goalies have all their teeth.)
Have you ever noticed something odd about bank deposit slips?
When is a door not a door?
References
[edit]- ^ a b Dartmouth College, http://www.math.dartmouth.edu/archive/m19w03/public_html/Section5-2.pdf