can we use Balanced Binary Search Tree? Find the smallest weight W greater then given weight I ... After setting the weight of that node equal to W - I ..delete that node..and insert it back into the Balanced Binary Search tree.. i guess that would give O(logN) complexity
On Sat, Mar 10, 2012 at 10:52 PM, saurabh singh <[email protected]> wrote: > The trivial solution would be as follows: > > > findAndUpdateMin(List Truck,value): > minDiff=MAX_INT > minIdx=-1 > for i in Truck.size do: > > if(Truck[i].FreeSpace>=value&& minDiff) then > > minDiff=Truck[i].FreeSpace-value > minIdx=i > endif > done > if(minIdx==-1) return failiure > > Truck[minIdx].FreeSpace=Truck[minIdx].FreeSpace-value > return minIdx > Saurabh Singh > B.Tech (Computer Science) > MNNIT > blog:geekinessthecoolway.blogspot.com > > > > On Sat, Mar 10, 2012 at 10:43 PM, Bhavani Pradeep <[email protected]>wrote: > >> yeah.. they can be removed too >> >> >> On Sat, Mar 10, 2012 at 10:41 PM, saurabh singh <[email protected]>wrote: >> >>> Is it possible items are removed from the truck too? >>> Saurabh Singh >>> B.Tech (Computer Science) >>> MNNIT >>> blog:geekinessthecoolway.blogspot.com >>> >>> >>> >>> On Sat, Mar 10, 2012 at 9:39 PM, shruthi sharma < >>> [email protected]> wrote: >>> >>>> I implemented it by using arraylist. I sorted the trucks according to >>>> the free space and when a load comes I iterated till the point, say j where >>>> I find a suitable space and then sorted it with the elements till j. I want >>>> to know if I can optimize it even further if possible. I want to know if >>>> there a best possible solution than what I implemented? >>>> >>>> -- >>>> 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. >>>> >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Bhavani Pradeep Darbha >> Software Engineer >> IBM - Indian Software Lab >> Pune. >> Ph: +91-9049996768 >> >> -- >> 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. >> > > -- > 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. > -- *Dheeraj Sharma* -- 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.
