SlideShare a Scribd company logo
Maximum Sum Subarray
Presented by Shaheen Kousar
Topics
• Introduction
– Maximum sum subarray problem
– WHY MSS?
• Approaches
• Kadane’s Algorithm
– One-Dimensional Array
– Two-Dimensional Array
Maximum Sum Problem
• Given array of numbers, find the subarray
(contiguous elements) with the largest
aggregate
-3 7 -12 1 6 -3 5 -2
WHY MSS?
• Maximum Sum Subarray problem is widely
used in applications such as pattern
recognition, image processing and data
mining.
Approaches
– Brute-Force Algorithm
– Divide And Conquer
– Kadane’s Algorithm
One-Dimensional Array
1 -3 2 -5 7 6 -1 -4 11 -23
• Let’s Find the Max subarray ending with A [4]=7
7-5
-5
-52
-5
7
-3 2
7
7-3 2
7
1
7
2
4
1
2
1 -3 2 -5 7 6 -1 -4 11 -23
Let’s Find the Max subarray ending with A [6]=-1
7-5
-5
-52
-5
7
-3 2
7
7-3 2
7
1
-1
-1
-1
-1
6
6
6
6
6
6
-1
-1
-1
-1
5
12
7
9
6
7
Two-Dimensional Array
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
2
0
2
-3
L = 0 , R = 0, Current Sum = 4 , Max Sum= 4,
Max-left = 0, Max-right = 0,Max-up= 0, Max-down = 2
0
1
2
3
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
3
6
0
0
Max-Sum = 4
L = 0 , R = 1, Current Sum = 9, Max Sum= 9,
Max-left = 0, Max-right = 1,Max-up= 0, Max-down = 1
0
1
2
3
2
0
2
-3
0
1
2
3
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
0
9
-1
1
Max-Sum = 9
• Current sum is not greater than max-sum here!
L = 0 , R = 2, Current Sum = 9, Max Sum= 9,
Max-left = 0, Max-right = 1,Max-up= 0, Max-down = 1
0
1
2
3
3
6
0
0
0
1
2
3
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
-4
13
3
1
Max-Sum = 9
L = 0 , R = 3, Current Sum = 17, Max Sum= 17,
Max-left = 0, Max-right = 1,Max-up= 1, Max-down = 3
0
1
2
3
0
9
-1
1
0
1
2
3
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
-6
13
1
4
Max-Sum = 17
L = 1 , R = 3, Current Sum = 18, Max Sum= 18,
Max-left = 1, Max-right = 3,Max-up= 1, Max-down = 3
0
1
2
3
-2
9
-3
4
0
1
2
3
• Iterate for each value of Outer loop for
L=1,2,3,4 and for each outer loop perform
inner loop for R=1,2,3,4.
Let’s find the Rectangle having Maximum sum
in the 2D Matrix
Index 0 1 2 3 4
0 2 1 -3 -4 5
1 0 6 3 4 1
2 2 -2 -1 4 -5
3 -3 3 1 0 3
-6
13
1
4
Max-Sum = 18
Max-left = 1, Max-right = 3,Max-up= 1, Max-down = 3
0
1
2
3
Time Complexity
Time Complexity for Kadane’s Algorithm is O(N^2).
_______________________________

More Related Content

What's hot

Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
AYESHA JAVED
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
Divya Ks
 
Backtracking
BacktrackingBacktracking
Backtracking
Pranay Meshram
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
Jenny Galino
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
Abhishek Singh
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Kmp
KmpKmp
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
Traian Rebedea
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
Hira Gul
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Melaku Bayih Demessie
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 

What's hot (20)

Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Kmp
KmpKmp
Kmp
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
 
Lower bound
Lower boundLower bound
Lower bound
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 

Similar to Maximum sum subarray

DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHMDATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
ABIRAMIS87
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and Algorithms
Cool Guy
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
jannatulferdousmaish
 
Number System2.pptx
Number System2.pptxNumber System2.pptx
Number System2.pptx
AnshRattan
 
Optimum engineering design - Day 5. Clasical optimization methods
Optimum engineering design - Day 5. Clasical optimization methodsOptimum engineering design - Day 5. Clasical optimization methods
Optimum engineering design - Day 5. Clasical optimization methods
SantiagoGarridoBulln
 
