mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

QUEUE using STacks:Vinisha Ma'am

3 posters

Go down

QUEUE using STacks:Vinisha Ma'am Empty QUEUE using STacks:Vinisha Ma'am

Post  ballu Sun Feb 01, 2009 10:10 pm

Implement a queue using two stacks
REduce the time as much as possibble
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

QUEUE using STacks:Vinisha Ma'am Empty Re: QUEUE using STacks:Vinisha Ma'am

Post  $corpion Mon Feb 02, 2009 2:34 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???
$corpion
$corpion

Posts : 25
Join date : 2009-01-30
Age : 37

Back to top Go down

QUEUE using STacks:Vinisha Ma'am Empty Re: QUEUE using STacks:Vinisha Ma'am

Post  shivang Mon Feb 02, 2009 3:27 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)
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

QUEUE using STacks:Vinisha Ma'am Empty Re: QUEUE using STacks:Vinisha Ma'am

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum