SlideShare a Scribd company logo
1 of 9
@OMKAR VERMA
GITM LUCKNOW
Department Of Computer Science & Engineering
Design & Analysis Of Algorithm
HoD Er. Brijesh Pandey Faculty Mr. Peeyush Kr. Pathak
1.HEAP SORT
MAX-HEAPIFY(A,i)
1. L=Left(i)
2. R=Right(i)
3. If l<= A.heap-size and A[l]>A[i]
4. Largest = l
5. Else largest = i
6. If r<= A.heap-size and A[r]>A[largest]
7. Largest = r
8. If largest ≠ i
9. Exchange A[i] with A[largest]
10. MAX-HEAPIFY(A,largest)
@OMKAR VERMA
BUILD-MAX-HEAP(A)
1. A.heap-size = A.length
2. For I = [A.length/2] downto 1
3. MAX_HEAPIFY (A,i)
2.QUICK SORT
QUICK SORT(A,p,r)
1. If p <r
2 . q=PARTITION(A,p,r)
3.QUICKSORT(A,p,q-1)
4.QUICKSORT(A,q+1,r)
Partition in Quick Sort
PARTITION (A,p,r)
1. X=A[r]
2. I=p-1
3. for j=p to r-1
4. if A[j] ≤ x
5. i=i+1
6. exchange A[i] with A[j]
7. exchange A[i+1] with A[r]
8. return i+1
3.Counting Sort
COUNTING-SORT(A,B,k)
1. let C[0……..k] be a new array
2. for i=0 to k
3. C[i] = 0
4. For j = 1 to A.length
5. C[A[j]] = C[A[j]+1] // C[i] now contains the number of elements equal to i.
6. For I = 1 to k
7. C[i] = C[i] + C[i-1]
8. //C[i] now contains the number of elements less than or equal to i.
9. For j= A.length downto 1
10. B[C[A[j]]] = A[j]
11. C[A[j]] = C[A[j]] - 1
@OMKAR VERMA
4.Radix Sort
RADIX_SORT(A,d)
1. For i=1 to d
2. Use a stable sort to sort array A on digit i.
5.Bucket Sort
BUCKET-SORT(A)
1. Let B[0. . . . . . .n-1] be a new array
2. N=A.length
3. For i=0 to n-1
4. Make B[i] an empty list
5. For i= 1 to n
6. Insert A[i] into list B[[nA[i]]]
7. For i= 0 to n-1
8. Sort list B[i] with insertion sort
9. Concatenate the lists B[0],B[1]. . . . . . . B[n-1] together in order.
ALGORITHM OF B -TREE
# B Tree Searching
B-TREE-SEARCH(x,k)
1. I=1
2. While i≤ x.n and k > x.keyi
3. i=i=i+1
4. if i ≤ x.n and k == x.keyi
5. return (x,i)
6. elseif x.leaf
7. return NIL
8. else DISK-READ(x,Ci)
9. return B-TREE-SEARCH(x.Ci,k)
@OMKAR VERMA
# B Tree Creating
B-TREE-CREATE(T)
1. X=ALLOCATE-NODE()
2. X.leaf = TRUE
3. X.n = 0
4. DISK-WRITE(x)
5. T.root = x
# B Tree Spliting
B-TREE-SPLIT-CHILD(x,i)
1. Z=ALLOCATE-NODE()
2. Y=x.Ci
3. Z.leaf=y.leaf
4. Z.n=t-1
5. For j=1 to t-1
6. Z.key(j) = y.key(j+1)
7. If not y.leaf
8. For j = 1 to t
9. Z.C(j)= y.C(j+t)
10. Y.n=t-1
11. For j=x.n+1 downto i+1
12. X.C(j+1)=x.C(j)
13. X.C(i+1)=z
14. For j=x.n downto i
15. X.key(j+1)=x.key(j)
16. X.key(i)=y.key(t)
17. X.n=x.n+1
18. DISK-WRITE(y)
19. DISK-WRITE(z)
20. DISK-WRITE(x)
# B Tree Insertion
B-TREE-INSERT(T,k)
1. R=T.root
2. If r.n==2t-1
3. S=ALLOCATE-NODE()
4. T.root=s
5. S.leaf=FALSE
6. S.n=0
7. S.C1=r
8. B-TREE-SPLIT-CHILD(s,1)
9. B-TREE-INSERT-NONFULL(s,k)
@OMKAR VERMA
10. Else B-TREE-INSERT-NONFULL(r,k)
ALGORITHM OF FIBONACCI HEAP
# Inserting A Node
FIB-HEAP-INSERT(H,x)
1. X.degree = 0
2. X.p = NIL
3. X.child = NIL
4. X.mark = FALSE
5. If H.min==NIL
6. Create a root list for H containing just x
7. H.min==x
8. Else insert x into H’s root list
9. If x.key < H.min.key
10. H.min=x
11. H.n = H.n+1
# Uniting Two Fibonacci Heap
FIB-HEAP-UNION(H1,H2)
1. H=MAKE-FIB-HEAP()
2. H.min=H1.min
3. Concatenate the root list of H2 with the root list of H
4. If(H1.min==NIL) or (H2.min≠NIL and H2.min.key<H1.min.key)
5. H.min=H2.min
6. H.n=H1.n+H2.n
7. Return H
#Extacting The Minimum Node
FIB-HEAP-EXTRACT-MIN(H)
1. Z=H.min
2. If z≠ NIL
3. For each child x of z
4. Add x to the root list of H
5. X.p=NIL
6. Remove z from the root list of H
7. If z == z.right
8. H.min= NIL
@OMKAR VERMA
9. Else H.min = z.right
10. CONSOLIDATE(H)
11. H.n = H.n-1
12. Return z
#CONSOLIDATE
1. Let A[0. . . . . . . . D(H.n)be a new array]
2. For i= 0 to D(H.n)
3. A[i]=NIL
4. For each node w in the root list of H
5. X=w
6. d= x.degree
7. while A[d] ≠ NIL
8. y=A[d] //another node with the same degree as x
9. if x.key > y.key
10. exchange x with y
11. FIB-HEAP-LINK(H,y,x)
12. A[d] = NIL
13. d = d+1
14. A[d] = x
15. H.min = NIL
16. For i=0 to D(H.n)
17. If A[i]≠ NIL
18. If H.min==NIL
19. Create a root list for H containing just A[i]
20. H.min = A[i]
21. Else insert A[i] into H’s root list
22. If A[i].key<H.min.key
23. H.min = A[i]
FIB-HEAP-LINK(H,y,x)
1. Remove y from the root list of H
2. Make y a child of x,incrementing x.degree
3. Y.mark=FALSE
#Decreasing a key in Fibonacci Heap
FIB-HEAP-DECREASE-KEY(H,x,k)
1. If k> x.key
2. Error “new key is greater than current key”
3. X.key=k
@OMKAR VERMA
4. Y=x.p
5. If ≠NIL and x.key<y.key
6. CUT(H,x,y)
7. CASCADING-CUT(H,y)
8. If x.key<H.min.key
9. H.min=x
# CUT(H,x,y)
1. Remove x from the child list of y,decrementing y.degree
2. Add x to the root list of H
3. X.p= NIL
4. X.mark=FALSE
# CASCADING-CUT(H,y)
1. Z=y.p
2. If z≠ NIL
3. If y.mark==FALSE
4. Y.mark = TRUE
5. Else CUT(H,y,z)
6. CASCADING-CUT(H,z)
# Deleting a node in Fibonacci Heap
FIB-HEAP-DELETE(H,x)
1. FIB-HEAP-DECREASE-KEY(H,x,-∞)
2. FIB-HEAP-EXTRACT-MIN(H)
ALGORITHM OF MINIMUM SPANNING TREE
#Kruskal’s Algorithm
MST-KRUSKAL(G,w)
1. A=ϕ
2. For each vertex v € G,V
3. MAKE-SET(v)
4. Sort the edges of G.E into nondecreasing order by weight w
5. For each edge (u,v) € G.E,taken in nondecreasing order by weight
6. If FIND-SET(u) ≠ FIND-SET(v)
7. A = A Ự {(u,v)}
@OMKAR VERMA
8. Union(u,v)
9. Return A
#Prim’s Algorithm
MST-PRIM(G,w,r)
1. For each u € G.V
2. U.key = ∞
3. U.π = NIL
4. R.key = 0
5. Q = G.V
6. While Q ≠ ϕ
7. U = EXTRACT-MIN(Q)
8. For each v € G.Adj[u]
9. If v € Q and w(u,v) < v.key
10. V.π = u
11. V.key = w(u,v)
ALGORITHM OF SINGLE SOURCE SORTEST PATH
# The Bellman-Ford Algorithm
BELLMAN-FORD(G,w,s)
1. INITIALIZE-SINGLE-SOURCE(G,s)
2. For i=1 to |G.V|-1
3. For each edge (u,v) € G.E
4. RELAX(u,v,w)
5. For each edge (u,v) € G.E
6. If v.d > u.d + w(u,v)
7. Return FALSE
8. Return TRUE
# Dijkstra’s Algorithm
1. INITIALIZE-SINGLE-SOURCE(G,s)
2. S = ϕ
3. Q = G.V
4. While Q ≠ ϕ
5. U=EXTRACT-MIN(Q)
6. S = S U {u}
@OMKAR VERMA
7. For each vertex v € G.Adj[u]
8. RELAX(u,v,w)

More Related Content

What's hot

5 4 function notation
5 4 function notation5 4 function notation
5 4 function notation
hisema01
 
Remainder and factor theorems
Remainder and factor theoremsRemainder and factor theorems
Remainder and factor theorems
Ron Eick
 
Pretest
PretestPretest
Pretest
ingroy
 
4.7 graph linear functions day 1
4.7 graph linear functions   day 14.7 graph linear functions   day 1
4.7 graph linear functions day 1
bweldon
 
Day 10 examples u1w14
Day 10 examples u1w14Day 10 examples u1w14
Day 10 examples u1w14
jchartiersjsd
 

What's hot (18)

Open addressiing &amp;rehashing,extendiblevhashing
Open addressiing &amp;rehashing,extendiblevhashingOpen addressiing &amp;rehashing,extendiblevhashing
Open addressiing &amp;rehashing,extendiblevhashing
 
Algebra 2 Unit 5 Lesson 2
Algebra 2 Unit 5 Lesson 2Algebra 2 Unit 5 Lesson 2
Algebra 2 Unit 5 Lesson 2
 
5 4 function notation
5 4 function notation5 4 function notation
5 4 function notation
 
2.1 the basic language of functions t
2.1 the basic language of functions  t2.1 the basic language of functions  t
2.1 the basic language of functions t
 
Multiplicacion de polinomios 1ro
Multiplicacion de polinomios   1roMultiplicacion de polinomios   1ro
Multiplicacion de polinomios 1ro
 
Hash function
Hash functionHash function
Hash function
 
Remainder and factor theorems
Remainder and factor theoremsRemainder and factor theorems
Remainder and factor theorems
 
Factor theorem
Factor theoremFactor theorem
Factor theorem
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2
 
Hashing
HashingHashing
Hashing
 
Maths revision
Maths  revisionMaths  revision
Maths revision
 
10.5 more on language of functions x
10.5 more on language of functions x10.5 more on language of functions x
10.5 more on language of functions x
 
Pretest
PretestPretest
Pretest
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
Hashing Algorithm
Hashing AlgorithmHashing Algorithm
Hashing Algorithm
 
4.7 graph linear functions day 1
4.7 graph linear functions   day 14.7 graph linear functions   day 1
4.7 graph linear functions day 1
 
Day 10 examples u1w14
Day 10 examples u1w14Day 10 examples u1w14
Day 10 examples u1w14
 
Hash tables
Hash tablesHash tables
Hash tables
 

Similar to Design and analysis of algorithm By Creative Developper

College Algebra MATH 107Record your answers and work on th.docx
College Algebra MATH 107Record your answers and work on th.docxCollege Algebra MATH 107Record your answers and work on th.docx
College Algebra MATH 107Record your answers and work on th.docx
clarebernice
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
league
 

