Suppose that a stack object contains the following values Top (8, 5, 2, 9)Bottom
ID: 3817774 • Letter: S
Question
Suppose that a stack object contains the following values Top (8, 5, 2, 9)Bottom. What is the contents of the tack after the following sequence of operations are executed left-to-right? Pop(), Push (8) A) Top {8, 5, 2, 9) Bottom B) Top {5, 2, 9} Bottom C) Top {} Bottom D) Top [8, 5, 2} Bottom E) None of the answers provided What is the complexity of the Is Empty{} operation for an array implementation of a Stack? A) O(1) B) O(N) C) O(logN) D) O(N^2) E) None of the answers provided utilize the following Stack class declaration Your solution must have no memory leaks!!//stack.h - complete header file for stack ADT #include using namespace std; class StackEmpty {/" Empty exception class "/} class StackFull {/" Empty exception class "/} class StackInvalidPeak {/" Empty exception class "/} const int MAXSIZE - 5;//Maximum number of values atored in Stack class Stack//Static array implementation of Stack ADT {Private: int data [MAXSIZE];//Allocated array that holds attack data int top;//Index of top element on stack Public: Stack ();//Initialized private variables of stack object -Stack ();//Destructor void Push (int n);//Adds integer n to top of attack;//Throws StackEmpty if stack is empty int Peek (int n) const;//Returns the value n positions down from top element//Throws StackEmpty if attack is empty//Throws StackInvalidPeek if n is otherwise out of range int Available () const;//Return the number of unused array elements};//End Class StackExplanation / Answer
6)answer: A ( Top{8,5,2,9} Bottom )
explanation:-
given sequence of operations are
Pop(),Push(8)
In pop operation top element of the stack is poped out..
in the given stack top element is 8
so, after pop operation the stack is
Top{5,2,9} Bottom
now again pushing 8, push(8)
so,after push(8) operation stack would be..
Top{8,5,2,9} Bottom
07) answer : A O(1))
explanation:-
for an array implementation of stack .. top value is -1 when it is empty..
so.... in isEmpty operation need just only one comparision
that is top ==-1
it takes constant complexity..
hence O(1)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.