2 d kadane
2 d kadane2 d kadane
2 d kadane
Tushar Bindal
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
ssuser01e301
 
Ke yi small summaries for big data
Ke yi small summaries for big dataKe yi small summaries for big data
Ke yi small summaries for big data
jins0618
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zeros
Daisy933462
 
The LCA problem revisited
The LCA problem revisitedThe LCA problem revisited
The LCA problem revisited
Minsung Hong
 
A framework for practical fast matrix multiplication
A framework for practical fast matrix multiplication�A framework for practical fast matrix multiplication�
A framework for practical fast matrix multiplication
Austin Benson
 
Algebra Trigonometry Problems
Algebra Trigonometry ProblemsAlgebra Trigonometry Problems
Algebra Trigonometry Problems
Don Dooley
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
vinay arora
 
Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014
Prof. Wim Van Criekinge
 
Alegebra Powers Substitution
Alegebra Powers SubstitutionAlegebra Powers Substitution
Alegebra Powers Substitution
Passy World
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
Tekle12
 
Problem Based Learning Presentation NACA
Problem Based Learning Presentation NACAProblem Based Learning Presentation NACA
Problem Based Learning Presentation NACA
Wahid Dino Samo
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
TayyabSattar5
 
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
22bcs058
 
7.2 Pythagorean Triples and Simplifying Radicals
7.2 Pythagorean Triples and Simplifying Radicals7.2 Pythagorean Triples and Simplifying Radicals
7.2 Pythagorean Triples and Simplifying Radicals
smiller5
 

Similar to Maximum sum subarray (20)

DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHMDATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and Algorithms
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
 
Number System2.pptx
Number System2.pptxNumber System2.pptx
Number System2.pptx
 
Optimum engineering design - Day 5. Clasical optimization methods
Optimum engineering design - Day 5. Clasical optimization methodsOptimum engineering design - Day 5. Clasical optimization methods
Optimum engineering design - Day 5. Clasical optimization methods
 
2 d kadane
2 d kadane2 d kadane
2 d kadane
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
 
Ke yi small summaries for big data
Ke yi small summaries for big dataKe yi small summaries for big data
Ke yi small summaries for big data
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zeros
 
The LCA problem revisited
The LCA problem revisitedThe LCA problem revisited
The LCA problem revisited
 
A framework for practical fast matrix multiplication
A framework for practical fast matrix multiplication�A framework for practical fast matrix multiplication�
A framework for practical fast matrix multiplication
 
Algebra Trigonometry Problems
Algebra Trigonometry ProblemsAlgebra Trigonometry Problems
Algebra Trigonometry Problems
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
 
Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014Bioinformatics t5-databasesearching v2014
Bioinformatics t5-databasesearching v2014
 
Alegebra Powers Substitution
Alegebra Powers SubstitutionAlegebra Powers Substitution
Alegebra Powers Substitution
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
Problem Based Learning Presentation NACA
Problem Based Learning Presentation NACAProblem Based Learning Presentation NACA
Problem Based Learning Presentation NACA
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
 
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
 
7.2 Pythagorean Triples and Simplifying Radicals
7.2 Pythagorean Triples and Simplifying Radicals7.2 Pythagorean Triples and Simplifying Radicals
7.2 Pythagorean Triples and Simplifying Radicals
 

Recently uploaded

Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussionArtificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
amekonnen
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Rosie Wells
 
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Dutch Power
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
gharris9
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
kkirkland2
 
Updated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidismUpdated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidism
Faculty of Medicine And Health Sciences
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij
 
2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf
Frederic Leger
 
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPointMẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
1990 Media
 
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
OECD Directorate for Financial and Enterprise Affairs
 
Carrer goals.pptx and their importance in real life
Carrer goals.pptx  and their importance in real lifeCarrer goals.pptx  and their importance in real life
Carrer goals.pptx and their importance in real life
artemacademy2
 
Competition and Regulation in Professions and Occupations – ROBSON – June 202...
Competition and Regulation in Professions and Occupations – ROBSON – June 202...Competition and Regulation in Professions and Occupations – ROBSON – June 202...
Competition and Regulation in Professions and Occupations – ROBSON – June 202...
OECD Directorate for Financial and Enterprise Affairs
 
XP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to LeadershipXP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to Leadership
samililja
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
ToshihiroIto4
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
SkillCertProExams
 
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussionPro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
gpww3sf4
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Dutch Power
 

