You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good afternoon! So, I've tested the BinaryMaxHeap class according the steps above and here the execution was perfect. For testing, I've created a execution project with a Main Class program with the follow code:
BinaryMaxHeap<long>maxHeap=newMaxHeap<long>(Comparer<long>.Default);Randomrand=new Random();/* Adding the elements to heap. */for(inti=0;i<80000;++i){
maxHeap.Add(rand.Next());}/* Removing the elements from heap. */while(!maxHeap.IsEmpty){varelement= maxHeap.ExtractMax();/* Showing part of heap. */if(maxHeap.Count %2000==0){
Console.WriteLine(element);}}
Maybe the found problem is related to execution time to generate random numbers, it's my guess. If a random object is created each time a random number is generated, putting the instantiation line inside loop affects performance.
steps to reproduce
Write a loop, from 1 to 80000, each time add a random int to the max heap.
In theory it takes very little time(NlogN, N=80000, <1sec ), but the program does take a long time.
I'v also tested the BinaryHeap in https://github.com/SolutionsDesign/Algorithmia, it performs well, so it is probably due to the bad algorithm.
The text was updated successfully, but these errors were encountered: