Topics of Discussion: Merging of Sorted Arrays. 2. Merge Sort. 3. Quick Sort
Topics of Discussion: Merging of Sorted Arrays. 2. Merge Sort. 3. Quick Sort
5/1/2012
PSD_Merge_Quick_Sort
5/1/2012
PSD_Merge_Quick_Sort
5/1/2012
PSD_Merge_Quick_Sort
5/1/2012
PSD_Merge_Quick_Sort
5/1/2012
PSD_Merge_Quick_Sort
11
5/1/2012
PSD_Merge_Quick_Sort
12
5/1/2012
PSD_Merge_Quick_Sort
13
5/1/2012
PSD_Merge_Quick_Sort
14
5/1/2012
PSD_Merge_Quick_Sort
15
5/1/2012
PSD_Merge_Quick_Sort
16
5/1/2012
PSD_Merge_Quick_Sort
17
5/1/2012
PSD_Merge_Quick_Sort
18
5/1/2012
20
Partition : Algorithm
Partition ( Array Type A , Integer Low_Idx, Integer High_Idx ) Pivot A [ Low_Idx ] ; Left_Idx Low_Idx + 1; Right_Idx High_Idx -1; WHILE TRUE do do Right_Idx ( j ) Right_Idx 1 while A [ Right_Idx (j) ].Key > Pivot.Key /* Move TOWARDS Left till the Array Element. Key > Pivot.Key*/ do Left_Idx ( i ) Left_Idx + 1 while A [ Left_Idx (i) ].Key <= Pivot.Key /* Move TOWARDS Right till Array Element. Key <= Pivot.Key */ /* The Above Loop Conditions ARE Violated i.e. Either A [ Right_Idx (j) ] .Key <= Pivot .Key OR A [ Left_Idx (i) ]. Key > Pivot.Key. */ IF (Left_Idx (i) < Right _Idx (j) ) THEN /* The Two Running Indices have NOT Crossed */ SWAP (A [Left_Idx (i) ] , A [ Right_Idx (j) ] ); /* Exchange Out of Order Elements */ ELSE /* The Two Running Indices Have Crossed */ RETURN (Right_Idx (j) ); end WHILE
5/1/2012
PSD_Merge_Quick_Sort
21
if (Low_Idx < High_Idx) THEN Part_Idx Partition ( A, Low_Idx, High_Idx); Quick_Sort ( A, Low_Idx, Part_Idx ); Quick_Sort (A, Part_Idx+1, High_Idx);
5/1/2012
PSD_Merge_Quick_Sort
22
5/1/2012
PSD_Merge_Quick_Sort
23
5/1/2012
PSD_Merge_Quick_Sort
24
5/1/2012
PSD_Merge_Quick_Sort
25
5/1/2012
PSD_Merge_Quick_Sort
26
5/1/2012
PSD_Merge_Quick_Sort
27
5/1/2012
PSD_Merge_Quick_Sort
28
5/1/2012
PSD_Merge_Quick_Sort
29
5/1/2012
PSD_Merge_Quick_Sort
30
5/1/2012
PSD_Merge_Quick_Sort
31
5/1/2012
PSD_Merge_Quick_Sort
32