SlideShare a Scribd company logo
Describe a data structure that supports both removeMin() and removeMax() with O(log(n))
complexity. You need to show the implementation of insert(), removeMin(), and removeMax(),
and prove their complexity. Hint: one can build on top of the heap.
/*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/
I need to understand
Describe a data structure that supports both removeMin() and removeMax() with O(log(n))
complexity. You need to show the implementation of insert(), removeMin(), and removeMax(),
and prove their complexity. Hint: one can build on top of the heap.
/*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/
I need to understand
Describe a data structure that supports both removeMin() and removeMax() with O(log(n))
complexity. You need to show the implementation of insert(), removeMin(), and removeMax(),
and prove their complexity. Hint: one can build on top of the heap.
/*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/
I need to understand
Solution
The idea here is to use the concept of two binary heaps along with the concept of list(doubly
linked list).
The doubly linked list contains all input items and indexes of corresponding min and max heap
nodes. The nodes of min and max heaps store addresses of nodes of doubly linked list. The root
node of min heap stores the address of minimum item in doubly linked list. Similarly, root of
max heap stores address of maximum item in doubly linked list. Following are the details of
operations.
1) findMax(): We get the address of maximum value node from root of Max Heap. So this is a
O(1) operation.
1) findMin(): We get the address of minimum value node from root of Min Heap. So this is a
O(1) operation.
3) removeMin(): We get the address of minimum value node from root of Min Heap. We use this
address to find the node in doubly linked list. From the doubly linked list, we get node of Max
Heap. We delete node from all three. We can delete a node from doubly linked list in O(1) time.
delete() operations for max and min heaps take O(Logn) time.
4) removeMax(): is similar to deleteMin()
5) Insert() We always insert at the beginning of linked list in O(1) time. Inserting the address in
Max and Min Heaps take O(Logn) time. So overall complexity is O(Logn)
#include
#include
#include
// A node of doubly linked list
struct LNode
{
int data;
int minHeapIndex;
int maxHeapIndex;
struct LNode *next, *prev;
};
// Structure for a doubly linked list
struct List
{
struct LNode *head;
};
// Structure for min heap
struct MinHeap
{
int size;
int capacity;
struct LNode* *array;
};
// Structure for max heap
struct MaxHeap
{
int size;
int capacity;
struct LNode* *array;
};
// The required data structure
struct CDS
{
struct MinHeap* minHeap;
struct MaxHeap* maxHeap;
struct List* list;
};
// A utility function to create a new List node
struct LNode* newLNode(int data)
{
struct LNode* node =
(struct LNode*) malloc(sizeof(struct LNode));
node->minHeapIndex = node->maxHeapIndex = -1;
node->data = data;
node->prev = node->next = NULL;
return node;
}
// Utility function to create a max heap of given capacity
struct MaxHeap* createMaxHeap(int capacity)
{
struct MaxHeap* maxHeap =
(struct MaxHeap*) malloc(sizeof(struct MaxHeap));
maxHeap->size = 0;
maxHeap->capacity = capacity;
maxHeap->array =
(struct LNode**) malloc(maxHeap->capacity * sizeof(struct LNode*));
return maxHeap;
}
// Utility function to create a min heap of given capacity
struct MinHeap* createMinHeap(int capacity)
{
struct MinHeap* minHeap =
(struct MinHeap*) malloc(sizeof(struct MinHeap));
minHeap->size = 0;
minHeap->capacity = capacity;
minHeap->array =
(struct LNode**) malloc(minHeap->capacity * sizeof(struct LNode*));
return minHeap;
}
// Utility function to create the main data structure
// with given capacity
struct CDS* createCDS(int capacity)
{
struct CDS* CDS =
(struct CDS*) malloc(sizeof(struct CDS));
CDS->minHeap = createMinHeap(capacity);
CDS->maxHeap = createMaxHeap(capacity);
CDS->list = createList();
return CDS;
}
// Some basic operations for heaps
int isMaxHeapEmpty(struct MaxHeap* heap)
{ return (heap->size == 0); }
int isMinHeapEmpty(struct MinHeap* heap)
{ return heap->size == 0; }
int isMaxHeapFull(struct MaxHeap* heap)
{ return heap->size == heap->capacity; }
int isMinHeapFull(struct MinHeap* heap)
{ return heap->size == heap->capacity; }
// The standard minHeapop function. The only thing it does extra
// is swapping indexes of heaps inside the List
void minHeapop(struct MinHeap* minHeap, int index)
{
int smallest, left, right;
smallest = index;
left = 2 * index + 1;
right = 2 * index + 2;
if ( minHeap->array[left] &&
left < minHeap->size &&
minHeap->array[left]->data < minHeap->array[smallest]->data
)
smallest = left;
if ( minHeap->array[right] &&
right < minHeap->size &&
minHeap->array[right]->data < minHeap->array[smallest]->data
)
smallest = right;
if (smallest != index)
{
// First swap indexes inside the List using address
// of List nodes
swapData(&(minHeap->array[smallest]->minHeapIndex),
&(minHeap->array[index]->minHeapIndex));
// Now swap pointers to List nodes
swapLNode(&minHeap->array[smallest],
&minHeap->array[index]);
// Fix the heap downward
minHeapop(minHeap, smallest);
}
}
// The standard maxHeapop function. The only thing it does extra
// is swapping indexes of heaps inside the List
void maxHeapop(struct MaxHeap* maxHeap, int index)
{
int largest, left, right;
largest = index;
left = 2 * index + 1;
right = 2 * index + 2;
if ( maxHeap->array[left] &&
left < maxHeap->size &&
maxHeap->array[left]->data > maxHeap->array[largest]->data
)
largest = left;
if ( maxHeap->array[right] &&
right < maxHeap->size &&
maxHeap->array[right]->data > maxHeap->array[largest]->data
)
largest = right;
if (largest != index)
{
// First swap indexes inside the List using address
// of List nodes
swapData(&maxHeap->array[largest]->maxHeapIndex,
&maxHeap->array[index]->maxHeapIndex);
// Now swap pointers to List nodes
swapLNode(&maxHeap->array[largest],
&maxHeap->array[index]);
// Fix the heap downward
maxHeapop(maxHeap, largest);
}
}
// Standard function to insert an item in Min Heap
void insertMinHeap(struct MinHeap* minHeap, struct LNode* temp)
{
if (isMinHeapFull(minHeap))
return;
++minHeap->size;
int i = minHeap->size - 1;
while (i && temp->data < minHeap->array[(i - 1) / 2]->data )
{
minHeap->array[i] = minHeap->array[(i - 1) / 2];
minHeap->array[i]->minHeapIndex = i;
i = (i - 1) / 2;
}
minHeap->array[i] = temp;
minHeap->array[i]->minHeapIndex = i;
}
// Standard function to insert an item in Max Heap
void insertMaxHeap(struct MaxHeap* maxHeap, struct LNode* temp)
{
if (isMaxHeapFull(maxHeap))
return;
++maxHeap->size;
int i = maxHeap->size - 1;
while (i && temp->data > maxHeap->array[(i - 1) / 2]->data )
{
maxHeap->array[i] = maxHeap->array[(i - 1) / 2];
maxHeap->array[i]->maxHeapIndex = i;
i = (i - 1) / 2;
}
maxHeap->array[i] = temp;
maxHeap->array[i]->maxHeapIndex = i;
}
// Function to find minimum value stored in the main data structure
int findMin(struct CDS* CDS)
{
if (isMinHeapEmpty(CDS->minHeap))
return INT_MAX;
return CDS->minHeap->array[0]->data;
}
// Function to find maximum value stored in the main data structure
int findMax(struct CDS* CDS)
{
if (isMaxHeapEmpty(CDS->maxHeap))
return INT_MIN;
return CDS->maxHeap->array[0]->data;
}
// Function to delete maximum value stored in the main data structure
void removeMax(struct CDS* CDS)
{
MinHeap *minHeap = CDS->minHeap;
MaxHeap *maxHeap = CDS->maxHeap;
if (isMaxHeapEmpty(maxHeap))
return;
struct LNode* temp = maxHeap->array[0];
// delete the maximum item from maxHeap
maxHeap->array[0] =
maxHeap->array[maxHeap->size - 1];
--maxHeap->size;
maxHeap->array[0]->maxHeapIndex = 0;
maxHeapop(maxHeap, 0);
// remove the item from minHeap
minHeap->array[temp->minHeapIndex] = minHeap->array[minHeap->size - 1];
--minHeap->size;
minHeap->array[temp->minHeapIndex]->minHeapIndex = temp->minHeapIndex;
minHeapop(minHeap, temp->minHeapIndex);
// remove the node from List
removeLNode(CDS->list, &temp);
}
// Function to delete minimum value stored in the main data structure
void removeMin(struct CDS* CDS)
{
MinHeap *minHeap = CDS->minHeap;
MaxHeap *maxHeap = CDS->maxHeap;
if (isMinHeapEmpty(minHeap))
return;
struct LNode* temp = minHeap->array[0];
// delete the minimum item from minHeap
minHeap->array[0] = minHeap->array[minHeap->size - 1];
--minHeap->size;
minHeap->array[0]->minHeapIndex = 0;
minHeapop(minHeap, 0);
// remove the item from maxHeap
maxHeap->array[temp->maxHeapIndex] = maxHeap->array[maxHeap->size - 1];
--maxHeap->size;
maxHeap->array[temp->maxHeapIndex]->maxHeapIndex = temp->maxHeapIndex;
maxHeapop(maxHeap, temp->maxHeapIndex);
// remove the node from List
removeLNode(CDS->list, &temp);
}
// Function to remove item from min and max heaps
void Delete(struct CDS* CDS, int item)
{
MinHeap *minHeap = CDS->minHeap;
MaxHeap *maxHeap = CDS->maxHeap;
// remove item from min heap
minHeap->array[temp->minHeapIndex] = minHeap->array[minHeap->size - 1];
--minHeap->size;
minHeap->array[temp->minHeapIndex]->minHeapIndex = temp->minHeapIndex;
minHeapop(minHeap, temp->minHeapIndex);
// remove item from max heap
maxHeap->array[temp->maxHeapIndex] = maxHeap->array[maxHeap->size - 1];
--maxHeap->size;
maxHeap->array[temp->maxHeapIndex]->maxHeapIndex = temp->maxHeapIndex;
maxHeapop(maxHeap, temp->maxHeapIndex);
// remove node from List
removeLNode(CDS->list, &temp);
}
// insert operation for main data structure
void Insert(struct CDS* CDS, int data)
{
// insert the item in List
insertAtHead(CDS->list, temp);
// insert the item in min heap
insertMinHeap(CDS->minHeap, temp);
// insert the item in max heap
insertMaxHeap(CDS->maxHeap, temp);
}
Hope this illustration helps...

More Related Content

Similar to Describe a data structure that supports both removeMin() and rem.pdf

Chapter2
Chapter2Chapter2
Chapter2
Krishna Kumar
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docx
debishakespeare
 
Practical cats
Practical catsPractical cats
Practical cats
Raymond Tay
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
mohdjakirfb
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
Merge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdfMerge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdf
feelinggifts
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
firstchoiceajmer
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
ankit11134
 
4 heapsort pq
4 heapsort pq4 heapsort pq
4 heapsort pq
hasan Mohammad
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
arihantcomputersddn
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
Abdulrahman890100
 
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
ajoy21
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
admin463580
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
adkinspaige22
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
Laura Hughes
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
SANDEEPARIHANT
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
Tim Essam
 

Similar to Describe a data structure that supports both removeMin() and rem.pdf (20)

Chapter2
Chapter2Chapter2
Chapter2
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docx
 
Practical cats
Practical catsPractical cats
Practical cats
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Merge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdfMerge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdf
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
4 heapsort pq
4 heapsort pq4 heapsort pq
4 heapsort pq
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
 

More from arihantstoneart

Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdfLet S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
arihantstoneart
 
It is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdfIt is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdf
arihantstoneart
 
I have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdfI have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdf
arihantstoneart
 
Implement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdfImplement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdf
arihantstoneart
 
If an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdfIf an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdf
arihantstoneart
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
arihantstoneart
 
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as  Type I diabetes insipidus.pdfHyposecretion of insulin is referred to as  Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
arihantstoneart
 
How are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdfHow are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdf
arihantstoneart
 
How does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdfHow does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdf
arihantstoneart
 
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdfFor MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
arihantstoneart
 
Explain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdfExplain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdf
arihantstoneart
 
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription  What critical RNA pr.pdfEukaryotic cells modify RNA after transcription  What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
arihantstoneart
 
Driverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdfDriverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdf
arihantstoneart
 
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdfColumbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
arihantstoneart
 
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdfAnatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
arihantstoneart
 
A person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdfA person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdf
arihantstoneart
 
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
arihantstoneart
 
Write your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdfWrite your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdf
arihantstoneart
 
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdfYou have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
arihantstoneart
 
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdfWith X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
arihantstoneart
 

More from arihantstoneart (20)

Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdfLet S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
 
It is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdfIt is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdf
 
I have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdfI have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdf
 
Implement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdfImplement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdf
 
If an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdfIf an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdf
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
 
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as  Type I diabetes insipidus.pdfHyposecretion of insulin is referred to as  Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
 
How are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdfHow are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdf
 
How does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdfHow does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdf
 
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdfFor MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
 
Explain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdfExplain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdf
 
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription  What critical RNA pr.pdfEukaryotic cells modify RNA after transcription  What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
 
Driverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdfDriverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdf
 
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdfColumbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
 
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdfAnatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
 
A person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdfA person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdf
 
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
 
Write your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdfWrite your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdf
 
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdfYou have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
 
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdfWith X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

Describe a data structure that supports both removeMin() and rem.pdf

  • 1. Describe a data structure that supports both removeMin() and removeMax() with O(log(n)) complexity. You need to show the implementation of insert(), removeMin(), and removeMax(), and prove their complexity. Hint: one can build on top of the heap. /*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/ I need to understand Describe a data structure that supports both removeMin() and removeMax() with O(log(n)) complexity. You need to show the implementation of insert(), removeMin(), and removeMax(), and prove their complexity. Hint: one can build on top of the heap. /*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/ I need to understand Describe a data structure that supports both removeMin() and removeMax() with O(log(n)) complexity. You need to show the implementation of insert(), removeMin(), and removeMax(), and prove their complexity. Hint: one can build on top of the heap. /*IF YOU WRITE CODE, PLEASE PROVIDE COMMENTS*/ I need to understand Solution The idea here is to use the concept of two binary heaps along with the concept of list(doubly linked list). The doubly linked list contains all input items and indexes of corresponding min and max heap nodes. The nodes of min and max heaps store addresses of nodes of doubly linked list. The root node of min heap stores the address of minimum item in doubly linked list. Similarly, root of max heap stores address of maximum item in doubly linked list. Following are the details of operations. 1) findMax(): We get the address of maximum value node from root of Max Heap. So this is a
  • 2. O(1) operation. 1) findMin(): We get the address of minimum value node from root of Min Heap. So this is a O(1) operation. 3) removeMin(): We get the address of minimum value node from root of Min Heap. We use this address to find the node in doubly linked list. From the doubly linked list, we get node of Max Heap. We delete node from all three. We can delete a node from doubly linked list in O(1) time. delete() operations for max and min heaps take O(Logn) time. 4) removeMax(): is similar to deleteMin() 5) Insert() We always insert at the beginning of linked list in O(1) time. Inserting the address in Max and Min Heaps take O(Logn) time. So overall complexity is O(Logn) #include #include #include // A node of doubly linked list struct LNode { int data; int minHeapIndex; int maxHeapIndex; struct LNode *next, *prev; }; // Structure for a doubly linked list struct List { struct LNode *head; }; // Structure for min heap struct MinHeap { int size; int capacity; struct LNode* *array; }; // Structure for max heap struct MaxHeap {
  • 3. int size; int capacity; struct LNode* *array; }; // The required data structure struct CDS { struct MinHeap* minHeap; struct MaxHeap* maxHeap; struct List* list; }; // A utility function to create a new List node struct LNode* newLNode(int data) { struct LNode* node = (struct LNode*) malloc(sizeof(struct LNode)); node->minHeapIndex = node->maxHeapIndex = -1; node->data = data; node->prev = node->next = NULL; return node; } // Utility function to create a max heap of given capacity struct MaxHeap* createMaxHeap(int capacity) { struct MaxHeap* maxHeap = (struct MaxHeap*) malloc(sizeof(struct MaxHeap)); maxHeap->size = 0; maxHeap->capacity = capacity; maxHeap->array = (struct LNode**) malloc(maxHeap->capacity * sizeof(struct LNode*)); return maxHeap; } // Utility function to create a min heap of given capacity struct MinHeap* createMinHeap(int capacity) { struct MinHeap* minHeap =
  • 4. (struct MinHeap*) malloc(sizeof(struct MinHeap)); minHeap->size = 0; minHeap->capacity = capacity; minHeap->array = (struct LNode**) malloc(minHeap->capacity * sizeof(struct LNode*)); return minHeap; } // Utility function to create the main data structure // with given capacity struct CDS* createCDS(int capacity) { struct CDS* CDS = (struct CDS*) malloc(sizeof(struct CDS)); CDS->minHeap = createMinHeap(capacity); CDS->maxHeap = createMaxHeap(capacity); CDS->list = createList(); return CDS; } // Some basic operations for heaps int isMaxHeapEmpty(struct MaxHeap* heap) { return (heap->size == 0); } int isMinHeapEmpty(struct MinHeap* heap) { return heap->size == 0; } int isMaxHeapFull(struct MaxHeap* heap) { return heap->size == heap->capacity; } int isMinHeapFull(struct MinHeap* heap) { return heap->size == heap->capacity; } // The standard minHeapop function. The only thing it does extra // is swapping indexes of heaps inside the List void minHeapop(struct MinHeap* minHeap, int index) { int smallest, left, right; smallest = index; left = 2 * index + 1; right = 2 * index + 2;
  • 5. if ( minHeap->array[left] && left < minHeap->size && minHeap->array[left]->data < minHeap->array[smallest]->data ) smallest = left; if ( minHeap->array[right] && right < minHeap->size && minHeap->array[right]->data < minHeap->array[smallest]->data ) smallest = right; if (smallest != index) { // First swap indexes inside the List using address // of List nodes swapData(&(minHeap->array[smallest]->minHeapIndex), &(minHeap->array[index]->minHeapIndex)); // Now swap pointers to List nodes swapLNode(&minHeap->array[smallest], &minHeap->array[index]); // Fix the heap downward minHeapop(minHeap, smallest); } } // The standard maxHeapop function. The only thing it does extra // is swapping indexes of heaps inside the List void maxHeapop(struct MaxHeap* maxHeap, int index) { int largest, left, right; largest = index; left = 2 * index + 1; right = 2 * index + 2; if ( maxHeap->array[left] && left < maxHeap->size && maxHeap->array[left]->data > maxHeap->array[largest]->data ) largest = left;
  • 6. if ( maxHeap->array[right] && right < maxHeap->size && maxHeap->array[right]->data > maxHeap->array[largest]->data ) largest = right; if (largest != index) { // First swap indexes inside the List using address // of List nodes swapData(&maxHeap->array[largest]->maxHeapIndex, &maxHeap->array[index]->maxHeapIndex); // Now swap pointers to List nodes swapLNode(&maxHeap->array[largest], &maxHeap->array[index]); // Fix the heap downward maxHeapop(maxHeap, largest); } } // Standard function to insert an item in Min Heap void insertMinHeap(struct MinHeap* minHeap, struct LNode* temp) { if (isMinHeapFull(minHeap)) return; ++minHeap->size; int i = minHeap->size - 1; while (i && temp->data < minHeap->array[(i - 1) / 2]->data ) { minHeap->array[i] = minHeap->array[(i - 1) / 2]; minHeap->array[i]->minHeapIndex = i; i = (i - 1) / 2; } minHeap->array[i] = temp; minHeap->array[i]->minHeapIndex = i; } // Standard function to insert an item in Max Heap void insertMaxHeap(struct MaxHeap* maxHeap, struct LNode* temp)
  • 7. { if (isMaxHeapFull(maxHeap)) return; ++maxHeap->size; int i = maxHeap->size - 1; while (i && temp->data > maxHeap->array[(i - 1) / 2]->data ) { maxHeap->array[i] = maxHeap->array[(i - 1) / 2]; maxHeap->array[i]->maxHeapIndex = i; i = (i - 1) / 2; } maxHeap->array[i] = temp; maxHeap->array[i]->maxHeapIndex = i; } // Function to find minimum value stored in the main data structure int findMin(struct CDS* CDS) { if (isMinHeapEmpty(CDS->minHeap)) return INT_MAX; return CDS->minHeap->array[0]->data; } // Function to find maximum value stored in the main data structure int findMax(struct CDS* CDS) { if (isMaxHeapEmpty(CDS->maxHeap)) return INT_MIN; return CDS->maxHeap->array[0]->data; } // Function to delete maximum value stored in the main data structure void removeMax(struct CDS* CDS) { MinHeap *minHeap = CDS->minHeap; MaxHeap *maxHeap = CDS->maxHeap; if (isMaxHeapEmpty(maxHeap)) return; struct LNode* temp = maxHeap->array[0];
  • 8. // delete the maximum item from maxHeap maxHeap->array[0] = maxHeap->array[maxHeap->size - 1]; --maxHeap->size; maxHeap->array[0]->maxHeapIndex = 0; maxHeapop(maxHeap, 0); // remove the item from minHeap minHeap->array[temp->minHeapIndex] = minHeap->array[minHeap->size - 1]; --minHeap->size; minHeap->array[temp->minHeapIndex]->minHeapIndex = temp->minHeapIndex; minHeapop(minHeap, temp->minHeapIndex); // remove the node from List removeLNode(CDS->list, &temp); } // Function to delete minimum value stored in the main data structure void removeMin(struct CDS* CDS) { MinHeap *minHeap = CDS->minHeap; MaxHeap *maxHeap = CDS->maxHeap; if (isMinHeapEmpty(minHeap)) return; struct LNode* temp = minHeap->array[0]; // delete the minimum item from minHeap minHeap->array[0] = minHeap->array[minHeap->size - 1]; --minHeap->size; minHeap->array[0]->minHeapIndex = 0; minHeapop(minHeap, 0); // remove the item from maxHeap maxHeap->array[temp->maxHeapIndex] = maxHeap->array[maxHeap->size - 1]; --maxHeap->size; maxHeap->array[temp->maxHeapIndex]->maxHeapIndex = temp->maxHeapIndex; maxHeapop(maxHeap, temp->maxHeapIndex); // remove the node from List removeLNode(CDS->list, &temp); } // Function to remove item from min and max heaps
  • 9. void Delete(struct CDS* CDS, int item) { MinHeap *minHeap = CDS->minHeap; MaxHeap *maxHeap = CDS->maxHeap; // remove item from min heap minHeap->array[temp->minHeapIndex] = minHeap->array[minHeap->size - 1]; --minHeap->size; minHeap->array[temp->minHeapIndex]->minHeapIndex = temp->minHeapIndex; minHeapop(minHeap, temp->minHeapIndex); // remove item from max heap maxHeap->array[temp->maxHeapIndex] = maxHeap->array[maxHeap->size - 1]; --maxHeap->size; maxHeap->array[temp->maxHeapIndex]->maxHeapIndex = temp->maxHeapIndex; maxHeapop(maxHeap, temp->maxHeapIndex); // remove node from List removeLNode(CDS->list, &temp); } // insert operation for main data structure void Insert(struct CDS* CDS, int data) { // insert the item in List insertAtHead(CDS->list, temp); // insert the item in min heap insertMinHeap(CDS->minHeap, temp); // insert the item in max heap insertMaxHeap(CDS->maxHeap, temp); } Hope this illustration helps...