Recently uploaded (20)

Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussionArtificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
 
Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
 
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
 
Updated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidismUpdated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidism
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
 
2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf
 
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPointMẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
Mẫu PPT kế hoạch làm việc sáng tạo cho nửa cuối năm PowerPoint
 
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
 
Carrer goals.pptx and their importance in real life
Carrer goals.pptx  and their importance in real lifeCarrer goals.pptx  and their importance in real life
Carrer goals.pptx and their importance in real life
 
Competition and Regulation in Professions and Occupations – ROBSON – June 202...
Competition and Regulation in Professions and Occupations – ROBSON – June 202...Competition and Regulation in Professions and Occupations – ROBSON – June 202...
Competition and Regulation in Professions and Occupations – ROBSON – June 202...
 
XP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to LeadershipXP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to Leadership
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
 
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussionPro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
 
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
 

Maximum sum subarray

  • 1. Maximum Sum Subarray Presented by Shaheen Kousar
  • 2. Topics • Introduction – Maximum sum subarray problem – WHY MSS? • Approaches • Kadane’s Algorithm – One-Dimensional Array – Two-Dimensional Array
  • 3. Maximum Sum Problem • Given array of numbers, find the subarray (contiguous elements) with the largest aggregate -3 7 -12 1 6 -3 5 -2
  • 4. WHY MSS? • Maximum Sum Subarray problem is widely used in applications such as pattern recognition, image processing and data mining.
  • 5. Approaches – Brute-Force Algorithm – Divide And Conquer – Kadane’s Algorithm
  • 6. One-Dimensional Array 1 -3 2 -5 7 6 -1 -4 11 -23
  • 7. • Let’s Find the Max subarray ending with A [4]=7 7-5 -5 -52 -5 7 -3 2 7 7-3 2 7 1 7 2 4 1 2 1 -3 2 -5 7 6 -1 -4 11 -23
  • 8. Let’s Find the Max subarray ending with A [6]=-1 7-5 -5 -52 -5 7 -3 2 7 7-3 2 7 1 -1 -1 -1 -1 6 6 6 6 6 6 -1 -1 -1 -1 5 12 7 9 6 7
  • 9. Two-Dimensional Array Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3
  • 10. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 2 0 2 -3 L = 0 , R = 0, Current Sum = 4 , Max Sum= 4, Max-left = 0, Max-right = 0,Max-up= 0, Max-down = 2 0 1 2 3
  • 11. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 3 6 0 0 Max-Sum = 4 L = 0 , R = 1, Current Sum = 9, Max Sum= 9, Max-left = 0, Max-right = 1,Max-up= 0, Max-down = 1 0 1 2 3 2 0 2 -3 0 1 2 3
  • 12. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 0 9 -1 1 Max-Sum = 9 • Current sum is not greater than max-sum here! L = 0 , R = 2, Current Sum = 9, Max Sum= 9, Max-left = 0, Max-right = 1,Max-up= 0, Max-down = 1 0 1 2 3 3 6 0 0 0 1 2 3
  • 13. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 -4 13 3 1 Max-Sum = 9 L = 0 , R = 3, Current Sum = 17, Max Sum= 17, Max-left = 0, Max-right = 1,Max-up= 1, Max-down = 3 0 1 2 3 0 9 -1 1 0 1 2 3
  • 14. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 -6 13 1 4 Max-Sum = 17 L = 1 , R = 3, Current Sum = 18, Max Sum= 18, Max-left = 1, Max-right = 3,Max-up= 1, Max-down = 3 0 1 2 3 -2 9 -3 4 0 1 2 3
  • 15. • Iterate for each value of Outer loop for L=1,2,3,4 and for each outer loop perform inner loop for R=1,2,3,4.
  • 16. Let’s find the Rectangle having Maximum sum in the 2D Matrix Index 0 1 2 3 4 0 2 1 -3 -4 5 1 0 6 3 4 1 2 2 -2 -1 4 -5 3 -3 3 1 0 3 -6 13 1 4 Max-Sum = 18 Max-left = 1, Max-right = 3,Max-up= 1, Max-down = 3 0 1 2 3
  • 17. Time Complexity Time Complexity for Kadane’s Algorithm is O(N^2). _______________________________