@Lucifier : for your heap approach here is my concerns :-
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
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) // 9 < 2 ->move to else if
condition
pop(Top(MaxH)) ;
else if (A[Top(MaxH)] - A[Top(MinH)] <= K) --> 9-2 <= 8 TRUE
.....break this loop.
break;
}
min heap=1,5,6,7,8,9,10
max heap=9,8,6,7,5,1
where i am getting it 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.