Skip to content

Commit

Permalink
Modified doc block comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0910 committed Feb 21, 2020
1 parent 559ccce commit 0e6a302
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 2 additions & 4 deletions Trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,19 @@ def bottom_nodes(node):

def left_nodes(node):
if node:
print(node.data, end=" ")
if node.left:
print(node.data, end=" ")
left_nodes(node.left)
elif node.right:
print(node.right, end=" ")
left_nodes(node.right)

def right_nodes(node):
if node:
if node.right:
right_nodes(node.right)
print(node.data, end=" ")
elif node.left:
right_nodes(node.left)
print(node.data, end=" ")
print(node.data, end=" ")
print(root.data, end=" ")
left_nodes(root.left)
bottom_nodes(root)
Expand Down
4 changes: 3 additions & 1 deletion array/bitonic_point.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
def bitonic_point(a, start, end):
"""
Function to find bitonic point in an array.
Bitonic array is the array with increases initially and then gradually decreases.
Bitonic array is the array with increases initially and then decreases after the pivot point.
The pivot point is the element which has elements in increasing sequence on the left and decreasing sequence
on the right
:param a: List
:param start: Int
:param end: Int
Expand Down
19 changes: 15 additions & 4 deletions array/rotated_array.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# a = [8, 9, 1, 2, 3, 4, 5, 6, 7]
a = [8, 9, 1, 2, 3, 4, 5, 6, 7]
# a = [4 ,5 ,6, 7, 8, 9, 1, 2, 3]
a = [1, 2, 3, 4, 5]


def find_lowest(a, low, high):
"""
To find the lowest number in a sorted rotated array.
The approach is to use binary search recursively and check for condition on the middle element of sub-arrays
If middle element is not lower than the mid-1 element, then recursive call on either left or right sub-array.
If a[mid] < a[high] then left sub-array else right sub-array.
:param a: List
:param low: Int
:param high: Int
:return: Int
"""
if not a:
return -1
if a[0] < a[-1]:
Expand All @@ -12,10 +22,11 @@ def find_lowest(a, low, high):
mid = (low+high) // 2
if a[mid-1] > a[mid] and a[mid] < a[mid+1]:
return a[mid]
elif abs(a[mid] - a[low]) > abs(a[mid] - a[high-1]):
elif a[mid] < a[high-1]:
return find_lowest(a, 0, mid-1)
else:
return find_lowest(a, mid+1, high)


x = find_lowest(a, 0, len(a)-1)
print(x)
print(x)

0 comments on commit 0e6a302

Please sign in to comment.