0% found this document useful (0 votes)
23 views3 pages

Tute1 Stacks

The document contains 6 questions about stacks and related concepts like data structures, stack implementations, and stack operations. Question 1 asks to draw stack frames after executing push and pop operations. Question 2 asks to implement methods of a stack class. Question 3 asks about disadvantages of a constructor and how to rewrite it. Question 4 asks to insert characters into a stack and display the values by removing them. Question 5 asks to fill in blanks about stacks. Question 6 asks to identify the operations given stack frames.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Tute1 Stacks

The document contains 6 questions about stacks and related concepts like data structures, stack implementations, and stack operations. Question 1 asks to draw stack frames after executing push and pop operations. Question 2 asks to implement methods of a stack class. Question 3 asks about disadvantages of a constructor and how to rewrite it. Question 4 asks to insert characters into a stack and display the values by removing them. Question 5 asks to fill in blanks about stacks. Question 6 asks to identify the operations given stack frames.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BSc (Hons) in Information Technology

Year 2
Data Structures and Algorithms – IT2070
Tutorial 1 - Stacks
2024

Question 1

a) Consider the following Stack and draw the Stack frames after executing each statement given below.

int a = 22, b = 44;

i) theStack.push(2);
ii) theStack.push(a);
iii) theStack.push(a + b);
iv) theStack.pop();
v) theStack.push(b);
vi) theStack.push(a –b );

Question 2

Consider the stackX class given below.

int top StackX(int size)


int maxSize void push(int no)
int stackArr[] int pop()
boolean isEmpty()
boolean isFull()
int getCount()

i) Implement isEmpty() and isFull() methods of the stack class.


ii) Implement getCount() method to return the no of items in the stack.

1
Question 3

Constructor of the stack class is implemented as follows,

public StackX()
{
stArr = new double[10];
maxSize = 10;
top = -1;
}

i) Mention one disadvantage of having the above constructor.


ii) Rewrite the constructor to avoid the disadvantage mentioned above.

Question 4

i. A stack class has already been implemented with push() , pop() and peek() methods. It is
a. used to store characters. Write a code segment to insert following characters to a
’myStack’ object created from the stack class.
b. ‘g’ , ‘t’, ‘o’, ‘p’
ii. Write code segment to display all the values in a stack by removing them.
iii. What is the result of section ii) above?

Question 5

Fill in the following blanks.

i) Most popular data structure is _______________


ii) The process of retrieving the element at the top of a stack without removing it is called
___________________
iii) A stack can be implemented using _____________ or ________________
iv) In a stack, if the “top” pointer is equal -1, then the stack is ____________________
v) The time complexity of the push and pop operations on a stack implementation are; push -
_______________ and pop - ____________

2
Question 6

Consider the initial stack frame of a stack given below.

5 Top

Below stack frames are obtained after executing three operations one after another to the above stack
frame. Write down the operations.

8 Top 8 Top

You might also like