Skip to content

Commit 3cd7762

Browse files
Update Kadanes.md
1 parent cb3c86d commit 3cd7762

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/dsa/Kadanes.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
id: Algorithms
2+
id:Kadanes-Algorithm
33
title: Kadanes Algorithm
4-
sidebar_label: Algorithms
4+
sidebar_label: KadanesAlgorithm
55
sidebar_position: 2
66
description: "Kadane's Algorithm efficiently finds the maximum sum contiguous subarray in a one-dimensional array. It's a dynamic programming technique named after its creator, Jay Kadane."
77
---
88
## Kadane's Algorithm:
99

1010
- **Purpose**: Finds the maximum sum of a contiguous subarray.
11-
- **Time Complexity**: O(n)
11+
- **Time Complexity**: $O(n)$
1212
- **Space Complexity**: O(1)
1313
- **Use Case**: Optimal for solving maximum subarray sum problems in linear time.
1414
### Simple Explanation
@@ -35,6 +35,7 @@ Output: 7
3535
Explanation: The subarray {4,-1, -2, 1, 5} has the largest sum 7.
3636

3737
### Python
38+
```py
3839

3940
def max_sub_array(nums):
4041
max_sum = float('-inf')
@@ -50,8 +51,10 @@ Explanation: The subarray {4,-1, -2, 1, 5} has the largest sum 7.
5051
current_sum = 0
5152

5253
return max_sum
54+
```
5355

5456
### C++
57+
```cpp
5558
// Kadane's Algorithm to find the maximum sum of a contiguous subarray
5659

5760
#include <iostream>
@@ -77,6 +80,7 @@ Explanation: The subarray {4,-1, -2, 1, 5} has the largest sum 7.
7780

7881
return max_sum;
7982
}
83+
```
8084
8185
### Explanation
8286
Explanation:

0 commit comments

Comments
 (0)