@Lucifier : it didnt work as you can see

input :- 6,10,8,5,9,7,1,5,4
K=8;

min heap=1,5,6,7,8,9,10
max heap=10,9,8,6,7,5,1

 A[Top(MaxH)] - A[Top(MinH)] > K i.e 10-1 > 8

//we are in else part of your logic

A[j] = A[Top(MinH)];

currentStrInd = Top(MaxH) +1;  // currentStrInd=2

pop(Top(MaxH));

(now , max heap= 9,8,6,7,5,1       min heap=1,5,6,7,8,9,10 )

while(MaxH is not empty)
{
      if (Top(MaxH) < currentStrInd)    // 4 < 2     ->move to else if
condition
        pop(Top(MaxH)) ;

     else if (A[Top(MaxH)] - A[Top(MinH)] <= K)  --> 9-1 <= 8 TRUE
.....break this loop.
        break;


}

even after coming out of the loop..
as you can see that element 6 is still in max heap array , along with this
i can see there is code to remove elements from the min heap...
this will cause problem for certain seq of input.

min heap=1,5,6,7,8,9,10
max heap=9,8,6,7,5,1

hope you get it what i am trying to say , correct me if i am wrong

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to