SlideShare a Scribd company logo
1 of 24
Admission in India 2015 
By: 
admission.edhole.com
Comp 122, Spring 2004 
Divide and Conquer 
(Merge Sort) 
admission.edhole.com
Divide and Conquer 
 Recursive in structure 
 Divide the problem into sub-problems that are 
similar to the original but smaller in size 
 Conquer the sub-problems by solving them 
recursively. If they are small enough, just solve 
them in a straightforward manner. 
 Combine the solutions to create a solution to 
the original problem 
admission.edhole.com 
- 3 Comp 122
An Example: Merge Sort 
Sorting Problem: Sort a sequence of n elements into 
non-decreasing order. 
 Divide: Divide the n-element sequence to be 
sorted into two subsequences of n/2 elements each 
 Conquer: Sort the two subsequences recursively 
using merge sort. 
 Combine: Merge the two sorted subsequences to 
produce the sorted answer. 
admission.edhole.com 
- 4 Comp 122
Merge Sort – Example 
18 26 32 6 43 15 9 1 
43 15 9 1 
18 26 32 6 
32 6 
18 26 
43 15 
15 
9 1 
18 26 
32 
6 
43 
9 
1 
1 6 9 15 18 26 32 43 
6 26 32 1 9 15 43 
18 26 6 32 
15 43 1 9 
18 6 
43 9 - 6 Comp 122 
18 18 26 
32 
6 
43 
15 
9 
1 
26 32 15 1 
Original Sequence Sorted Sequence 
admission.edhole.com
Merge-Sort (A, p, r) 
INPUT: a sequence of n numbers stored in array A 
OUTPUT: an ordered sequence of n numbers 
MergeSort (A, p, r) // sort A[p..r] by divide & conquer 
1 if p < r 
2 then q ¬ ë(p+r)/2û 
3 MergeSort (A, p, q) 
4 MergeSort (A, q+1, r) 
5 Merge (A, p, q, r) // merges A[p..q] with A[q+1..r] 
Initial Call: MergeSort(A, 1, n) 
admission.edhole.com 
- 7 Comp 122
Procedure Merge 
Merge(A, p, q, r) 
1 n1 ¬ q – p + 1 
2 n2 ¬ r – q 
3 for i ¬ 1 to n1 
4 do L[i] ¬ A[p + i – 1] 
5 for j ¬ 1 to n2 
6 do R[j] ¬ A[q + j] 
7 L[n1+1] ¬ ¥ 
8 R[n2+1] ¬ ¥ 
9 i ¬ 1 
10 j ¬ 1 
11 for k ¬p to r 
12 do if L[i] £ R[j] 
13 then A[k] ¬ L[i] 
14 i ¬ i + 1 
15 else A[k] ¬ R[j] 
16 j ¬ j + 1 
- 8 Comp 122 
Input: Array containing 
sorted subarrays A[p..q] 
and A[q+1..r]. 
Output: Merged sorted 
subarray in A[p..r]. 
Sentinels, to avoid having to 
check if either subarray is 
fully copied at each step. 
admission.edhole.com
Merge – Example 
A … 6 1 8 6 26 8 32 9 26 1 32 9 42 43 
… 
k k k k k k k 
L R 
- 9 Comp 122 
j 
k 
k 
6 8 26 32 1 9 42 43 
i i i i 
¥ ¥ 
i j j j j 
admission.edhole.com
Correctness of Merge 
Merge(A, p, q, r) 
1 n1 ¬ q – p + 1 
2 n2 ¬ r – q 
3 for i ¬ 1 to n1 
4 do L[i] ¬ A[p + i – 1] 
5 for j ¬ 1 to n2 
6 do R[j] ¬ A[q + j] 
7 L[n1+1] ¬ ¥ 
8 R[n2+1] ¬ ¥ 
9 i ¬ 1 
10 j ¬ 1 
11 for k ¬p to r 
12 do if L[i] £ R[j] 
13 then A[k] ¬ L[i] 
14 i ¬ i + 1 
15 else A[k] ¬ R[j] 
16 j ¬ j + 1 
Loop Invariant for the for loop 
At the start of each iteration of the 
for loop: 
- 10 Comp 122 
Subarray A[p..k – 1] 
contains the k – p smallest elements 
of L and R in sorted order. 
L[i] and R[j] are the smallest elements of 
L and R that have not been copied back into 
A. 
Initialization: 
Before the first iteration: 
•A[p..k – 1] is empty. 
•i = j = 1. 
•L[1] and R[1] are the smallest 
elements of L and R not copied to A. 
admission.edhole.com
Correctness of Merge 
Merge(A, p, q, r) 
1 n1 ¬ q – p + 1 
2 n2 ¬ r – q 
3 for i ¬ 1 to n1 
4 do L[i] ¬ A[p + i – 1] 
5 for j ¬ 1 to n2 
6 do R[j] ¬ A[q + j] 
7 L[n1+1] ¬ ¥ 
8 R[n2+1] ¬ ¥ 
9 i ¬ 1 
10 j ¬ 1 
11 for k ¬p to r 
12 do if L[i] £ R[j] 
13 then A[k] ¬ L[i] 
14 i ¬ i + 1 
15 else A[k] ¬ R[j] 
16 j ¬ j + 1 
Maintenance: 
Case 1: L[i] £ R[j] 
•By LI, A contains p – k smallest elements 
of L and R in sorted order. 
•By LI, L[i] and R[j] are the smallest 
elements of L and R not yet copied into A. 
•Line 13 results in A containing p – k + 1 
smallest elements (again in sorted order). 
Incrementing i and k reestablishes the LI 
for the next iteration. 
Similarly for L[i] > R[j]. 
Termination: 
•On termination, k = r + 1. 
•By LI, A contains r – p + 1 smallest 
elements of L and R in sorted order. 
•L and R together contain r – p + 3 elements. 
All but the two sentinels have been copied 
back into A. admission.edhole.com 
- 11 Comp 122
Analysis of Merge Sort 
 Running time T(n) of Merge Sort: 
 Divide: computing the middle takes Q(1) 
 Conquer: solving 2 subproblems takes 2T(n/2) 
 Combine: merging n elements takes Q(n) 
 Total: 
