SlideShare uma empresa Scribd logo
1 de 24
HEAP
GROUP : INFINITY
PRESENTATION TOPIC :Write a program to construct a Heap and perform deletion, insertion,
search, update. Also find the Smallest and Largest Elements in the Heap and Find the Common Ancestor
and Print the Path.
Presented to:
Dr. Sheak Rashed Haider Noori
Assistant Professor
Department Of CSE
Daffodil Internal University
• Presented by:
• Anirudha Dhar Parash (152-15-5742)
• S.M. Zahidul Islam (152-15-5925)
• Samyamay Howlader (152-15-5913)
• Muzahidul Islam (152-15-5585)
• Sharuk Ahmed (152-15-5796)
(Insert Function)
Anirudha Dhar
ID: 152-15-5742
INSERT FUNCTION
void insert(int num, int location)
{
int parentnode;
while (location > 0)
{
parentnode =(location - 1)/2;
if (num <= array[parentnode])
{
array[location] = num;
return;
}
array[location] = array[parentnode];
location = parentnode;
}
array[0] = num;
}
(Delete & Display Function)
S.M. Zahidul Islam
ID: 152-15-5925
DELETE FUNCTION
void delete(int array[],int size )
{
int i=size-1;
array[0]=array[i];
i--;
heap_sort(array,i);
}
void heap_sort(int array[],int size)
{
int i,c,root,temp;
for (i = 1; i <=size; i++)
{
c = i;
do
{
root = (c - 1) / 2;
if (array[root] < array[c])
{
temp = array[root];
array[root] = array[c];
array[c] = temp;
}
c = root;
}
while (c != 0);
}
}
DISPLAY FUNCTION
void display(int array[],int n)
{
int i;
if (n == 0)
{
printf("Heap is empty n");
return;
}
for (i = 0; i < n; i++)
printf("%d ", array[i]);
printf("n");
}
(Search Function)
Samyamay Howlader Niloy
ID: 152-15-5913
SEARCH FUNCTION
void search(int array[],int n)
{
int i,key;
printf("Enter the number that you search:");
scanf("%d",&key);
if (n == 0)
{
printf("Heap is empty n");
return;
}
for (i = 0; i < n; i++)
{
if(array[i]==key)
{
printf("The number is found");
}
}
}
(Max & Min Num Function)
Muzahidul Islam
ID: 152-15-5585
MAX NUM FUNCTION
void max_num(int array[],int n)
{
int i,max;
max=array[0];
for (i = 0; i < n; i++)
{
if(array[i]>max)
{
max=array[i];
}
}
printf("The maximum number in heap: %d",max);
}
MIN NUM FUNCTION
void min_num(int array[],int n)
{
int i,min;
min=array[0];
for (i = 0; i < n; i++)
{
if(array[i]<min)
{
min=array[i];
}
}
printf("The minimum number in heap: %d",min);
}
(COMMON ANCESTOR & Update Function)
Sharuk Ahmed
ID: 152-15-5796
COMMON ANCESTOR FUNCTION
void ancestor(int array[],int n,int num)
{
int i,a[100];
if (n == 0)
{
printf("Heap is empty n");
return;
}
for (i = 0; i < n; i++)
{
a[i]=array[i];
if(array[i]==num)
{
break;
}
}
printf("Common Ancestors : ");
do
{
a[i]=a[(i-1)/2];
printf("%d,",a[i]);
i=(i-1)/2;
}
while(i>=1);
printf("n");
}
UPDATE FUNCTION
void update(int array[],int n )
{
int i,key,num;
printf("enter the number that is to be delete : ");
scanf("%d",&key);
printf("enter the number that you update : ");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(array[i]==key)
{
array[i]=num;
}
}
heap_sort(array,n);
printf("the number is updated : ");
}
MAIN FUNCTION
int main()
{
int choice, num;
n = 0;
while(1)
{
printf("1.Insert the element n");
printf("2.Delete the element n");
printf("3.Display all elements n");
printf("4.Search element: n");
printf("5.Search max number: n");
printf("6.Search min number: n");
printf("7.Find the Common Ancestor: n");
printf("8.Update an element: n");
printf("9.Quit n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the element to be inserted to the list :
");
scanf("%d", &num);
insert(num, n);
n = n + 1;
break;
case 2:
delete(array,n);
n=n-1;
break;
case 3:
display(array,n);
break;
case 4:
search(array,n);
break;
case 5:
max_num(array,n);
break;
case 6:
min_num(array,n);
break;
case 7:
printf("Enter the element : ");
scanf("%d", &num);
ancestor(array,n,num);
break;
case 8:
update(array,n);
break;
case 9:
exit(0);
default:
printf("Invalid choice n");
}
}
}
LAIBRARY FUNCTION
&
GLOBAL VARIABLES
#include <stdio.h>
int array[100], n;
Any questions
?
Thank You!!!

