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

Commit 351c699

Browse files
committed
More recursion exercises
1 parent 021bcaf commit 351c699

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

PythonDataStructsAndAlgo/Notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@
5252
5353
> This can be done from the copy module using the deepcopy() function.
5454
55-
> To produce an array of 8 elements with a value 0 we can do: counters= [0] *8, meaning all the cells in the list reference to the same object "0"
55+
> To produce an array of 8 elements with a value 0 we can do: counters= [0] *8, meaning all the cells in the list reference to the same object "0"
56+

PythonDataStructsAndAlgo/Recursion/C-4-17.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ def isPalindrome(str):
66
if str[0] != str[-1]:
77
return False
88
print(str)
9+
"""Every time the function is called the array decrements in size and the
10+
first and last elements are ignored, thus traveling through the array
11+
Thus with recursion the size of the array decreases """
912
return isPalindrome(str[1:-1])
1013

1114
print(isPalindrome('racecar'))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def whichHasMore(str):
2+
vowels=['a','e','i','o','u']
3+
4+
if len(str) == 0:
5+
return 0
6+
if str[0] not in vowels:
7+
return 1 + whichHasMore(str[1:])
8+
else:
9+
return whichHasMore(str[1:])
10+
11+
print(whichHasMore("hoi"))

0 commit comments

Comments
 (0)