Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 36bab00

Browse files
committed
DOCS Added docs to binary_search and rank functions plus other refactorings
1 parent a504236 commit 36bab00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def print_int_array(the_array: [int]) -> None:
103103

104104
def matrix_transposition(the_matrix: [[int]]) -> [[int]]:
105105
"""Returns the transposition of a matrix"""
106-
rows = len(the_matrix)
107-
cols = len(the_matrix[0]) # the number of columns remain constant
106+
rows: int = len(the_matrix)
107+
cols: int = len(the_matrix[0]) # the number of columns remain constant
108108

109109
transposed_matrix = [[0] * rows for _ in range(cols)]
110110

@@ -141,10 +141,12 @@ def fact(n: int) -> int:
141141

142142

143143
def binary_search(key: int, the_array: [int]) -> int:
144+
"""Calls _rank() to binary search the_array"""
144145
return _rank(key, sorted(the_array), 0, len(the_array) - 1) # works best on sorted arrays
145146

146147

147148
def _rank(key: int, the_array: [int], min_index: int, max_index: int) -> int:
149+
"""Returns the index of the key if present, -1 if not"""
148150
if min_index > max_index:
149151
return -1
150152

@@ -221,7 +223,7 @@ def main():
221223
print()
222224
print("- Recursive Fib")
223225

224-
for i in range(4):
226+
for i in range(40):
225227
print(Fibonacci.fib(i))
226228

227229
print()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /