SlideShare uma empresa Scribd logo
1 de 26
IS 2610: Data Structures Priority Queue, Heapsort, Searching March 15, 2004
Priority Queues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Priority Queue ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Priority Queue: Elementary operations void PQinit(int); int PQempty(); void PQinsert(Item); Item PQdelmax(); #include <stdlib.h> #include &quot;Item.h&quot;  static Item *pq;  static int N; void PQinit(int maxN) { pq = malloc(maxN*sizeof(Item)); N = 0; } int PQempty()  { return N == 0; } void PQinsert(Item v) { pq[N++] = v; } Item PQdelmax() { int j, max = 0; for (j = 1; j < N; j++) if (less(pq[max], pq[j])) max = j; exch(pq[max], pq[N-1]);  return pq[--N]; }
Heap Data Structure ,[object Object],[object Object],[object Object],[object Object],[object Object]
Heap Data Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algorithms on Heaps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A E T A I M G R N O X S P
Bottom-up heapify ,[object Object],[object Object],fixUp(Item a[], int k) { while (k > 1 && less(a[k/2], a[k])) { exch(a[k], a[k/2]); k = k/2; } } A E R A I M G S N O X T P
Top-down heapify ,[object Object],[object Object],A E R A I M G S N P O T X fixDown(Item a[], int k, int N) { int j; while (2*k <= N) { j = 2*k; if (j < N && less(a[j], a[j+1])) j++; if (!less(a[k], a[j])) break; exch(a[k], a[j]); k = j; } } I M N O X P
Heap-based priority Queue ,[object Object],[object Object],[object Object],[object Object],[object Object],#include <stdlib.h> #include &quot;Item.h&quot;  static Item *pq;  static int N; void PQinit(int maxN) { pq = malloc((maxN+1)*sizeof(Item)); N = 0; } int PQempty()  { return N == 0; } void PQinsert(Item v) { pq[++N] = v; fixUp(pq, N); } Item PQdelmax() {  exch(pq[1], pq[N]);  fixDown(pq, 1, N-1);  return pq[N--];  }
Sorting with a priority Queue ,[object Object],[object Object],[object Object],[object Object],void PQsort(Item a[], int l, int r) { int k; PQinit(); for (k = l; k <= r; k++) PQinsert(a[k]); for (k = r; k >= l; k--) a[k] = PQdelmax(); }
Bottom-up Heap ,[object Object],[object Object],G E X A M P R T I A S O L E N T A X M I P void heapsort(Item a[], int l, int r) { int k, N = r-l+1; Item* pq = a + l -1; for (k = N/2; k >= 1; k--)  fixDown(pq, k, N); while (N > 1)  { exch(pq[1], pq[N]);  fixDown(pq, 1, --N); } }
Bottom-up Heap ,[object Object],[object Object],G E T A M I R X P A S O L E N G E S A M I R T O A X P L E N
Radix Sort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Radix Sort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bits, Bytes and Word ,[object Object],[object Object],[object Object],[object Object],[object Object]
Bits, Bytes and Word ,[object Object],[object Object],#define bitsword 32 #define bitsbyte 8 #define bytesword 4 #define R (1 << bitsbyte) #define digit(A, B) (((A) >> (bitsword-((B)+1)*bitsbyte)) & (R-1)) // Another possibility #define digit(A, B) A[B]
Binary Quicksort ,[object Object],[object Object],quicksortB(int a[], int l, int r, int w) { int i = l, j = r; if (r <= l || w > bitsword) return; while (j != i) {  while (digit(a[i], w) == 0 && (i < j)) i++; while (digit(a[j], w) == 1 && (j > i)) j--; exch(a[i], a[j]); } if (digit(a[r], w) == 0) j++; quicksortB(a, l, j-1, w+1); quicksortB(a, j, r, w+1); } void sort(Item a[], int l, int r) {  quicksortB(a, l, r, 0); }
Binary Quicksort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MSD Radix Sort ,[object Object],[object Object]
LSD Radix Sort ,[object Object],[object Object],[object Object],[object Object]
Symbol Table ,[object Object],[object Object],[object Object],[object Object]
Symbol Table ADT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],void STinit(int); int STcount(); void STinsert(Item); Item STsearch(Key); void STdelete(Item); Item STselect(int); void STsort(void (*visit)(Item));
Key-indexed ST ,[object Object],static Item *st; static int M = maxKey; void STinit(int maxN)  { int i; st = malloc((M+1)*sizeof(Item)); for (i = 0; i <= M; i++) st[i] = NULLitem;  } int STcount()  { int i, N = 0; for (i = 0; i < M; i++)  if (st[i] != NULLitem) N++; return N; } void STinsert(Item item) { st[key(item)] = item; } Item STsearch(Key v) { return st[v]; } void STdelete(Item item) { st[key(item)] = NULLitem; }   Item STselect(int k) { int i; for (i = 0; i < M; i++) if (st[i] != NULLitem)  if (k-- == 0) return st[i];  } void STsort(void (*visit)(Item)) { int i; for (i = 0; i < M; i++) if (st[i] != NULLitem) visit(st[i]); }
Sequential Search based ST ,[object Object],[object Object],[object Object],[object Object]
Binary Search ,[object Object],[object Object],[object Object],[object Object],[object Object],Item search(int l, int r, Key v) { int m = (l+r)/2; if (l > r) return NULLitem; if eq(v, key(st[m])) return st[m]; if (l == r) return NULLitem; if less(v, key(st[m]))  return search(l, m-1, v); else return search(m+1, r, v); } Item STsearch(Key v) { return search(0, N-1, v); }

Mais conteúdo relacionado

Mais procurados

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
eShikshak
 

Mais procurados (20)

Queue implementation
Queue implementationQueue implementation
Queue implementation
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Lec3
Lec3Lec3
Lec3
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Queue
QueueQueue
Queue
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
 
Insertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority QueuesInsertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority Queues
 
Queue
QueueQueue
Queue
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Team 6
Team 6Team 6
Team 6
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queue
QueueQueue
Queue
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & SearchingHub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
Arrays
ArraysArrays
Arrays
 
Queue
QueueQueue
Queue
 

Destaque

WL TelPay Tutorial ENGLISH
WL TelPay Tutorial ENGLISHWL TelPay Tutorial ENGLISH
WL TelPay Tutorial ENGLISH
Claudia Baha
 
Riley james johnstone presentation
Riley james johnstone presentationRiley james johnstone presentation
Riley james johnstone presentation
warjohnstone
 
Info2 sec 2_-_data__information
Info2 sec 2_-_data__informationInfo2 sec 2_-_data__information
Info2 sec 2_-_data__information
saltashict
 
presentación de la imagen fija
presentación de la imagen fijapresentación de la imagen fija
presentación de la imagen fija
kitopa
 
Oltre Tata: lean startup all'italiana
Oltre Tata: lean startup all'italianaOltre Tata: lean startup all'italiana
Oltre Tata: lean startup all'italiana
Francesco Trucchia
 
παραβολή
παραβολήπαραβολή
παραβολή
Kozalakis
 

Destaque (20)

Building blocks for a tangible marketing plan
Building blocks for a tangible marketing planBuilding blocks for a tangible marketing plan
Building blocks for a tangible marketing plan
 
Comunicato attività polisportiva - Pallavolo N°10 del 14 dicembre
Comunicato attività polisportiva - Pallavolo N°10 del 14 dicembreComunicato attività polisportiva - Pallavolo N°10 del 14 dicembre
Comunicato attività polisportiva - Pallavolo N°10 del 14 dicembre
 
WL TelPay Tutorial ENGLISH
WL TelPay Tutorial ENGLISHWL TelPay Tutorial ENGLISH
WL TelPay Tutorial ENGLISH
 
Riley james johnstone presentation
Riley james johnstone presentationRiley james johnstone presentation
Riley james johnstone presentation
 
Õppematerjalide loomine LeMill keskkonnas
Õppematerjalide loomine LeMill keskkonnasÕppematerjalide loomine LeMill keskkonnas
Õppematerjalide loomine LeMill keskkonnas
 
las herramientas
las herramientaslas herramientas
las herramientas
 
Info2 sec 2_-_data__information
Info2 sec 2_-_data__informationInfo2 sec 2_-_data__information
Info2 sec 2_-_data__information
 
Some real life data analysis on stationary and non-stationary Time Series
Some real life data analysis on stationary and non-stationary Time SeriesSome real life data analysis on stationary and non-stationary Time Series
Some real life data analysis on stationary and non-stationary Time Series
 
justatemplate_test
justatemplate_testjustatemplate_test
justatemplate_test
 
Presentatie 3 februari Buisleidingenstraat
Presentatie 3 februari BuisleidingenstraatPresentatie 3 februari Buisleidingenstraat
Presentatie 3 februari Buisleidingenstraat
 
Clout januari 2014
Clout januari 2014Clout januari 2014
Clout januari 2014
 
New account
New accountNew account
New account
 
Latest Items from Europe 2016
Latest Items from Europe 2016Latest Items from Europe 2016
Latest Items from Europe 2016
 
presentación de la imagen fija
presentación de la imagen fijapresentación de la imagen fija
presentación de la imagen fija
 
Buen uso de la red y el internet
Buen uso de la red y el internetBuen uso de la red y el internet
Buen uso de la red y el internet
 
Oltre Tata: lean startup all'italiana
Oltre Tata: lean startup all'italianaOltre Tata: lean startup all'italiana
Oltre Tata: lean startup all'italiana
 
Using Practice Fusion for PQRS EHR Reporting in 2014
Using Practice Fusion for PQRS EHR Reporting in 2014Using Practice Fusion for PQRS EHR Reporting in 2014
Using Practice Fusion for PQRS EHR Reporting in 2014
 
