Skip to content

Commit

Permalink
correction of docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
xtof-durr committed Jan 8, 2024
1 parent 264e57f commit 87d5389
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tryalgo/dyn_prog_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def dyn_prog_Monge(W):


def _decode(i, j, R, level, current):
"""Decodes a binary search tree encoded in the root matrix R into a level array
:returns: the level array
:complexity: linear
"""
"""is used by decode_root_matrix_to_level for recursive decoding."""
if i >= j:
return # nothing to do
root = R[i][j]
Expand All @@ -55,6 +52,10 @@ def _decode(i, j, R, level, current):


def decode_root_matrix_to_level(R):
"""Decodes a binary search tree encoded in the root matrix R into a level array
:returns: the level array
:complexity: linear
"""
n = len(R)
level = [0] * n
_decode(0, n - 1, R, level, 0)
Expand All @@ -69,8 +70,8 @@ def opt_bin_search_tree2(success, failure):
:param failure: n+1 dimensional array with frequency between the elements,
failure[i] is frequency of a query strictly between element i and i+1.
These arrays do not have to be normalized.
:returns level: n dimensional array with the level of each element
in an optimal search tree. The index i with level[i]==0 is the root.
:returns: The value of an optimal search tree and the matrix with the roots for each
subproblem, encoding the actual tree.
:complexity: O(n^2)
"""
n = len(failure)
Expand All @@ -86,8 +87,8 @@ def opt_bin_search_tree1(freq):
""" Optimal binary search tree on elements from 0 to n-1
:param freq: n dimensional array with frequency of every element i.
:returns level: n dimensional array with the level of each element
in an optimal search tree. The index i with level[i]==0 is the root.
:returns: The value of an optimal search tree and the matrix with the roots for each
subproblem, encoding the actual tree.
:complexity: O(n^2)
"""
n = len(freq)
Expand Down

0 comments on commit 87d5389

Please sign in to comment.