AlgoGenesis / C

AlgoGenesis is a centralized open-source platform dedicated to providing optimized and well-documented algorithm implementations in C. Perfect for both beginners and advanced users, this repository serves as a comprehensive learning resource for solving algorithmic challenges.
MIT License
33 stars 87 forks source link

Kadan's Algorithm #270

Open Bhumika-00 opened 1 day ago

Bhumika-00 commented 1 day ago

Description:

I am proposing Kadan's Algorithm that is used to calculate the sub arrays in an array.

Checklist:

Additional Information:

Kadane's Algorithm is a well-known method for finding the maximum sum of a contiguous subarray within a one-dimensional array of numbers. It efficiently computes the result in linear time, making it very effective for large datasets.

How It Works: Initialization:

Start with two variables: max_so_far to keep track of the maximum sum encountered so far (initialize it to a very small number, or the first element of the array). max_ending_here to store the maximum sum of the subarray that ends at the current position (initialize it to 0). Iterate through the array:

For each element in the array: Update max_ending_here by adding the current element. If max_ending_here exceeds max_so_far, update max_so_far. If max_ending_here drops below 0, reset it to 0 (since starting a new subarray could yield a higher sum). Final Result:

After processing all elements, max_so_far contains the maximum sum of any contiguous subarray..

github-actions[bot] commented 1 day ago

👋 Thank you for raising an issue! We appreciate your effort in helping us improve. Our team will review it shortly. Stay tuned!