T(n) = Q(1) if n = 1 
T(n) = 2T(n/2) + Q(n) if n > 1 
Þ T(n) = Q(n lg n) (CLRS, Chapter 4) 
admission.edhole.com 
- 12 Comp 122
Comp 122, Spring 2004 
RReeccuurrrreenncceess –– II 
admission.edhole.com
Recurrence Relations 
 Equation or an inequality that characterizes a 
function by its values on smaller inputs. 
 Solution Methods (Chapter 4) 
 Substitution Method. 
 Recursion-tree Method. 
 Master Method. 
 Recurrence relations arise when we analyze the 
running time of iterative or recursive algorithms. 
 Ex: Divide and Conquer. 
T(n) = Q(1) if n £ c 
T(n) = a T(n/b) + D(n) + C(n) otherwise 
admission.edhole.com 
- 14 Comp 122
Substitution Method 
 Guess the form of the solution, then 
use mathematical induction to show it correct. 
 Substitute guessed answer for the function when the 
inductive hypothesis is applied to smaller values – 
hence, the name. 
 Works well when the solution is easy to guess. 
 No general way to guess the correct solution. 
admission.edhole.com 
- 15 Comp 122
Example – Exact Function 
Recurrence: T(n) = 1 if n = 1 
T(n) = 2T(n/2) + n if n > 1 
Guess: T(n) = n lg n + n. 
Induction: 
•Basis: n = 1 Þ n lgn + n = 1 = T(n). 
•Hypothesis: T(k) = k lg k + k for all k < n. 
•Inductive Step: T(n) = 2 T(n/2) + n 
= 2 ((n/2)lg(n/2) + (n/2)) + n 
= n (lg(n/2)) + 2n 
= n lg n – n + 2n 
= n lg n + n 
admission.edhole.com 
- 16 Comp 122
Recursion-tree Method 
 Making a good guess is sometimes difficult with 
the substitution method. 
 Use recursion trees to devise good guesses. 
 Recursion Trees 
 Show successive expansions of recurrences using 
trees. 
 Keep track of the time spent on the subproblems of a 
divide and conquer algorithm. 
 Help organize the algebraic bookkeeping necessary 
to solve a recurrence. 
admission.edhole.com 
- 17 Comp 122
Recursion Tree – Example 
 Running time of Merge Sort: 
T(n) = Q(1) if n = 1 
T(n) = 2T(n/2) + Q(n) if n > 1 
 Rewrite the recurrence as 
