QUEUE using STacks:Vinisha Ma'am
3 posters
Page 1 of 1
QUEUE using STacks:Vinisha Ma'am
Implement a queue using two stacks
REduce the time as much as possibble
REduce the time as much as possibble
ballu- Posts : 58
Join date : 2009-02-01
Re: QUEUE using STacks:Vinisha Ma'am
time complexity for queue operation will be O(1)
and deque operation will be...
pop all and push in second stack + pop topmost + pop all and push again bak in first array
O(n)+O(1)+O(n-1)=O(n)
can it be bettered???
and deque operation will be...
pop all and push in second stack + pop topmost + pop all and push again bak in first array
O(n)+O(1)+O(n-1)=O(n)
can it be bettered???
$corpion- Posts : 25
Join date : 2009-01-30
Age : 37
Re: QUEUE using STacks:Vinisha Ma'am
no it cant be better......ya to tujhe pop operation O(n) rakhna padega ya phir push operation O(n) rakhna padega...
dono mein se ek O(n) chalega and dusra O(1)
dono mein se ek O(n) chalega and dusra O(1)
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
Similar topics
» Copy alink list:Vinisha Ma'am
» STACKS - the ignored datastructure
» Structure - Vinisha Ma'am
» Missing and Repeated :Vinisha Ma'am
» List vs arrays:Vinisha Ma'am
» STACKS - the ignored datastructure
» Structure - Vinisha Ma'am
» Missing and Repeated :Vinisha Ma'am
» List vs arrays:Vinisha Ma'am
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|