Solar Chimney
Solar ChimneySolar Chimney
Solar Chimney
 
Solar chimney
Solar chimneySolar chimney
Solar chimney
 
παραβολή
παραβολήπαραβολή
παραβολή
 

Semelhante a Algorithm

Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
WrushabhShirsat3
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
bermanbeancolungak45
 

Semelhante a Algorithm (20)

DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
 
chapter7 Sorting.ppt
chapter7 Sorting.pptchapter7 Sorting.ppt
chapter7 Sorting.ppt
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Data structure
Data  structureData  structure
Data structure
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
Ch02
Ch02Ch02
Ch02
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 

Último

Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Amil Baba Naveed Bangali
 
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
baharayali
 
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
Amil Baba Naveed Bangali
 
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
baharayali
 
VADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call meVADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call me
shivanisharma5244
 
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
makhmalhalaaay
 
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
baharayali
 

Último (20)

Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
 
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
 
St. Louise de Marillac and Galley Prisoners
St. Louise de Marillac and Galley PrisonersSt. Louise de Marillac and Galley Prisoners
St. Louise de Marillac and Galley Prisoners
 
May 2024 Calendar of Events for Hope Lutheran Church
May 2024 Calendar of Events for Hope Lutheran ChurchMay 2024 Calendar of Events for Hope Lutheran Church
May 2024 Calendar of Events for Hope Lutheran Church
 
Top No 1 Amil baba in Islamabad Famous Amil baba in Pakistan Amil baba Contac...
Top No 1 Amil baba in Islamabad Famous Amil baba in Pakistan Amil baba Contac...Top No 1 Amil baba in Islamabad Famous Amil baba in Pakistan Amil baba Contac...
Top No 1 Amil baba in Islamabad Famous Amil baba in Pakistan Amil baba Contac...
 
The Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docxThe Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docx
 
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
Best Astrologer Vashikaran Specialist in Germany and France Black Magic Exper...
 
Zulu - The Epistle of Ignatius to Polycarp.pdf
Zulu - The Epistle of Ignatius to Polycarp.pdfZulu - The Epistle of Ignatius to Polycarp.pdf
Zulu - The Epistle of Ignatius to Polycarp.pdf
 
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
 
VADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call meVADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call me
 
St. John's Church Parish Magazine - May 2024
St. John's Church Parish Magazine - May 2024St. John's Church Parish Magazine - May 2024
St. John's Church Parish Magazine - May 2024
 
"The Magnificent Surah Rahman: PDF Version"
"The Magnificent Surah Rahman: PDF Version""The Magnificent Surah Rahman: PDF Version"
"The Magnificent Surah Rahman: PDF Version"
 
NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024
 
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
 
Genesis 1:8 || Meditate the Scripture daily verse by verse
Genesis 1:8  ||  Meditate the Scripture daily verse by verseGenesis 1:8  ||  Meditate the Scripture daily verse by verse
Genesis 1:8 || Meditate the Scripture daily verse by verse
 
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
Top Kala Jadu, Bangali Amil baba in Lahore and Kala jadu specialist in Lahore...
 
Deerfoot Church of Christ Bulletin 4 28 24
Deerfoot Church of Christ Bulletin 4 28 24Deerfoot Church of Christ Bulletin 4 28 24
Deerfoot Church of Christ Bulletin 4 28 24
 
Elite Class ➥8448380779▻ Call Girls In Mehrauli Gurgaon Road Delhi NCR
Elite Class ➥8448380779▻ Call Girls In Mehrauli Gurgaon Road Delhi NCRElite Class ➥8448380779▻ Call Girls In Mehrauli Gurgaon Road Delhi NCR
Elite Class ➥8448380779▻ Call Girls In Mehrauli Gurgaon Road Delhi NCR
 
Legends of the Light v2.pdf xxxxxxxxxxxxx
Legends of the Light v2.pdf xxxxxxxxxxxxxLegends of the Light v2.pdf xxxxxxxxxxxxx
Legends of the Light v2.pdf xxxxxxxxxxxxx
 
MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptxMEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptx
 

Algorithm

  • 1. IS 2610: Data Structures Priority Queue, Heapsort, Searching March 15, 2004
  • 2.
  • 3.
  • 4. Priority Queue: Elementary operations void PQinit(int); int PQempty(); void PQinsert(Item); Item PQdelmax(); #include <stdlib.h> #include &quot;Item.h&quot; static Item *pq; static int N; void PQinit(int maxN) { pq = malloc(maxN*sizeof(Item)); N = 0; } int PQempty() { return N == 0; } void PQinsert(Item v) { pq[N++] = v; } Item PQdelmax() { int j, max = 0; for (j = 1; j < N; j++) if (less(pq[max], pq[j])) max = j; exch(pq[max], pq[N-1]); return pq[--N]; }
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.