Mais conteúdo relacionado

Mais procurados

pycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslateRenyuan Lyu
 
3分くらいで分かるassert()
3分くらいで分かるassert()3分くらいで分かるassert()
3分くらいで分かるassert()Ippei Ogiwara
 
6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui documentRazvan Raducanu, PhD
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regularesAnel Sosa
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvassuitzero
 
Rubyconfindia2018 - GPU accelerated libraries for Ruby
Rubyconfindia2018 - GPU accelerated libraries for RubyRubyconfindia2018 - GPU accelerated libraries for Ruby
Rubyconfindia2018 - GPU accelerated libraries for RubyPrasun Anand
 
Fcontratos
FcontratosFcontratos
Fcontratoskarlloss
 
Dfs implementation in c
Dfs implementation in cDfs implementation in c
Dfs implementation in cHapPy SumOn
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめようYuriko IKEDA
 

Mais procurados (15)

pycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslate
 
Vcs17
Vcs17Vcs17
Vcs17
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
3分くらいで分かるassert()
3分くらいで分かるassert()3分くらいで分かるassert()
3分くらいで分かるassert()
 
A proper introduction to Elm
A proper introduction to ElmA proper introduction to Elm
A proper introduction to Elm
 
Rumus
RumusRumus
Rumus
 
6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regulares
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvas
 
Rubyconfindia2018 - GPU accelerated libraries for Ruby
Rubyconfindia2018 - GPU accelerated libraries for RubyRubyconfindia2018 - GPU accelerated libraries for Ruby
Rubyconfindia2018 - GPU accelerated libraries for Ruby
 
Fcontratos
FcontratosFcontratos
Fcontratos
 
R code
R codeR code
R code
 
P5
P5P5
P5
 
Dfs implementation in c
Dfs implementation in cDfs implementation in c
Dfs implementation in c
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
 

Semelhante a Heap operations program with ancestor path

design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopMohammad Imam Hossain
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdfarjunchetri1
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 

Semelhante a Heap operations program with ancestor path (20)

design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Pnno
PnnoPnno
Pnno
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Ada file
Ada fileAda file
Ada file
 
Ds
DsDs
Ds
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
InsertionSort.pdf
InsertionSort.pdfInsertionSort.pdf
InsertionSort.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 

Mais de S.M.Zahidul Islam sumon (14)

Bioinfo
Bioinfo Bioinfo
Bioinfo
 
Discrete math-presentation
Discrete math-presentationDiscrete math-presentation
Discrete math-presentation
 
Drone
DroneDrone
Drone
 
C programming
C programmingC programming
C programming
 
Os
OsOs
Os
 
Physics ii
Physics iiPhysics ii
Physics ii
 
Block chain
Block chainBlock chain
Block chain
 
Image processing
Image processingImage processing
Image processing
 
Data mining(1)
Data mining(1)Data mining(1)
Data mining(1)
 
Lcd bresenham
Lcd bresenhamLcd bresenham
Lcd bresenham
 
Simulation pst
Simulation pstSimulation pst
Simulation pst
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Technology in education
Technology in educationTechnology in education
Technology in education
 
Zah architecture 123
Zah architecture 123Zah architecture 123
Zah architecture 123
 

Último

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Último (20)

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