Similar to Design and analysis of algorithm By Creative Developper (20)

Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Unit III Heaps.ppt
Unit III Heaps.pptUnit III Heaps.ppt
Unit III Heaps.ppt
 
Question bank xi
Question bank xiQuestion bank xi
Question bank xi
 
Heaps
HeapsHeaps
Heaps
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
NCM LECTURE NOTES ON LATIN SQUARES(27) (1) (1)
NCM LECTURE NOTES ON LATIN SQUARES(27) (1) (1)NCM LECTURE NOTES ON LATIN SQUARES(27) (1) (1)
NCM LECTURE NOTES ON LATIN SQUARES(27) (1) (1)
 
NCM LECTURE NOTES ON LATIN SQUARES(27)
NCM LECTURE NOTES ON LATIN SQUARES(27)NCM LECTURE NOTES ON LATIN SQUARES(27)
NCM LECTURE NOTES ON LATIN SQUARES(27)
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
Maths important questions for 2018
Maths important questions for 2018Maths important questions for 2018
Maths important questions for 2018
 
Maths imp questions for 2018
Maths imp questions for 2018Maths imp questions for 2018
Maths imp questions for 2018
 
College Algebra MATH 107Record your answers and work on th.docx
College Algebra MATH 107Record your answers and work on th.docxCollege Algebra MATH 107Record your answers and work on th.docx
College Algebra MATH 107Record your answers and work on th.docx
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳
 
Ip3614981501
Ip3614981501Ip3614981501
Ip3614981501
 
Array
ArrayArray
Array
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy SubgroupsA Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
 
Chapter 9 ds
Chapter 9 dsChapter 9 ds
Chapter 9 ds
 
Operations on Functions.pdf
Operations on Functions.pdfOperations on Functions.pdf
Operations on Functions.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Design and analysis of algorithm By Creative Developper

  • 1. @OMKAR VERMA GITM LUCKNOW Department Of Computer Science & Engineering Design & Analysis Of Algorithm HoD Er. Brijesh Pandey Faculty Mr. Peeyush Kr. Pathak 1.HEAP SORT MAX-HEAPIFY(A,i) 1. L=Left(i) 2. R=Right(i) 3. If l<= A.heap-size and A[l]>A[i] 4. Largest = l 5. Else largest = i 6. If r<= A.heap-size and A[r]>A[largest] 7. Largest = r 8. If largest ≠ i 9. Exchange A[i] with A[largest] 10. MAX-HEAPIFY(A,largest)
  • 2. @OMKAR VERMA BUILD-MAX-HEAP(A) 1. A.heap-size = A.length 2. For I = [A.length/2] downto 1 3. MAX_HEAPIFY (A,i) 2.QUICK SORT QUICK SORT(A,p,r) 1. If p <r 2 . q=PARTITION(A,p,r) 3.QUICKSORT(A,p,q-1) 4.QUICKSORT(A,q+1,r) Partition in Quick Sort PARTITION (A,p,r) 1. X=A[r] 2. I=p-1 3. for j=p to r-1 4. if A[j] ≤ x 5. i=i+1 6. exchange A[i] with A[j] 7. exchange A[i+1] with A[r] 8. return i+1 3.Counting Sort COUNTING-SORT(A,B,k) 1. let C[0……..k] be a new array 2. for i=0 to k 3. C[i] = 0 4. For j = 1 to A.length 5. C[A[j]] = C[A[j]+1] // C[i] now contains the number of elements equal to i. 6. For I = 1 to k 7. C[i] = C[i] + C[i-1] 8. //C[i] now contains the number of elements less than or equal to i. 9. For j= A.length downto 1 10. B[C[A[j]]] = A[j] 11. C[A[j]] = C[A[j]] - 1
  • 3. @OMKAR VERMA 4.Radix Sort RADIX_SORT(A,d) 1. For i=1 to d 2. Use a stable sort to sort array A on digit i. 5.Bucket Sort BUCKET-SORT(A) 1. Let B[0. . . . . . .n-1] be a new array 2. N=A.length 3. For i=0 to n-1 4. Make B[i] an empty list 5. For i= 1 to n 6. Insert A[i] into list B[[nA[i]]] 7. For i= 0 to n-1 8. Sort list B[i] with insertion sort 9. Concatenate the lists B[0],B[1]. . . . . . . B[n-1] together in order. ALGORITHM OF B -TREE # B Tree Searching B-TREE-SEARCH(x,k) 1. I=1 2. While i≤ x.n and k > x.keyi 3. i=i=i+1 4. if i ≤ x.n and k == x.keyi 5. return (x,i) 6. elseif x.leaf 7. return NIL 8. else DISK-READ(x,Ci) 9. return B-TREE-SEARCH(x.Ci,k)
  • 4. @OMKAR VERMA # B Tree Creating B-TREE-CREATE(T) 1. X=ALLOCATE-NODE() 2. X.leaf = TRUE 3. X.n = 0 4. DISK-WRITE(x) 5. T.root = x # B Tree Spliting B-TREE-SPLIT-CHILD(x,i) 1. Z=ALLOCATE-NODE() 2. Y=x.Ci 3. Z.leaf=y.leaf 4. Z.n=t-1 5. For j=1 to t-1 6. Z.key(j) = y.key(j+1) 7. If not y.leaf 8. For j = 1 to t 9. Z.C(j)= y.C(j+t) 10. Y.n=t-1 11. For j=x.n+1 downto i+1 12. X.C(j+1)=x.C(j) 13. X.C(i+1)=z 14. For j=x.n downto i 15. X.key(j+1)=x.key(j) 16. X.key(i)=y.key(t) 17. X.n=x.n+1 18. DISK-WRITE(y) 19. DISK-WRITE(z) 20. DISK-WRITE(x) # B Tree Insertion B-TREE-INSERT(T,k) 1. R=T.root 2. If r.n==2t-1 3. S=ALLOCATE-NODE() 4. T.root=s 5. S.leaf=FALSE 6. S.n=0 7. S.C1=r 8. B-TREE-SPLIT-CHILD(s,1) 9. B-TREE-INSERT-NONFULL(s,k)
  • 5. @OMKAR VERMA 10. Else B-TREE-INSERT-NONFULL(r,k) ALGORITHM OF FIBONACCI HEAP # Inserting A Node FIB-HEAP-INSERT(H,x) 1. X.degree = 0 2. X.p = NIL 3. X.child = NIL 4. X.mark = FALSE 5. If H.min==NIL 6. Create a root list for H containing just x 7. H.min==x 8. Else insert x into H’s root list 9. If x.key < H.min.key 10. H.min=x 11. H.n = H.n+1 # Uniting Two Fibonacci Heap FIB-HEAP-UNION(H1,H2) 1. H=MAKE-FIB-HEAP() 2. H.min=H1.min 3. Concatenate the root list of H2 with the root list of H 4. If(H1.min==NIL) or (H2.min≠NIL and H2.min.key<H1.min.key) 5. H.min=H2.min 6. H.n=H1.n+H2.n 7. Return H #Extacting The Minimum Node FIB-HEAP-EXTRACT-MIN(H) 1. Z=H.min 2. If z≠ NIL 3. For each child x of z 4. Add x to the root list of H 5. X.p=NIL 6. Remove z from the root list of H 7. If z == z.right 8. H.min= NIL
  • 6. @OMKAR VERMA 9. Else H.min = z.right 10. CONSOLIDATE(H) 11. H.n = H.n-1 12. Return z #CONSOLIDATE 1. Let A[0. . . . . . . . D(H.n)be a new array] 2. For i= 0 to D(H.n) 3. A[i]=NIL 4. For each node w in the root list of H 5. X=w 6. d= x.degree 7. while A[d] ≠ NIL 8. y=A[d] //another node with the same degree as x 9. if x.key > y.key 10. exchange x with y 11. FIB-HEAP-LINK(H,y,x) 12. A[d] = NIL 13. d = d+1 14. A[d] = x 15. H.min = NIL 16. For i=0 to D(H.n) 17. If A[i]≠ NIL 18. If H.min==NIL 19. Create a root list for H containing just A[i] 20. H.min = A[i] 21. Else insert A[i] into H’s root list 22. If A[i].key<H.min.key 23. H.min = A[i] FIB-HEAP-LINK(H,y,x) 1. Remove y from the root list of H 2. Make y a child of x,incrementing x.degree 3. Y.mark=FALSE #Decreasing a key in Fibonacci Heap FIB-HEAP-DECREASE-KEY(H,x,k) 1. If k> x.key 2. Error “new key is greater than current key” 3. X.key=k
  • 7. @OMKAR VERMA 4. Y=x.p 5. If ≠NIL and x.key<y.key 6. CUT(H,x,y) 7. CASCADING-CUT(H,y) 8. If x.key<H.min.key 9. H.min=x # CUT(H,x,y) 1. Remove x from the child list of y,decrementing y.degree 2. Add x to the root list of H 3. X.p= NIL 4. X.mark=FALSE # CASCADING-CUT(H,y) 1. Z=y.p 2. If z≠ NIL 3. If y.mark==FALSE 4. Y.mark = TRUE 5. Else CUT(H,y,z) 6. CASCADING-CUT(H,z) # Deleting a node in Fibonacci Heap FIB-HEAP-DELETE(H,x) 1. FIB-HEAP-DECREASE-KEY(H,x,-∞) 2. FIB-HEAP-EXTRACT-MIN(H) ALGORITHM OF MINIMUM SPANNING TREE #Kruskal’s Algorithm MST-KRUSKAL(G,w) 1. A=ϕ 2. For each vertex v € G,V 3. MAKE-SET(v) 4. Sort the edges of G.E into nondecreasing order by weight w 5. For each edge (u,v) € G.E,taken in nondecreasing order by weight 6. If FIND-SET(u) ≠ FIND-SET(v) 7. A = A Ự {(u,v)}
  • 8. @OMKAR VERMA 8. Union(u,v) 9. Return A #Prim’s Algorithm MST-PRIM(G,w,r) 1. For each u € G.V 2. U.key = ∞ 3. U.π = NIL 4. R.key = 0 5. Q = G.V 6. While Q ≠ ϕ 7. U = EXTRACT-MIN(Q) 8. For each v € G.Adj[u] 9. If v € Q and w(u,v) < v.key 10. V.π = u 11. V.key = w(u,v) ALGORITHM OF SINGLE SOURCE SORTEST PATH # The Bellman-Ford Algorithm BELLMAN-FORD(G,w,s) 1. INITIALIZE-SINGLE-SOURCE(G,s) 2. For i=1 to |G.V|-1 3. For each edge (u,v) € G.E 4. RELAX(u,v,w) 5. For each edge (u,v) € G.E 6. If v.d > u.d + w(u,v) 7. Return FALSE 8. Return TRUE # Dijkstra’s Algorithm 1. INITIALIZE-SINGLE-SOURCE(G,s) 2. S = ϕ 3. Q = G.V 4. While Q ≠ ϕ 5. U=EXTRACT-MIN(Q) 6. S = S U {u}
  • 9. @OMKAR VERMA 7. For each vertex v € G.Adj[u] 8. RELAX(u,v,w)