Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d5887ca

Browse files
committed
recursion exercise 4-9
1 parent 30e69cb commit d5887ca

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

PythonDataStructsAndAlgo/Notes.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@
2727
2828
>> os.path.join(path, filename) - Compose a path string name and filename string using an appropriate operating system separator between the two ("/" or "\\\"). Returning the string that represents the full path to the file.
2929
30-
> Linear recursion - if a recursive function is designed so that each invocation of the body makes at most one new recursive call, this is known as linear recursion.
30+
> Linear recursion - if a recursive function is designed so that each invocation of the body makes at most one new recursive call, this is known as linear recursion.
31+
32+
> Multiple Recursion - process in which a function may take more than 2 recursive calls.
33+
34+
### Defining Recursive Algorithms
35+
36+
>Test for base cases - there should be at least 1 base case. These base cases should be defined so that every possible chain of recursive calls will eventually reach a base case, and the handling of each base case.
37+
38+
>Recur - If not a base case, we perform one or more recursive calls. This recursive step may involve a test that decides which of several possible recursive calls to make. We should define each possible recursive call so that it makes progress torwards a base case.
39+
40+
#### Parameterizing a recursion
41+
> To design a good algorithm, it is useful to think of the different ways we might define the subproblems that have the same general structure as the original problem.
42+
43+
>Tail recursion - if any recursive call that is made from one context is the very last operation in that context, with the return value of the recursive call immediately returned by enclosing recursion.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def minMax(list, length):
2+
if(length ==1):
3+
return list[0]
4+
return max(list[length-1], minMax(list, length-1))
5+
6+
list=[2,5,2,3,8,9,3,1]
7+
8+
print(minMax(list, len(list)))

0 commit comments

Comments
 (0)