Skip to content

AnaPauR/Homeworks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Explanation

For this task I made a Python implementation of an algorithm to find the maximum sum subarray within an array. The algorithm implemented here is known as Kadane's algorithm, which efficiently solves the maximum subarray sum problem in linear time complexity.

About the algorithm

Kadane's algorithm is a dynamic programming-based approach to find the maximum sum subarray within an array of integers. It iterates through the array, maintaining the maximum sum found so far (max_so_far) and the current sum of elements (curr_sum). At each step, it updates 'curr_sum' by adding the current element to it and compares it with 'max_so_far'. If 'curr_sum' becomes greater than 'max_so_far', 'max_so_far' is updated accordingly. If 'curr_sum' becomes negative, it is reset to zero, effectively starting a new subarray. By iteratively updating these variables, the algorithm finds the maximum sum subarray.

About the code

This code implements Kadane's algorithm to efficiently find the maximum sum subarray within an array of integers. It handles both positive and negative numbers, as well as cases where the entire array is negative. To use the code you must call the 'max_sum_subarray' function and pass any array of integers as an argument. The function will return the maximum sum subarray along with its start and end indices.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages