diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-05-24 11:18:46 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-05-24 11:19:55 -0500 |
commit | 7a73162607544204032aa66cce755daf21edebda (patch) | |
tree | 58578e01f15f34a855d99c32898db9d7a1603e67 /csci4041/hw2prob3.py | |
parent | do some stuff (diff) | |
download | homework-7a73162607544204032aa66cce755daf21edebda.tar homework-7a73162607544204032aa66cce755daf21edebda.tar.gz homework-7a73162607544204032aa66cce755daf21edebda.tar.bz2 homework-7a73162607544204032aa66cce755daf21edebda.tar.lz homework-7a73162607544204032aa66cce755daf21edebda.tar.xz homework-7a73162607544204032aa66cce755daf21edebda.tar.zst homework-7a73162607544204032aa66cce755daf21edebda.zip |
Graduate
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'csci4041/hw2prob3.py')
-rw-r--r-- | csci4041/hw2prob3.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/csci4041/hw2prob3.py b/csci4041/hw2prob3.py new file mode 100644 index 0000000..cc53704 --- /dev/null +++ b/csci4041/hw2prob3.py @@ -0,0 +1,34 @@ +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 + 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, 3, 5, 6, 8, 9] + +#TESTS +print(IS_IN_MIN_HEAP(l, 0)) +print(IS_IN_MIN_HEAP(l, 1)) +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, 9)) +print(IS_IN_MIN_HEAP(l, 200))
\ No newline at end of file |