Uncategorized

What is Kadane’s algorithm

By 2022-12-18No Comments

Kadane’s algorithm is a way to find the subarray with the largest sum in an array of numbers. It involves iterating over the elements of the array and keeping track of the maximum sum ending at each index.

Imagine you have a jar with some marbles in it, and each marble has a number written on it. Kadane’s algorithm helps you find the group of marbles with the highest total sum. Here’s how it works:

  1. Take one marble at a time and check if adding it to the current group of marbles will make the total sum larger. If it does, add the marble to the group. If it doesn’t, start a new group with just that marble.
  2. Repeat this process for all the marbles.
  3. At the end, the group with the highest total sum is the subarray with the largest sum.

For example, let’s say you have the following array of numbers: [1, -3, 2, -5, 7, 6, -1, 4]. Here’s how you can find the subarray with the largest sum using Kadane’s algorithm:

  1. Take the first marble (1) and add it to a group. The total sum of the group is 1.
  2. Take the second marble (-3) and add it to the group. The total sum of the group is now -2.
  3. Take the third marble (2) and add it to the group

sure

 

미국식
[ʃʊr]
영국식
[ʃʊə(r); ʃɔː(r)]
1. 확신하는, 확실히 아는 (=certain), (↔unsure)
2. 확실히[틀림없이] ~을 받을/~을 할
3. 그럼[그래](요) (=yes)
4. (강조의 의미로) 정말