T(n) = c if n = 1 
T(n) = 2T(n/2) + cn if n > 1 
c > 0: Running time for the base case and 
time per array element for the divide and 
combine steps. 
admission.edhole.com 
- 18 Comp 122
Recursion Tree for Merge Sort 
For the original problem, 
we have a cost of cn, 
plus two subproblems 
each of size (n/2) and 
running time T(n/2). 
cn 
Cost of divide and 
merge. 
T(n/2) T(n/2) 
Each of the size n/2 problems 
has a cost of cn/2 plus two 
subproblems, each costing 
T(n/4). cn 
- 19 Comp 122 
cn/2 cn/2 
T(n/4) T(n/4) T(n/4) T(n/4) 
Cost of sorting 
subproblems. 
admission.edhole.com
Recursion Tree for Merge Sort 
Continue expanding until the problem size reduces to 1. 
cn 
cn/2 cn/2 
cn/4 cn/4 cn/4 cn/4 
c c c c c c 
lg n 
- 20 Comp 122 
cn 
cn 
cn 
cn 
admission.edhole.com Total : cnlgn+cn
Recursion Tree for Merge Sort 
Continue expanding until the problem size reduces to 1. 
cn 
cn/2 cn/2 
cn/4 cn/4 cn/4 cn/4 
c c c c c c 
•Each level has total cost cn. 
•Each time we go down one level, 
the number of subproblems doubles, 
but the cost per subproblem halves 
Þ cost per level remains the same. 
•There are lg n + 1 levels, height is 
lg n. (Assuming n is a power of 2.) 
•Can be proved by induction. 
•Total cost = sum of costs at each 
level = (lg n + 1)cn = cnlgn + cn = 
Q(n lgn). 
admission.edhole.com 
- 21 Comp 122
Other Examples 
 Use the recursion-tree method to determine a 
guess for the recurrences 
 T(n) = 3T(ën/4û) + Q(n2). 
 T(n) = T(n/3) + T(2n/3) + O(n). 
admission.edhole.com 
- 22 Comp 122
Recursion Trees – Caution Note 
 Recursion trees only generate guesses. 
 Verify guesses using substitution method. 
 A small amount of “sloppiness” can be 
tolerated. Why? 
 If careful when drawing out a recursion tree and 
summing the costs, can be used as direct proof. 
admission.edhole.com 
- 23 Comp 122
The Master Method 
 Based on the Master theorem. 
 “Cookbook” approach for solving recurrences 
of the form 
T(n) = aT(n/b) + f(n) 
• a ³ 1, b > 1 are constants. 
• f(n) is asymptotically positive. 
• n/b may not be an integer, but we ignore floors and 
ceilings. Why? 
 Requires memorization of three cases. 
admission.edhole.com 
- 24 Comp 122
The Master Theorem 
Theorem 4.1 
Let a ³ 1 and b > 1 be constants, let f(n) be a function, and 
Theorem 4.1 
Let a ³ 1 and b > 1 be constants, let f(n) be a function, and 
Let T(n) be defined on nonnegative integers by the recurrence 
T(n) = aT(n/b) + f(n), where we can replace n/b by ën/bû or én/bù. 
T(n) can be bounded asymptotically in three cases: 
Let T(n) be defined on nonnegative integers by the recurrence 
T(n) = aT(n/b) + f(n), where we can replace n/b by ën/bû or én/bù. 
T(n) can be bounded asymptotically in three cases: 
1. If f(n) = O(nlogba–e) for some constant e > 0, then T(n) = Q(nlogba). 
2. If f(n) = Q(nlogba), then T(n) = Q(nlogbalg n). 
3. If f(n) = W(nlogba+e) for some constant e > 0, 
1. If f(n) = O(nlogba–e) for some constant e > 0, then T(n) = Q(nlogba). 
2. If f(n) = Q(nlogba), then T(n) = Q(nlogbalg n). 
3. If f(n) = W(nlogba+e) for some constant e > 0, 
and if, for some constant c < 1 and all sufficiently large n, 
we have a·f(n/b) £ c f(n), then T(n) = Q(f(n)). 
and if, for some constant c < 1 and all sufficiently large n, 
we have a·f(n/b) £ c f(n), then T(n) = Q(f(n)). 
We’ll return to recurrences as we need them… 
admission.edhole.com 
- 25 Comp 122

More Related Content

What's hot

What's hot (19)

Heuristics for counterexamples to the Agrawal Conjecture
Heuristics for counterexamples to the Agrawal ConjectureHeuristics for counterexamples to the Agrawal Conjecture
Heuristics for counterexamples to the Agrawal Conjecture
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Thesis 6
Thesis 6Thesis 6
Thesis 6
 
Math induction
Math inductionMath induction
Math induction
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
DSP System Assignment Help
DSP System Assignment HelpDSP System Assignment Help
DSP System Assignment Help
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
balakrishnan2004
balakrishnan2004balakrishnan2004
balakrishnan2004
 
