From a2c4a7cfb2dbc884b48e1f945de4544d10f5b543 Mon Sep 17 00:00:00 2001 From: cparthiv Date: Fri, 4 Apr 2025 10:18:45 -0700 Subject: [PATCH 1/2] simplify fibonacci recurse --- 01-Introduction/index.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/01-Introduction/index.py b/01-Introduction/index.py index 9e85259..b3b85f7 100644 --- a/01-Introduction/index.py +++ b/01-Introduction/index.py @@ -42,10 +42,8 @@ # Not memoized def fibo(n): - if n == 0: - return 0 - if n == 1: - return 1 + if n < 2: + return n; return fibo(n-1) + fibo(n-2) print(fibo(10)) From 675d07a4567014ea6d91725832d6360d226b700f Mon Sep 17 00:00:00 2001 From: cparthiv Date: Sat, 5 Apr 2025 16:20:17 -0700 Subject: [PATCH 2/2] return -1 if element not present --- 03-Sorting/index3.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/03-Sorting/index3.py b/03-Sorting/index3.py index f36048f..d2fbbf6 100644 --- a/03-Sorting/index3.py +++ b/03-Sorting/index3.py @@ -22,6 +22,8 @@ def binary_search(arr, elem, prim_index=0): + if len(arr) < 2: + return -1 mid = int(len(arr) / 2) mid_elem = arr[mid] if mid_elem == elem: