Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)
Hi Nishant As per the question, (priority queue) PQ is used to implement stack. With PQ, you cannot do push and pop both in O(1). If you use heap tree(max heap assuming you increase priority for upcoming pushed objects or min-heap otherwise) for PQ, it will take O(log n) for each operation push and pop. This is what Ankur is also trying to indicate. Thanks Monish On Sunday, May 26, 2013 12:49:48 PM UTC+5:30, Nishant Pandey wrote: @Ankur... what ever we are inserting we are inserting at the head of the list, so its O(1). we are overriding Enque method with Push(). On Sun, May 26, 2013 at 10:15 AM, Ankur Khurana ankur.k...@gmail.comjavascript: wrote: but in this approach , How is Push having O(1) complexity ? On 25 May 2013 17:52, rohit jangid rohit@gmail.com javascript:wrote: you are doing it correct. On Sat, May 25, 2013 at 5:37 PM, Nishant Pandey nishant.b...@gmail.comjavascript: wrote: I am not getting the y priority Q is getting used for this question, as in case of P Queue, things are arranged as per the priority so when we will insert the data we can simply increament the priority. Algo would be like this : Enque(q, data) { push(q, data, increrase the prioroty); } int Deque() { return pop(); } here higher priority one shuld be poped first. PLEASE SUGGEST if any good approach some one is having other than this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+...@googlegroups.com javascript:. -- Rohit Jangid http://rohitjangid.com Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+...@googlegroups.com javascript:. -- Regards, Ankur Khurana Software Developer Engineer, Microsoft India Development Center, Hyderabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+...@googlegroups.com javascript:. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)
@Ankur... what ever we are inserting we are inserting at the head of the list, so its O(1). we are overriding Enque method with Push(). On Sun, May 26, 2013 at 10:15 AM, Ankur Khurana ankur.kkhur...@gmail.comwrote: but in this approach , How is Push having O(1) complexity ? On 25 May 2013 17:52, rohit jangid rohit.nsi...@gmail.com wrote: you are doing it correct. On Sat, May 25, 2013 at 5:37 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: I am not getting the y priority Q is getting used for this question, as in case of P Queue, things are arranged as per the priority so when we will insert the data we can simply increament the priority. Algo would be like this : Enque(q, data) { push(q, data, increrase the prioroty); } int Deque() { return pop(); } here higher priority one shuld be poped first. PLEASE SUGGEST if any good approach some one is having other than this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- Rohit Jangid http://rohitjangid.com Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- Regards, Ankur Khurana Software Developer Engineer, Microsoft India Development Center, Hyderabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
[algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)
I am not getting the y priority Q is getting used for this question, as in case of P Queue, things are arranged as per the priority so when we will insert the data we can simply increament the priority. Algo would be like this : Enque(q, data) { push(q, data, increrase the prioroty); } int Deque() { return pop(); } here higher priority one shuld be poped first. PLEASE SUGGEST if any good approach some one is having other than this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)
you are doing it correct. On Sat, May 25, 2013 at 5:37 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: I am not getting the y priority Q is getting used for this question, as in case of P Queue, things are arranged as per the priority so when we will insert the data we can simply increament the priority. Algo would be like this : Enque(q, data) { push(q, data, increrase the prioroty); } int Deque() { return pop(); } here higher priority one shuld be poped first. PLEASE SUGGEST if any good approach some one is having other than this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- Rohit Jangid http://rohitjangid.com Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)
but in this approach , How is Push having O(1) complexity ? On 25 May 2013 17:52, rohit jangid rohit.nsi...@gmail.com wrote: you are doing it correct. On Sat, May 25, 2013 at 5:37 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: I am not getting the y priority Q is getting used for this question, as in case of P Queue, things are arranged as per the priority so when we will insert the data we can simply increament the priority. Algo would be like this : Enque(q, data) { push(q, data, increrase the prioroty); } int Deque() { return pop(); } here higher priority one shuld be poped first. PLEASE SUGGEST if any good approach some one is having other than this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- Rohit Jangid http://rohitjangid.com Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- Regards, Ankur Khurana Software Developer Engineer, Microsoft India Development Center, Hyderabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.