[algogeeks] Stack problem
How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.com wrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
no this wont work coz wat will hapen if that min is popped out ? On Sun, Sep 4, 2011 at 11:11 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.com wrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
+1 sandeep On Sun, Sep 4, 2011 at 11:11 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.com wrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- U.D.I.T Sent by Nokia OVI (c) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
not possible to track min. because even if u keep track min position if u pop tat element again we need to search for next min which isnot possible in o(1) correct me if im wrong On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.com wrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
maintain a separate stack containing min and max element at each step. so if u pop an element for the original stack, pop from the second stack also... On Sun, Sep 4, 2011 at 11:13 PM, Deepak Garg deepakgarg...@gmail.comwrote: +1 sandeep On Sun, Sep 4, 2011 at 11:11 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.comwrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- U.D.I.T Sent by Nokia OVI (c) -- U.D.I.T Sent by Nokia OVI (c) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
+1 Deepak.. On Sun, Sep 4, 2011 at 11:15 PM, Deepak Garg deepakgarg...@gmail.comwrote: maintain a separate stack containing min and max element at each step. so if u pop an element for the original stack, pop from the second stack also... On Sun, Sep 4, 2011 at 11:13 PM, Deepak Garg deepakgarg...@gmail.comwrote: +1 sandeep On Sun, Sep 4, 2011 at 11:11 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.comwrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- U.D.I.T Sent by Nokia OVI (c) -- U.D.I.T Sent by Nokia OVI (c) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Stack problem
suppose in that max stack max elements are maitained.suppose one element with value less arrives.u need to insert it in proper pos.how is that possible in 0(1) ? On Sun, Sep 4, 2011 at 11:15 PM, Deepak Garg deepakgarg...@gmail.comwrote: maintain a separate stack containing min and max element at each step. so if u pop an element for the original stack, pop from the second stack also... On Sun, Sep 4, 2011 at 11:13 PM, Deepak Garg deepakgarg...@gmail.comwrote: +1 sandeep On Sun, Sep 4, 2011 at 11:11 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: we can take another variable min.. first time push operation is done , store the element into min.. next time push is performed , compare the number u r pushing with the already stored no in min variable.. and store minimum of two no's in min variable.. and thn perform the push operation.. so min always contain the minimum no... tell me will that approach work or not? On Sun, Sep 4, 2011 at 10:38 PM, Sangeeta sangeeta15...@gmail.comwrote: How would you design a stack which,in addition to push and pop,also has a function min which returns the minimum element?push,pop and min should all operate in O(1) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- U.D.I.T Sent by Nokia OVI (c) -- U.D.I.T Sent by Nokia OVI (c) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.