Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)

2013-05-26 Thread Nishant Pandey
@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

Re: [algogeeks] What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.EO

2013-05-26 Thread Nitish Raj
Ravi you r correct. Rope aka Cord. On Sun, May 26, 2013 at 9:36 AM, Ravi Ranjan ravi.cool2...@gmail.comwrote: Rope On Sat, May 25, 2013 at 10:24 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: In one of the interview it was asked, can some one suggest good DS for this. Thanks

Re: [algogeeks] What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.EO

2013-05-26 Thread Nishant Pandey
i feel stack would be good as we undo the last edited item easily in stack, i have not implemented Rope, if some have implemented Rope, please help me i am interested in implementing Rope. On Sun, May 26, 2013 at 4:21 PM, Nitish Raj raj.n...@gmail.com wrote: Ravi you r correct. Rope aka Cord.

[algogeeks] inplace merge of 2 sorted parts of an array

2013-05-26 Thread bharat b
An array is given, first and second half are sorted .. Make the array sorted inplace... Need an algo better than O(n^2).. If the length of the array is odd.. middle is either in first half or second half. Ex: 1. Arr[] = {2,3,6,8,-5,-2,3,8} -- output : Arr[]={-5,-2,2,3,3,6,8,8}; 2. Arr[] =

Re: [algogeeks] inplace merge of 2 sorted parts of an array

2013-05-26 Thread Nishant Pandey
The solution could be given in this way. 1) In one pass get the end index of both array says e1 and e2. 2) now in next pass compare elements at e1 and e2 . a) if a(e1) a(e2) swap the elements and then decreament e1 and e2 both. b) if a(e1) a(e2) decreament e2. c) if a(e1) == a(e2) then

Re: [algogeeks] inplace merge of 2 sorted parts of an array

2013-05-26 Thread Ankit Agarwal
The first pass is not necessary. We can finding the middle element as follows: N = even, Range [ 0 - (N/2 - 1) ] [ N/2 - (N - 1) ] N = odd, if (A[N/2] A[N/2 -1]) Range [ 0 - N/2 ] [ (N/2 + 1) - (N - 1) ] else if ( A[N/2] A[N/2 + 1]) Range [ 0 - (N/2 - 1) ] [

Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-26 Thread Nishant Pandey
@DOn can u explain ur first algo, it would be helpful. On Wed, May 22, 2013 at 7:28 PM, Don dondod...@gmail.com wrote: My program works with any numbers. Don On May 22, 3:45 am, Pramida Tumma pramida.tu...@gmail.com wrote: This above program works only if the array contains consecutive