Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
Q. The reason bubble sort algorithm is inefficient is that it continues execution even after an array is sorted by performing unnecessary comparisons. Therefore, the number of comparisons in the best and worst cases both are same. Modify the algorithm such that it will not make the next pass when the array is already sorted.
Ans:
The bubble sort continues the execution even after an array is sorted. To avoid unnecessary comparisons we add a Boolean variable say switched and initialize it by True in the starting. Along with the "for" loop, we hear add the condition (switched=true) and make it false inside the outer for loop. If a swapping is done then the value of switched is made true. Thus if no swapping has been done in the first pass, then no more comparisons will be done further and the program shall exit.
The algorithm after modifying it in the above stated manner will be as follows:-
void bubble(int x[],int n)
{
int j,pass,hold;
bool switched=true;
for(pass=0;pass
switched=false;
for(j=0;j
switched=true; hold=x[j]; x[j]=x[j+1];
x[j+1]=hold;
}
Q. Sort the sequence written below of keys using merge sort. 66, 77, 11, 88, 99, 22, 33, 44, 55 Ans:
Q. Convert the given infix expression into the postfix expression (also Show the steps) A ∗ (B + D)/ E - F(G + H / k ) Ans. Steps showing Infix to Post fix
Operation of Algorithm The following sequence of diagrams shows the operation of Dijkstra's Algorithm. The bold vertices show the vertex to which shortest path has been find ou
It does not have any cycles (circuits, or closed paths), which would imply the existence of more than one path among two nodes. It is the most general kind of tree, and might be co
The best algorithm to solve a given problem is one that requires less space in memory and takes less time to complete its execution. But in practice it is not always possible to
Q. Give the algorithm to build a binary tree where the yields of preorder and post order traversal are given to us.
B- Tree A B-tree of order m is an m-way true in which 1) All leaves are on the similar level 2) All internal nodes except the root have at most m-1(non-empty) childre
This method is the reverse of FIFO and assumes that each issue of stock is made from latest items received in the enterprises .Thus if the last lot to be received is not sufficient
Determine the greatest common divisor (GCD) of two integers, m & n. The algorithm for GCD might be defined as follows: While m is greater than zero: If n is greater than m, s
Write a function that performs the integer mod function. Given the previous functions you have implemented already, this one should be a piece of cake. This function will find the
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!
whatsapp: +1-415-670-9521
Phone: +1-415-670-9521
Email: info@expertsmind.com
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd