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

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
PECB
 
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
QucHHunhnh
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
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
 
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...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 

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)