SlideShare a Scribd company logo
Analysis of AlgorithmsAnalysis of Algorithms
Divide and Conquer Approach
1Instructor: Sadia Arshid, DCS &SE
 Divide the problems into a number of sub
problems.
 Conquer the sub problems by solving
them recursively. If the sub-problem
sizes are small enough, just solve the
problems in a straight forward manner.
 Combine the solutions to the sub
problems into the solution for the original
problem.
Divide and Conquer ApproachDivide and Conquer Approach
2Instructor: Sadia Arshid, DCS &SE
Divide-and-ConquerDivide-and-Conquer
AlgorithmsAlgorithms
 An algorithm design
– merge sort
– maxmin
– quick sort
– Matrix multiplication
 A larger problem is broken up into smaller
problems, the smaller problems are recursively,
and the results are merged together again
3Instructor: Sadia Arshid, DCS &SE
Divide-and-ConquerDivide-and-Conquer
AlgorithmsAlgorithms
More formally, we will consider only those
algorithms which:
– divide a problem into sub-problems, each
approximately of size n/b
– in all cases we have seen, the whole was
divided into b equal sub-problems
– solve those sub-problems recursively
– combine the solutions to the sub-problems to
get a solution to the overall problem
4Instructor: Sadia Arshid, DCS &SE
MERGE SORTMERGE SORT
Graphically, merge sort is represented as
follows:
Once we have sorted the shortest lists, then
we merge then back together again into a
sorted list
5Instructor: Sadia Arshid, DCS &SE
 Divide the n element sequence to be
sorted into two subsequences of n/2
elements each.
 Conquer: Sort the two subsequences to
produce the sorted answer.
 Combine: Merge the two sorted sub
sequences to produce the sorted answer.
Merge SortMerge Sort
6Instructor: Sadia Arshid, DCS &SE
Merge Sort AlgorithmMerge Sort Algorithm
procedure MergeSort(n,s)
h=n/2, m=n-h
u=array[1..h], v=array[m..n]
if n>1
copy s[1] through s[h] to u
copy s[h+1] through s[n] to v
mergesort(h,u)
mergesort(m,v)
merge(h,m,u,v,s] 7Instructor: Sadia Arshid, DCS &SE
procedure merge(h,m,u,v,s)
i=1,j=1,k=1
while i<=h and j<=m
if u[i]<v[j]
s[k]=u[i], i=i+1
else s[k]=v[j],j=j+1
k=k+1
if i>h
copy v[j] through v[m] to s[k] through s[h+m]
else
copy u[i] through u[h] to s[k] through s[h+m]
8Instructor: Sadia Arshid, DCS &SE
Merge SortMerge Sort Base Case: When the sequences to be sorted has length
1.
108 56 1214 89 3466Unsorted
108 56 1466
Divide
10866
Divide
66
Divide
66
BCase
66
Merge
108
Divide
108
BCase
108
Merge
66 108
Merge
56 14
Divide
56
Divide
56
BCase
56
Merge
14
Divide
14
BCase
14
Merge
14 56
Merge
56 66 10814
Merge
1289 34
Divide
1289
Divide
89
Divide
89
BCase
89
Merge
12
Divide
12
BCase
12
Merge
8912
Merge
34
Divide
34
BCase
34
Merge
3412 89
Merge
14 34 8956 66 10812Sorted
9Instructor: Sadia Arshid, DCS &SE
Merge Sort AnalysisMerge Sort Analysis
 T(n)=T[h]+T[m]+complexity of merge
 Complexity of merge: worst case, h+m-1
 Suppose n is a power of two, so that we always split
into even halves.
– h=n/2, m=n-n/2=n/2
– w(n)=w[n/2]+w[n/2]+n-1
 For n = 1 the time to merge sort is1 otherwise
 The time to merge sort n numbers is equal to the
time to do two recursive merge sorts of size n/2, plus
the time to merge, which is linear.
 Solve this recurrence to find out running time. 10Instructor: Sadia Arshid, DCS &SE
