aboutsummaryrefslogtreecommitdiffstats
path: root/csci4041
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2020-03-02 16:31:05 -0600
committerRossTheRoss <msattr@gmail.com>2020-03-02 16:31:05 -0600
commitc8b2a92f44b47f648488a6d5f7a89d8ffc705184 (patch)
treedc058e2ad5fa4631e7f892aa17c0c5e988940c22 /csci4041
parentDo 4041 HW (diff)
downloadhomework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar.gz
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar.bz2
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar.lz
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar.xz
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.tar.zst
homework-c8b2a92f44b47f648488a6d5f7a89d8ffc705184.zip
fix 4041 hw?
Diffstat (limited to 'csci4041')
-rw-r--r--csci4041/hw2prob3.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/csci4041/hw2prob3.py b/csci4041/hw2prob3.py
index 9fd64b3..f3a6806 100644
--- a/csci4041/hw2prob3.py
+++ b/csci4041/hw2prob3.py
@@ -1,19 +1,24 @@
def CHILD(i,j):
return 2*i + (j+1)
+
def IS_IN_MIN_HEAP(A,e):
return FIND_ELEMENT(A,0,e)
def FIND_ELEMENT(A,i,e):
if A[i] is e:
return True
- elif CHILD(i,0) < len(A) and A[CHILD(i,0)] <= e:
- return IS_IN_MIN_HEAP(A[1:],e)
- if CHILD(i,1) < len(A) and A[CHILD(i,1)] <= e:
- return IS_IN_MIN_HEAP(A[2:],e)
- return False
+ else:
+ bool = False
+ lChild = CHILD(i, 0)
+ rChild = CHILD(i, 1)
+ if lChild < len(A) and A[lChild] <= e:
+ bool = FIND_ELEMENT(A, lChild, e)
+ if bool is not True and rChild < len(A) and A[rChild] <= e:
+ bool = FIND_ELEMENT(A, rChild, e)
+ return bool
#TEST MIN-HEAP
#Feel free to redefine as much as you want
-l = [0, 2, 4, 5, 8, 12, 20]
+l = [0, 2, 3, 5, 6, 8, 9]
#TESTS
print(IS_IN_MIN_HEAP(l, 0))
@@ -22,7 +27,7 @@ print(IS_IN_MIN_HEAP(l, 2))
print(IS_IN_MIN_HEAP(l, 3))
print(IS_IN_MIN_HEAP(l, 4))
print(IS_IN_MIN_HEAP(l, 5))
+print(IS_IN_MIN_HEAP(l, 6))
+print(IS_IN_MIN_HEAP(l, 7))
print(IS_IN_MIN_HEAP(l, 8))
-print(IS_IN_MIN_HEAP(l, 10))
-print(IS_IN_MIN_HEAP(l, 11))
-print(IS_IN_MIN_HEAP(l, 20))
+print(IS_IN_MIN_HEAP(l, 9))