Algorithm to insert element to a max-heap sequentially, Data Structure & Algorithms

Assignment Help:

Q. Write  down the  algorithm  to  insert  an  element  to  a  max-heap  which  is  represented sequentially.          

Ans:

The algorithm to insert an element "newkey" to a max heap of size i-1 where i>=1:

s=i;

parent=s div 2;

key[s]=newkey;

while(s<>0 && key[parent]<=key[s])

{

/*interchange parent and child*/

temp=key[parent]; key[parent]=key[s]; key[s]=temp;

s=parent;

parent=s div 2;

}


Related Discussions:- Algorithm to insert element to a max-heap sequentially

Algorithm to build a binary tree , Q. Give the algorithm to build a binary ...

Q. Give the algorithm to build a binary tree where the yields of preorder and post order traversal are given to us.

State warnock algorithm, Warnock's Algorithm An interesting approach to...

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Define ordinary variable, Ordinary variable An ordinary variable of a e...

Ordinary variable An ordinary variable of a easy data type can store a one element only

Algorithm, Describe different methods of developing algorithms with example...

Describe different methods of developing algorithms with examples.

Stack and queue, write a algorithsm in c to perform push and pop operation...

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Stack, Explain the array and linked list implementation of stack

Explain the array and linked list implementation of stack

Deletion of an element from the linear array, Program will demonstrate dele...

Program will demonstrate deletion of an element from the linear array /* declaration of delete_list function */ voiddelete_list(list *, int); /* definition of delete_list

What are the languages which support assertions, What are the languages whi...

What are the languages which support assertions Languages which support assertions often provide different levels of support. For instance, Java has an assert statement which t

Polynomials, Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8...

Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8  can  be  represented by using arrays. Arithmetic operations such as addition & multiplication of polynomials are com

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd