GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
155 views

can someone give some understandable explaination about this?

asked in Programming by Active (2.5k points) 2 16 48 | 155 views

2 Answers

+3 votes
Best answer
Ans:- A
What question asked to do :- If any stack is empty then give the condition by which we can show "Error" if any pop operation appiled on a empty stack.
Solution:-
1) Given Q stacks of size P/Q, and it start from 0.
2) By giving stack 0 stores elements from 0 to Q-1 and so on (these no.'s are element's position in array S), they have actually given       you the size of each stack i.e. P/Q = Q.
3) Now if a stack 0 is empty then it means top0 == -1, or it can be said top0 == 0*(P/Q) - 1,
    Similary for top1 == Q-1
                       => top1 == 1*(P/Q) - 1
                      => top1 == Q - 1 ( P/Q = Q).
Now generalize it
Top i == i (P/Q) - 1
answered by anonymous 1 1 2
selected by
+1 vote
Implementation of multiple stack in a single array : let array size P, and we are implementing Q stacks hence each stack size becomes P/Q; Array is indexed from 0 to P-1 (size of array is P); Each stack is empty yet as we have not pushed any element. so TOP of 0th stack is T0=0*P/Q - 1, 1st stack is TOP1=1*P/Q - 1; .... and so on ith stack TOPi= i*P/Q - 1; now come on question; FOR POP OPERATION ON STACK IT SHOULD NOT BE EMPTY, so T(i) =T(i-1)+P/Q (ith stack TOP will be equal to (i-1)th stack TOP +Stack size=P/Q ) by expression T(i)==( (i-1)*P/Q - 1 )+ P/Q so it becomes  A
answered by (39 points) 2

Related questions

0 votes
0 answers
1
asked in Programming by S Ram Active (2.5k points) 2 16 48 | 37 views
0 votes
0 answers
2
asked in Programming by rahul sharma 5 Veteran (15k points) 13 111 317 | 41 views
0 votes
1 answer
3
asked in Programming by rahul sharma 5 Veteran (15k points) 13 111 317 | 85 views


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23678 Points

  2. Bikram

    17268 Points

  3. Habibkhan

    8950 Points

  4. srestha

    6446 Points

  5. Debashish Deka

    5478 Points

  6. jothee

    5128 Points

  7. Sachin Mittal 1

    4882 Points

  8. joshi_nitish

    4486 Points

  9. sushmita

    4032 Points

  10. Rishi yadav

    3974 Points


Recent Badges

Popular Question Hira Thakur
Notable Question amaity
Notable Question srestha
Nice Answer Madhab
Renewal Madhab
Popular Question sourabh
Notable Question K ANKITH KUMAR
Great Answer saloni
Resurrection saloni
Great Question Ishrat Jahan
27,406 questions
35,255 answers
84,502 comments
33,454 users