w(1) = 0
w(n) = 2w(n/2) + n-1
 W[n]=2w[n/2]+n-1
 W[n/2]=2w[n/4]+n/2-1
 W[n/4]=2w[n/8]+n/4-1
 By backward substitution
 W[n]=2(2w(n/4)+n/2-1)+n-1
 =22
w(n/4)+n-2+n-1
 =22
(2w(n/8)+n/4-1)+n-2+n-1
 =23
w[n/8]+n-22
+n-2+n-1
11Instructor: Sadia Arshid, DCS &SE
 By generalizing equation
 =2i
w[n/2i
]+in-2i-1
-2i-2
-…..-20
 =2i
w[n/2i
]+in-(2i
-1)
 By taking n=2i
 =nw[n/n]+nlgn-(n-1)
 =nlgn-(n-1)єO(nlgn)
12Instructor: Sadia Arshid, DCS &SE
Problem with Merge SortProblem with Merge Sort
In-place sorting ?
Space Complexity
13Instructor: Sadia Arshid, DCS &SE
Computation TreeComputation Tree
108 56 1214 89 3466
108 56 1466 1289 34
10866 56 14 1289 34
66 108 56 14 89 12
N = 7
lg 7  = 3
Tree Depth = 3
34
14Instructor: Sadia Arshid, DCS &SE
at each level total number of items are n
and total recursive calls are lg n(depth of
tree)
so total space complexity is nlgn
15Instructor: Sadia Arshid, DCS &SE
Other version of MERGEOther version of MERGE
SORTSORT
procedure MergeSort2(low,high,n,s)
if low<high
mid=(low+high)/2
mergesort2(low,mid)
mergesort2(mid+1,high)
merge2(low,mid,high]
16Instructor: Sadia Arshid, DCS &SE
procedure merge2(low,mid,high)
i=low,j=mid,h=low
while h<=mid and j<=high
if s[h]<s[j]
u[i]=s[h], h=h+1
else u[i]=s[j], j=j+1
i=i+1
if i>h
copy s[h] through s[mid] to u[i] to u[high]
else
copy s[j] through s[high] to u[i] to u[high]
17Instructor: Sadia Arshid, DCS &SE
time complexity???
space complexity???
18Instructor: Sadia Arshid, DCS &SE

More Related Content

What's hot

Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingzukun
 
Definite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by PartsDefinite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by Parts
Lakshmikanta Satapathy
 
Dm ha 2
Dm ha 2Dm ha 2
Dm ha 2
IIUM
 
Comuter graphics bresenhams line drawing algorithm
Comuter graphics bresenhams line drawing algorithmComuter graphics bresenhams line drawing algorithm
Comuter graphics bresenhams line drawing algorithm
Rachana Marathe
 
Indefinite Integrals QA 21
Indefinite Integrals QA 21Indefinite Integrals QA 21
Indefinite Integrals QA 21
Lakshmikanta Satapathy
 
Matrix
Matrix  Matrix
Matrix
JosephinBoddu
 
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
Moses Boudourides
 
Presentation4
Presentation4Presentation4
Presentation4Jorge707r
 
K-means Clustering || Data Mining
K-means Clustering || Data MiningK-means Clustering || Data Mining
K-means Clustering || Data Mining
Iffat Firozy
 
Gaussian elimination
Gaussian eliminationGaussian elimination
Gaussian elimination
Awais Qureshi
 
Intigrations
IntigrationsIntigrations
Intigrations
Parti Kazim
 
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
ssusere0a682
 
Comuter graphics dda algorithm
Comuter graphics dda algorithm Comuter graphics dda algorithm
Comuter graphics dda algorithm
Rachana Marathe
 
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFULLADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
Fransiskeran
 
Numerical analysis stationary variables
Numerical analysis  stationary variablesNumerical analysis  stationary variables
Numerical analysis stationary variables
SHAMJITH KM
 
Indefinite Integrals 12
Indefinite Integrals 12Indefinite Integrals 12
Indefinite Integrals 12
Lakshmikanta Satapathy
 

What's hot (16)

Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
 
Definite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by PartsDefinite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by Parts
 
Dm ha 2
Dm ha 2Dm ha 2
Dm ha 2
 
Comuter graphics bresenhams line drawing algorithm
Comuter graphics bresenhams line drawing algorithmComuter graphics bresenhams line drawing algorithm
Comuter graphics bresenhams line drawing algorithm
 
Indefinite Integrals QA 21
Indefinite Integrals QA 21Indefinite Integrals QA 21
Indefinite Integrals QA 21
 
Matrix
Matrix  Matrix
Matrix
 
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
Boudourides & Lenis, Distribution of Groups of Vertices Across Multilayer Net...
 
Presentation4
Presentation4Presentation4
Presentation4
 
K-means Clustering || Data Mining
K-means Clustering || Data MiningK-means Clustering || Data Mining
K-means Clustering || Data Mining
 
Gaussian elimination
Gaussian eliminationGaussian elimination
Gaussian elimination
 
Intigrations
IntigrationsIntigrations
Intigrations
 
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
ゲーム理論NEXT コア第4回(最終回) -平衡ゲームとコア-
 
Comuter graphics dda algorithm
Comuter graphics dda algorithm Comuter graphics dda algorithm
Comuter graphics dda algorithm
 
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFULLADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
LADDER AND SUBDIVISION OF LADDER GRAPHS WITH PENDANT EDGES ARE ODD GRACEFUL
 
Numerical analysis stationary variables
Numerical analysis  stationary variablesNumerical analysis  stationary variables
Numerical analysis stationary variables
 
Indefinite Integrals 12
Indefinite Integrals 12Indefinite Integrals 12
Indefinite Integrals 12
 

Viewers also liked

Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Muhammad Sarfraz
 
Merge sort
Merge sortMerge sort
Merge sort
Nicholas Case
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Merge sort
Merge sortMerge sort
Merge sort
Rojin Khadka
 
Merge sort
Merge sortMerge sort
Merge sort
Srikrishnan Suresh
 
Merge sort
Merge sortMerge sort
Merge sort
Chusnul Khotimah
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sort
smita gupta
 
Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained
Mohit Tare
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
Yoshi Watanabe
 
Presentation-Merge Sort
Presentation-Merge SortPresentation-Merge Sort
Presentation-Merge Sort
Md Showrov Ahmed
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
yazad dumasia
 
Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 

Viewers also liked (17)

Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Merge sort
Merge sortMerge sort
Merge sort
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Merge sort
Merge sortMerge sort
Merge sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
MSc_thesis
MSc_thesisMSc_thesis
MSc_thesis
 
Merge sort
Merge sortMerge sort
Merge sort
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sort
 
Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 
Presentation-Merge Sort
Presentation-Merge SortPresentation-Merge Sort
Presentation-Merge Sort
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Mergesort
MergesortMergesort
Mergesort
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
 
Merge sort
Merge sortMerge sort
Merge sort
 

Similar to 05 dc1

Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
B.Kirron Reddi
 
dynamic-programming
dynamic-programmingdynamic-programming
dynamic-programming
MuhammadSheraz836877
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15
Hira Gul
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
smruti sarangi
 
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
DarioVelo1
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
Pramit Kumar
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
aj ahmed
 
Programming workshop
Programming workshopProgramming workshop
Programming workshop
Sandeep Joshi
 
UNIT-II.pptx
UNIT-II.pptxUNIT-II.pptx
UNIT-II.pptx
JyoReddy9
 
Merge Sort
Merge SortMerge Sort
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
Practical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient ApportionmentPractical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient Apportionment
Raphael Reitzig
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
Matlab Assignment Experts
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
giridaroori
 
Graphical method
Graphical methodGraphical method
Graphical method
Vipul Zanzrukiya
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Seongwon Hwang
 