Unit 3
Unit 3Unit 3
Unit 3
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 

Similar to Admission in india 2015

Top school in noida
Top school in noidaTop school in noida
Top school in noidaEdhole.com
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxGadaFarhan
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docxeugeniadean34240
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
lecture 15
lecture 15lecture 15
lecture 15sajinsc
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesjayavignesh86
 
Introduction
IntroductionIntroduction
Introductionpilavare
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probabilitybryan111472
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxDeepakM509554
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortManishPrajapati78
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMAlpana Ingale
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfShiwani Gupta
 

Similar to Admission in india 2015 (20)

Top school in noida
Top school in noidaTop school in noida
Top school in noida
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Mergesort
MergesortMergesort
Mergesort
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
lecture 15
lecture 15lecture 15
lecture 15
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
 
Introduction
IntroductionIntroduction
Introduction
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
2.pptx
2.pptx2.pptx
2.pptx
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEM
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
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
 

More from Edhole.com

Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarkaEdhole.com
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarkaEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarkaEdhole.com
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarkaEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbaiEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 

More from Edhole.com (20)

Ca in patna
Ca in patnaCa in patna
Ca in patna
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarka
 
Ca in dwarka
Ca in dwarkaCa in dwarka
Ca in dwarka
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarka
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Ca in patna
Ca in patnaCa in patna
Ca in patna
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarka
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarka
 
