Can you please tell us from where we can find such questions? On Sat, Jul 23, 2011 at 4:21 PM, Nikhil Gupta <[email protected]>wrote:
> Nice question Kamakshi. The person above has given almost a perfect answer. > > For example i=3, we will pop the elements one by one from the top of the > 1st stack and pushed to the 2nd stack until the value (top - i) is reached. > > > On Sat, Jul 23, 2011 at 3:52 PM, ross <[email protected]> wrote: > >> Well. the idea of an array is - given an integer 'i', you should >> support RANDOM ACCESS to the ith element in the 1d array. >> Since, we have two stacks, if you want to access an ith element ( say, >> i = 5 ),pop all the top 4 elements from the 1st stack and push it to >> the second stack. >> Now, access the 5th element on top of the 1st stack, then, pop the >> elements from the 2nd stack back and push them to the 1st stack. >> However, access is O(n) due to the inherent property of a stack which >> forbids random access! >> >> >> On Jul 23, 2:00 pm, Kamakshii Aggarwal <[email protected]> wrote: >> > consider a language that does no have arrays...but u can define stack >> data >> > type like >> > stack s; >> > using pop ,push and other operations on 2 stacks,how can one dimensions >> > array can be implemented?? >> > >> > -- >> > Regards, >> > Kamakshi >> > [email protected] >> >> -- >> 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. >> >> > > > -- > Nikhil Gupta > Senior Co-ordinator, Publicity > CSI, NSIT Students' Branch > NSIT, New Delhi, India > > -- > 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.