Similar to 05 dc1 (20)

Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
dynamic-programming
dynamic-programmingdynamic-programming
dynamic-programming
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
02_Gffdvxvvxzxzczcczzczcczczczxvxvxvds2.ppt
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
Programming workshop
Programming workshopProgramming workshop
Programming workshop
 
UNIT-II.pptx
UNIT-II.pptxUNIT-II.pptx
UNIT-II.pptx
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Practical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient ApportionmentPractical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient Apportionment
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Graphical method
Graphical methodGraphical method
Graphical method
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in Theano
 

More from Hira Gul

Final iwvc
Final iwvcFinal iwvc
Final iwvc
Hira Gul
 
Oerating system project
Oerating system projectOerating system project
Oerating system project
Hira Gul
 
project Judaism iwvc presentation
project Judaism iwvc presentation project Judaism iwvc presentation
project Judaism iwvc presentation
Hira Gul
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
Hira Gul
 
07 dc3
07 dc307 dc3
07 dc3
Hira Gul
 
06 dc2
06 dc206 dc2
06 dc2
Hira Gul
 
04 brute force
04 brute force04 brute force
04 brute force
Hira Gul
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
Hira Gul
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
Hira Gul
 
01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015
Hira Gul
 

More from Hira Gul (11)

Final iwvc
Final iwvcFinal iwvc
Final iwvc
 
Oerating system project
Oerating system projectOerating system project
Oerating system project
 
project Judaism iwvc presentation
project Judaism iwvc presentation project Judaism iwvc presentation
project Judaism iwvc presentation
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
 
07 dc3
07 dc307 dc3
07 dc3
 
06 dc2
06 dc206 dc2
06 dc2
 
04 brute force
04 brute force04 brute force
04 brute force
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
 
03 dc
03 dc03 dc
03 dc
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015
 

Recently uploaded

Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 

