diff --git a/algorithms/2_BubbleSort/bubble_sort_exercise.md b/algorithms/2_BubbleSort/bubble_sort_exercise.md index 5068b08..e930890 100644 --- a/algorithms/2_BubbleSort/bubble_sort_exercise.md +++ b/algorithms/2_BubbleSort/bubble_sort_exercise.md @@ -36,5 +36,5 @@ elements = [ ] ``` -[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithmsAlgorithms/2_BubbleSort/bubble_sort_exercise_solution.py) +[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithms/2_BubbleSort/bubble_sort_exercise_solution.py) diff --git a/algorithms/8_recursion/recursion.py b/algorithms/8_recursion/recursion.py new file mode 100644 index 0000000..a903e1f --- /dev/null +++ b/algorithms/8_recursion/recursion.py @@ -0,0 +1,16 @@ +def find_sum(n): + if n==1: + return 1 + return n + find_sum(n-1) + +def fib(n): + # 0,1,1,2,3,5,8 <-- fibonacci numbers + # -------------- + # 0,1,2,3,4,5,6 <-- index + if n==0 or n==1: + return n + return fib(n-1) + fib(n-2) + +if __name__=='__main__': + print(find_sum(5)) + print(fib(10)) \ No newline at end of file diff --git a/data_structures/2_Arrays/Solution/3_odd_even_numbers.py b/data_structures/2_Arrays/Solution/3_odd_even_numbers.py index 334b53c..ec1c4b7 100644 --- a/data_structures/2_Arrays/Solution/3_odd_even_numbers.py +++ b/data_structures/2_Arrays/Solution/3_odd_even_numbers.py @@ -2,8 +2,8 @@ odd_numbers = [] -for i in range(max): - if i%2 == 1: +for i in range(1, max): + if i % 2 == 1: odd_numbers.append(i) -print("Odd numbers: ",odd_numbers) +print("Odd numbers: ", odd_numbers)