Heap operations program with ancestor path

  • 2. PRESENTATION TOPIC :Write a program to construct a Heap and perform deletion, insertion, search, update. Also find the Smallest and Largest Elements in the Heap and Find the Common Ancestor and Print the Path. Presented to: Dr. Sheak Rashed Haider Noori Assistant Professor Department Of CSE Daffodil Internal University • Presented by: • Anirudha Dhar Parash (152-15-5742) • S.M. Zahidul Islam (152-15-5925) • Samyamay Howlader (152-15-5913) • Muzahidul Islam (152-15-5585) • Sharuk Ahmed (152-15-5796)
  • 4. INSERT FUNCTION void insert(int num, int location) { int parentnode; while (location > 0) { parentnode =(location - 1)/2; if (num <= array[parentnode]) { array[location] = num; return; } array[location] = array[parentnode]; location = parentnode; } array[0] = num; }
  • 5. (Delete & Display Function) S.M. Zahidul Islam ID: 152-15-5925
  • 6. DELETE FUNCTION void delete(int array[],int size ) { int i=size-1; array[0]=array[i]; i--; heap_sort(array,i); } void heap_sort(int array[],int size) { int i,c,root,temp;
  • 7. for (i = 1; i <=size; i++) { c = i; do { root = (c - 1) / 2; if (array[root] < array[c]) { temp = array[root]; array[root] = array[c]; array[c] = temp; } c = root; } while (c != 0); } }
  • 8. DISPLAY FUNCTION void display(int array[],int n) { int i; if (n == 0) { printf("Heap is empty n"); return; } for (i = 0; i < n; i++) printf("%d ", array[i]); printf("n"); }
  • 9. (Search Function) Samyamay Howlader Niloy ID: 152-15-5913
  • 10. SEARCH FUNCTION void search(int array[],int n) { int i,key; printf("Enter the number that you search:"); scanf("%d",&key); if (n == 0) { printf("Heap is empty n"); return; } for (i = 0; i < n; i++) { if(array[i]==key) { printf("The number is found"); } } }
  • 11. (Max & Min Num Function) Muzahidul Islam ID: 152-15-5585
  • 12. MAX NUM FUNCTION void max_num(int array[],int n) { int i,max; max=array[0]; for (i = 0; i < n; i++) { if(array[i]>max) { max=array[i]; } } printf("The maximum number in heap: %d",max); }
  • 13. MIN NUM FUNCTION void min_num(int array[],int n) { int i,min; min=array[0]; for (i = 0; i < n; i++) { if(array[i]<min) { min=array[i]; } } printf("The minimum number in heap: %d",min); }
  • 14. (COMMON ANCESTOR & Update Function) Sharuk Ahmed ID: 152-15-5796
  • 15. COMMON ANCESTOR FUNCTION void ancestor(int array[],int n,int num) { int i,a[100]; if (n == 0) { printf("Heap is empty n"); return; } for (i = 0; i < n; i++) { a[i]=array[i]; if(array[i]==num) { break; } }
  • 16. printf("Common Ancestors : "); do { a[i]=a[(i-1)/2]; printf("%d,",a[i]); i=(i-1)/2; } while(i>=1); printf("n"); }
  • 17. UPDATE FUNCTION void update(int array[],int n ) { int i,key,num; printf("enter the number that is to be delete : "); scanf("%d",&key); printf("enter the number that you update : "); scanf("%d",&num); for(i=0; i<n; i++) { if(array[i]==key) { array[i]=num; } } heap_sort(array,n); printf("the number is updated : "); }
  • 18. MAIN FUNCTION int main() { int choice, num; n = 0; while(1) { printf("1.Insert the element n"); printf("2.Delete the element n"); printf("3.Display all elements n"); printf("4.Search element: n"); printf("5.Search max number: n"); printf("6.Search min number: n"); printf("7.Find the Common Ancestor: n"); printf("8.Update an element: n"); printf("9.Quit n"); printf("Enter your choice : ");
  • 19. scanf("%d", &choice); switch(choice) { case 1: printf("Enter the element to be inserted to the list : "); scanf("%d", &num); insert(num, n); n = n + 1; break; case 2: delete(array,n); n=n-1; break;
  • 20. case 3: display(array,n); break; case 4: search(array,n); break; case 5: max_num(array,n); break; case 6: min_num(array,n); break; case 7: printf("Enter the element : "); scanf("%d", &num); ancestor(array,n,num); break;
  • 22. LAIBRARY FUNCTION & GLOBAL VARIABLES #include <stdio.h> int array[100], n;