05 dc1

  • 1. Analysis of AlgorithmsAnalysis of Algorithms Divide and Conquer Approach 1Instructor: Sadia Arshid, DCS &SE
  • 2.  Divide the problems into a number of sub problems.  Conquer the sub problems by solving them recursively. If the sub-problem sizes are small enough, just solve the problems in a straight forward manner.  Combine the solutions to the sub problems into the solution for the original problem. Divide and Conquer ApproachDivide and Conquer Approach 2Instructor: Sadia Arshid, DCS &SE
  • 3. Divide-and-ConquerDivide-and-Conquer AlgorithmsAlgorithms  An algorithm design – merge sort – maxmin – quick sort – Matrix multiplication  A larger problem is broken up into smaller problems, the smaller problems are recursively, and the results are merged together again 3Instructor: Sadia Arshid, DCS &SE
  • 4. Divide-and-ConquerDivide-and-Conquer AlgorithmsAlgorithms More formally, we will consider only those algorithms which: – divide a problem into sub-problems, each approximately of size n/b – in all cases we have seen, the whole was divided into b equal sub-problems – solve those sub-problems recursively – combine the solutions to the sub-problems to get a solution to the overall problem 4Instructor: Sadia Arshid, DCS &SE
  • 5. MERGE SORTMERGE SORT Graphically, merge sort is represented as follows: Once we have sorted the shortest lists, then we merge then back together again into a sorted list 5Instructor: Sadia Arshid, DCS &SE
  • 6.  Divide the n element sequence to be sorted into two subsequences of n/2 elements each.  Conquer: Sort the two subsequences to produce the sorted answer.  Combine: Merge the two sorted sub sequences to produce the sorted answer. Merge SortMerge Sort 6Instructor: Sadia Arshid, DCS &SE
  • 7. Merge Sort AlgorithmMerge Sort Algorithm procedure MergeSort(n,s) h=n/2, m=n-h u=array[1..h], v=array[m..n] if n>1 copy s[1] through s[h] to u copy s[h+1] through s[n] to v mergesort(h,u) mergesort(m,v) merge(h,m,u,v,s] 7Instructor: Sadia Arshid, DCS &SE
  • 8. procedure merge(h,m,u,v,s) i=1,j=1,k=1 while i<=h and j<=m if u[i]<v[j] s[k]=u[i], i=i+1 else s[k]=v[j],j=j+1 k=k+1 if i>h copy v[j] through v[m] to s[k] through s[h+m] else copy u[i] through u[h] to s[k] through s[h+m] 8Instructor: Sadia Arshid, DCS &SE
  • 9. Merge SortMerge Sort Base Case: When the sequences to be sorted has length 1. 108 56 1214 89 3466Unsorted 108 56 1466 Divide 10866 Divide 66 Divide 66 BCase 66 Merge 108 Divide 108 BCase 108 Merge 66 108 Merge 56 14 Divide 56 Divide 56 BCase 56 Merge 14 Divide 14 BCase 14 Merge 14 56 Merge 56 66 10814 Merge 1289 34 Divide 1289 Divide 89 Divide 89 BCase 89 Merge 12 Divide 12 BCase 12 Merge 8912 Merge 34 Divide 34 BCase 34 Merge 3412 89 Merge 14 34 8956 66 10812Sorted 9Instructor: Sadia Arshid, DCS &SE
  • 10. Merge Sort AnalysisMerge Sort Analysis  T(n)=T[h]+T[m]+complexity of merge  Complexity of merge: worst case, h+m-1  Suppose n is a power of two, so that we always split into even halves. – h=n/2, m=n-n/2=n/2 – w(n)=w[n/2]+w[n/2]+n-1  For n = 1 the time to merge sort is1 otherwise  The time to merge sort n numbers is equal to the time to do two recursive merge sorts of size n/2, plus the time to merge, which is linear.  Solve this recurrence to find out running time. 10Instructor: Sadia Arshid, DCS &SE
  • 11. w(1) = 0 w(n) = 2w(n/2) + n-1  W[n]=2w[n/2]+n-1  W[n/2]=2w[n/4]+n/2-1  W[n/4]=2w[n/8]+n/4-1  By backward substitution  W[n]=2(2w(n/4)+n/2-1)+n-1  =22 w(n/4)+n-2+n-1  =22 (2w(n/8)+n/4-1)+n-2+n-1  =23 w[n/8]+n-22 +n-2+n-1 11Instructor: Sadia Arshid, DCS &SE
  • 12.  By generalizing equation  =2i w[n/2i ]+in-2i-1 -2i-2 -…..-20  =2i w[n/2i ]+in-(2i -1)  By taking n=2i  =nw[n/n]+nlgn-(n-1)  =nlgn-(n-1)єO(nlgn) 12Instructor: Sadia Arshid, DCS &SE
  • 13. Problem with Merge SortProblem with Merge Sort In-place sorting ? Space Complexity 13Instructor: Sadia Arshid, DCS &SE
  • 14. Computation TreeComputation Tree 108 56 1214 89 3466 108 56 1466 1289 34 10866 56 14 1289 34 66 108 56 14 89 12 N = 7 lg 7  = 3 Tree Depth = 3 34 14Instructor: Sadia Arshid, DCS &SE
  • 15. at each level total number of items are n and total recursive calls are lg n(depth of tree) so total space complexity is nlgn 15Instructor: Sadia Arshid, DCS &SE
  • 16. Other version of MERGEOther version of MERGE SORTSORT procedure MergeSort2(low,high,n,s) if low<high mid=(low+high)/2 mergesort2(low,mid) mergesort2(mid+1,high) merge2(low,mid,high] 16Instructor: Sadia Arshid, DCS &SE
  • 17. procedure merge2(low,mid,high) i=low,j=mid,h=low while h<=mid and j<=high if s[h]<s[j] u[i]=s[h], h=h+1 else u[i]=s[j], j=j+1 i=i+1 if i>h copy s[h] through s[mid] to u[i] to u[high] else copy s[j] through s[high] to u[i] to u[high] 17Instructor: Sadia Arshid, DCS &SE