Skip to content

Commit b9edce1

Browse files
author
Partho Biswas
committed
code updated
1 parent 7af153e commit b9edce1

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

algoexpert.io/python/Kadane's_Algorithm.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33

44
# O(n) time | O(1) space - where n is the length of the input array
5-
def kadanes_algorithm(array):
6-
max_ending_here = array[0]
7-
max_so_far = array[0]
8-
for i in range(1, len(array)):
9-
num = array[i]
10-
max_ending_here = max(num, max_ending_here + num)
11-
max_so_far = max(max_so_far, max_ending_here)
12-
return max_so_far
5+
def kadanesAlgorithm(array):
6+
maxEdingHere, maxSoFar = array[0], array[0]
7+
for i in range(1, len(array)):
8+
num = array[i]
9+
maxEdingAtPrevIdx = maxEdingHere
10+
maxEdingHere = max(num, num + maxEdingAtPrevIdx)
11+
maxSoFar = max(maxSoFar, maxEdingHere)
12+
return maxSoFar
1313

algoexpert.io/python/Selection_Sort.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
# Best: O(n^2) time | O(1) space
55
# Avarage: O(n^2) time | O(1) space
66
# Worst: O(n^2) time | O(1) space
7-
def selection_sort(input_array):
7+
def selectionSort(array):
88
current_index = 0
9-
while current_index < len(input_array) - 1:
9+
while current_index < len(array) - 1:
1010
smallest_index = current_index
11-
for i in range(current_index + 1, len(input_array)):
12-
if input_array[i] < input_array[current_index]:
11+
for i in range(current_index + 1, len(array)):
12+
if array[i] < array[smallest_index]:
1313
smallest_index = i
14-
swap(current_index, smallest_index, input_array)
15-
current_index += 1
16-
return input_array
17-
14+
swap(current_index, smallest_index, array)
15+
current_index += 1
16+
return array
1817

1918
def swap(i, j, array):
2019
array[i], array[j] = array[j], array[i]

0 commit comments

Comments
 (0)