Ca in dwarka
Ca in dwarkaCa in dwarka
Ca in dwarka
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbai
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Admission in india 2015

  • 1. Admission in India 2015 By: admission.edhole.com
  • 2. Comp 122, Spring 2004 Divide and Conquer (Merge Sort) admission.edhole.com
  • 3. Divide and Conquer  Recursive in structure  Divide the problem into sub-problems that are similar to the original but smaller in size  Conquer the sub-problems by solving them recursively. If they are small enough, just solve them in a straightforward manner.  Combine the solutions to create a solution to the original problem admission.edhole.com - 3 Comp 122
  • 4. An Example: Merge Sort Sorting Problem: Sort a sequence of n elements into non-decreasing order.  Divide: Divide the n-element sequence to be sorted into two subsequences of n/2 elements each  Conquer: Sort the two subsequences recursively using merge sort.  Combine: Merge the two sorted subsequences to produce the sorted answer. admission.edhole.com - 4 Comp 122
  • 5. Merge Sort – Example 18 26 32 6 43 15 9 1 43 15 9 1 18 26 32 6 32 6 18 26 43 15 15 9 1 18 26 32 6 43 9 1 1 6 9 15 18 26 32 43 6 26 32 1 9 15 43 18 26 6 32 15 43 1 9 18 6 43 9 - 6 Comp 122 18 18 26 32 6 43 15 9 1 26 32 15 1 Original Sequence Sorted Sequence admission.edhole.com
  • 6. Merge-Sort (A, p, r) INPUT: a sequence of n numbers stored in array A OUTPUT: an ordered sequence of n numbers MergeSort (A, p, r) // sort A[p..r] by divide & conquer 1 if p < r 2 then q ¬ ë(p+r)/2û 3 MergeSort (A, p, q) 4 MergeSort (A, q+1, r) 5 Merge (A, p, q, r) // merges A[p..q] with A[q+1..r] Initial Call: MergeSort(A, 1, n) admission.edhole.com - 7 Comp 122
  • 7. Procedure Merge Merge(A, p, q, r) 1 n1 ¬ q – p + 1 2 n2 ¬ r – q 3 for i ¬ 1 to n1 4 do L[i] ¬ A[p + i – 1] 5 for j ¬ 1 to n2 6 do R[j] ¬ A[q + j] 7 L[n1+1] ¬ ¥ 8 R[n2+1] ¬ ¥ 9 i ¬ 1 10 j ¬ 1 11 for k ¬p to r 12 do if L[i] £ R[j] 13 then A[k] ¬ L[i] 14 i ¬ i + 1 15 else A[k] ¬ R[j] 16 j ¬ j + 1 - 8 Comp 122 Input: Array containing sorted subarrays A[p..q] and A[q+1..r]. Output: Merged sorted subarray in A[p..r]. Sentinels, to avoid having to check if either subarray is fully copied at each step. admission.edhole.com
  • 8. Merge – Example A … 6 1 8 6 26 8 32 9 26 1 32 9 42 43 … k k k k k k k L R - 9 Comp 122 j k k 6 8 26 32 1 9 42 43 i i i i ¥ ¥ i j j j j admission.edhole.com
  • 9. Correctness of Merge Merge(A, p, q, r) 1 n1 ¬ q – p + 1 2 n2 ¬ r – q 3 for i ¬ 1 to n1 4 do L[i] ¬ A[p + i – 1] 5 for j ¬ 1 to n2 6 do R[j] ¬ A[q + j] 7 L[n1+1] ¬ ¥ 8 R[n2+1] ¬ ¥ 9 i ¬ 1 10 j ¬ 1 11 for k ¬p to r 12 do if L[i] £ R[j] 13 then A[k] ¬ L[i] 14 i ¬ i + 1 15 else A[k] ¬ R[j] 16 j ¬ j + 1 Loop Invariant for the for loop At the start of each iteration of the for loop: - 10 Comp 122 Subarray A[p..k – 1] contains the k – p smallest elements of L and R in sorted order. L[i] and R[j] are the smallest elements of L and R that have not been copied back into A. Initialization: Before the first iteration: •A[p..k – 1] is empty. •i = j = 1. •L[1] and R[1] are the smallest elements of L and R not copied to A. admission.edhole.com
  • 10. Correctness of Merge Merge(A, p, q, r) 1 n1 ¬ q – p + 1 2 n2 ¬ r – q 3 for i ¬ 1 to n1 4 do L[i] ¬ A[p + i – 1] 5 for j ¬ 1 to n2 6 do R[j] ¬ A[q + j] 7 L[n1+1] ¬ ¥ 8 R[n2+1] ¬ ¥ 9 i ¬ 1 10 j ¬ 1 11 for k ¬p to r 12 do if L[i] £ R[j] 13 then A[k] ¬ L[i] 14 i ¬ i + 1 15 else A[k] ¬ R[j] 16 j ¬ j + 1 Maintenance: Case 1: L[i] £ R[j] •By LI, A contains p – k smallest elements of L and R in sorted order. •By LI, L[i] and R[j] are the smallest elements of L and R not yet copied into A. •Line 13 results in A containing p – k + 1 smallest elements (again in sorted order). Incrementing i and k reestablishes the LI for the next iteration. Similarly for L[i] > R[j]. Termination: •On termination, k = r + 1. •By LI, A contains r – p + 1 smallest elements of L and R in sorted order. •L and R together contain r – p + 3 elements. All but the two sentinels have been copied back into A. admission.edhole.com - 11 Comp 122
  • 11. Analysis of Merge Sort  Running time T(n) of Merge Sort:  Divide: computing the middle takes Q(1)  Conquer: solving 2 subproblems takes 2T(n/2)  Combine: merging n elements takes Q(n)  Total: T(n) = Q(1) if n = 1 T(n) = 2T(n/2) + Q(n) if n > 1 Þ T(n) = Q(n lg n) (CLRS, Chapter 4) admission.edhole.com - 12 Comp 122
  • 12. Comp 122, Spring 2004 RReeccuurrrreenncceess –– II admission.edhole.com
  • 13. Recurrence Relations  Equation or an inequality that characterizes a function by its values on smaller inputs.  Solution Methods (Chapter 4)  Substitution Method.  Recursion-tree Method.  Master Method.  Recurrence relations arise when we analyze the running time of iterative or recursive algorithms.  Ex: Divide and Conquer. T(n) = Q(1) if n £ c T(n) = a T(n/b) + D(n) + C(n) otherwise admission.edhole.com - 14 Comp 122
  • 14. Substitution Method  Guess the form of the solution, then use mathematical induction to show it correct.  Substitute guessed answer for the function when the inductive hypothesis is applied to smaller values – hence, the name.  Works well when the solution is easy to guess.  No general way to guess the correct solution. admission.edhole.com - 15 Comp 122
  • 15. Example – Exact Function Recurrence: T(n) = 1 if n = 1 T(n) = 2T(n/2) + n if n > 1 Guess: T(n) = n lg n + n. Induction: •Basis: n = 1 Þ n lgn + n = 1 = T(n). •Hypothesis: T(k) = k lg k + k for all k < n. •Inductive Step: T(n) = 2 T(n/2) + n = 2 ((n/2)lg(n/2) + (n/2)) + n = n (lg(n/2)) + 2n = n lg n – n + 2n = n lg n + n admission.edhole.com - 16 Comp 122
  • 16. Recursion-tree Method  Making a good guess is sometimes difficult with the substitution method.  Use recursion trees to devise good guesses.  Recursion Trees  Show successive expansions of recurrences using trees.  Keep track of the time spent on the subproblems of a divide and conquer algorithm.  Help organize the algebraic bookkeeping necessary to solve a recurrence. admission.edhole.com - 17 Comp 122
  • 17. Recursion Tree – Example  Running time of Merge Sort: T(n) = Q(1) if n = 1 T(n) = 2T(n/2) + Q(n) if n > 1  Rewrite the recurrence as T(n) = c if n = 1 T(n) = 2T(n/2) + cn if n > 1 c > 0: Running time for the base case and time per array element for the divide and combine steps. admission.edhole.com - 18 Comp 122
  • 18. Recursion Tree for Merge Sort For the original problem, we have a cost of cn, plus two subproblems each of size (n/2) and running time T(n/2). cn Cost of divide and merge. T(n/2) T(n/2) Each of the size n/2 problems has a cost of cn/2 plus two subproblems, each costing T(n/4). cn - 19 Comp 122 cn/2 cn/2 T(n/4) T(n/4) T(n/4) T(n/4) Cost of sorting subproblems. admission.edhole.com
  • 19. Recursion Tree for Merge Sort Continue expanding until the problem size reduces to 1. cn cn/2 cn/2 cn/4 cn/4 cn/4 cn/4 c c c c c c lg n - 20 Comp 122 cn cn cn cn admission.edhole.com Total : cnlgn+cn
  • 20. Recursion Tree for Merge Sort Continue expanding until the problem size reduces to 1. cn cn/2 cn/2 cn/4 cn/4 cn/4 cn/4 c c c c c c •Each level has total cost cn. •Each time we go down one level, the number of subproblems doubles, but the cost per subproblem halves Þ cost per level remains the same. •There are lg n + 1 levels, height is lg n. (Assuming n is a power of 2.) •Can be proved by induction. •Total cost = sum of costs at each level = (lg n + 1)cn = cnlgn + cn = Q(n lgn). admission.edhole.com - 21 Comp 122
  • 21. Other Examples  Use the recursion-tree method to determine a guess for the recurrences  T(n) = 3T(ën/4û) + Q(n2).  T(n) = T(n/3) + T(2n/3) + O(n). admission.edhole.com - 22 Comp 122
  • 22. Recursion Trees – Caution Note  Recursion trees only generate guesses.  Verify guesses using substitution method.  A small amount of “sloppiness” can be tolerated. Why?  If careful when drawing out a recursion tree and summing the costs, can be used as direct proof. admission.edhole.com - 23 Comp 122
  • 23. The Master Method  Based on the Master theorem.  “Cookbook” approach for solving recurrences of the form T(n) = aT(n/b) + f(n) • a ³ 1, b > 1 are constants. • f(n) is asymptotically positive. • n/b may not be an integer, but we ignore floors and ceilings. Why?  Requires memorization of three cases. admission.edhole.com - 24 Comp 122
  • 24. The Master Theorem Theorem 4.1 Let a ³ 1 and b > 1 be constants, let f(n) be a function, and Theorem 4.1 Let a ³ 1 and b > 1 be constants, let f(n) be a function, and Let T(n) be defined on nonnegative integers by the recurrence T(n) = aT(n/b) + f(n), where we can replace n/b by ën/bû or én/bù. T(n) can be bounded asymptotically in three cases: Let T(n) be defined on nonnegative integers by the recurrence T(n) = aT(n/b) + f(n), where we can replace n/b by ën/bû or én/bù. T(n) can be bounded asymptotically in three cases: 1. If f(n) = O(nlogba–e) for some constant e > 0, then T(n) = Q(nlogba). 2. If f(n) = Q(nlogba), then T(n) = Q(nlogbalg n). 3. If f(n) = W(nlogba+e) for some constant e > 0, 1. If f(n) = O(nlogba–e) for some constant e > 0, then T(n) = Q(nlogba). 2. If f(n) = Q(nlogba), then T(n) = Q(nlogbalg n). 3. If f(n) = W(nlogba+e) for some constant e > 0, and if, for some constant c < 1 and all sufficiently large n, we have a·f(n/b) £ c f(n), then T(n) = Q(f(n)). and if, for some constant c < 1 and all sufficiently large n, we have a·f(n/b) £ c f(n), then T(n) = Q(f(n)). We’ll return to recurrences as we need them… admission.edhole.com - 25 Comp 122

Editor's Notes

  1. Talk about how mathematical induction works.