From 6b20815f757331e66295c51f8a2815de86e59451 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Tue, 28 Jan 2025 13:35:36 -0500 Subject: [PATCH] updating notes --- .../07_order_notation_recursion/README.md | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lectures/07_order_notation_recursion/README.md b/lectures/07_order_notation_recursion/README.md index 55bb831..4b9743c 100644 --- a/lectures/07_order_notation_recursion/README.md +++ b/lectures/07_order_notation_recursion/README.md @@ -2,10 +2,10 @@ - Algorithm Analysis, Formal Definition of Order Notation - Simple recursion, Visualization of recursion, Iteration vs. Recursion -- “Rules” for writing recursive functions, Lots of examples -- Lots of Examples! +- “Rules” for writing recursive functions + @@ -75,7 +75,7 @@ quadratic root. - O(n2), O(n3), O(nk), a.k.a. POLYNOMIAL. e.g., find closest pair of points. - O(2n), O(kn), a.k.a. EXPONENTIAL. e.g., Fibonacci, playing chess. -## 7.6 Exercise: A Slightly Harder Example + -## 7.7 Best-Case, Average-Case and Worst-Case Analysis +## 7.6 Best-Case, Average-Case and Worst-Case Analysis - For a given fixed size array, we might want to know: – The fewest number of operations (best case) that might occur. @@ -100,7 +101,7 @@ if (found) cout << "It is there!\n"; - The last is the most common. The first is rarely used. - On the previous algorithm, the best case is O(1), but the average case and worst case are both O(n). -## 7.8 Approaching An Analysis Problem +## 7.7 Approaching An Analysis Problem - Decide the important variable (or variables) that determine the “size” of the problem. For arrays and other “container classes” this will generally be the number of values stored. @@ -111,7 +112,7 @@ of loop iterations. of comparisons. - Do the count and use order notation to describe the result. -## 7.9 Exercise: Order Notation +## 7.8 Exercise: Order Notation For each version below, give an order notation estimate of the number of operations as a function of n: @@ -140,7 +141,7 @@ for (int j=i; j -## 7.15 Rules for Writing Recursive Functions +## 7.14 Rules for Writing Recursive Functions Here is an outline of five steps that are useful in writing and debugging recursive functions. Note: You don’t have to do them in exactly this order... @@ -237,7 +239,7 @@ recursive calls. It is also the hardest part! are you going to do with the result of the recursive call?) 5. Assume the recursive calls work correctly, but make sure they are progressing toward the base case(s)! -## 7.16 Location of the Recursive Call — Example: Printing the Contents of a Vector +## 7.15 Location of the Recursive Call — Example: Printing the Contents of a Vector Here is a function to print the contents of a vector. Actually, it’s two functions: a driver function, and a true recursive function. It is common to have a driver function that just initializes the first recursive function call. @@ -268,7 +270,7 @@ int main() { How can you change the second print vec function as little as possible so that this code prints the contents of the vector in reverse order? -## 7.17 Fibonacci Optimization: Order Notation of Time vs. Space +## 7.16 Fibonacci Optimization: Order Notation of Time vs. Space The Fibonacci sequence is defined: ![alt text](fibonacci_sequence.png "fibonacci sequence")