 # Stack 5 Questions 5 Marks Class 12 Computer Science Code 083

## Stack – 5 Important Questions 5 Marks

I tried my best to select the best 5 important categories of questions for the class 12 Computer Science 083 board examination. In the Class 12 Computer Science 083 syllabus, you have to learn about Stack and Its application. Here I am providing you five most important questions. According to term wise syllabus, the weightage of Stack questions in CBSE Board examination is 5 Marks. They can be asked the questions of different categories like – definition/concepts (learning) based, application-based, uses of the stack in problems, and programming based on a stack.

### Question 1 –  Definition / Theory-Based

(i) What is Data Structure?

Answer: Data structure is a way of storing and organising information in the computer. It has well-defined operations, properties and behaviours.

For Examples- Stack, Queue, Linked List, Array, List, etc.

(ii) What do you mean by Stack? What is the significance of TOP in the stack? Write two characteristics of Stack?

Answer: Stack – a stack is an abstract data type and a linear or user-defined data structure based on the principle of Last In First Out (LIFO).

Significance of Top: A stack is a list where insertion and deletion can take place only at one end called Top.

Characteristics of Stacks:

• It is a LIFO data structure.
• The insertion and deletion happen at one end i.e. from the top of the stack.

(iii) What are the operations on the stack? Define each.

Answer: Operations on the Stack are –

• (a) push – to insert an element in the stack at the top position
• (b) pop – to delete an element from the stack from the top position
• (c) peek – to get the topmost element without deletion.
• (d) traversal – to access all the elements from the stack, from top to bottom.

(iv) What are the applications of the stack?

(a) Infix to postfix conversion using stack.

(b) Evaluation of postfix expression.

(c) Reverse a string using a stack.

(d) Implement two stacks in an array.

(v) What do you mean by Underflow and Overflow?

Answer: UNDERFLOW – In stack, the UNDERFLOW condition occurs, when the stack is empty and we try to delete an element from the stack.

OVERFLOW – In stack, the OVERFLOW condition occurs, when the stack is full, and we try to insert an element into the stack.

### Question 2 Type A: Programming/Coding Based

Que 1: Ajay has a list containing integers. You need to help him create a program with separate user-defined functions to perform the following operations based on this list.

• Traverse the content of the list and push all positive numbers into a stack.

• Pop and display the content of the stack.

For Example:

If the sample Content of the list is as follows:

N=[-2, 131,-34, 56, 21, -379, 98, -22, 35, 38]

Sample Output of the code should be:

38 35 98 21 56 131

Output:

Que 2: Sunil has a list containing 10 integers. You need to help him create a program with separate user-defined functions to perform the following operations based on this list.

● Traverse the content of the list and push the even numbers into a stack.

● Pop and display the content of the stack.

For Example:

If the sample Content of the list is as follows:

N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]

Sample Output of the code should be:

38 22 98 56 34 12

Output:

### Question 3 Type B: Programming/Coding Based

Que 1: Anjeev has a message (string) that has an upper case alphabet in it. Write a program, with separate user-defined functions to perform the following operations:

• Push the upper case alphabets in the string into a stack.

• Pop and display the content of the stack.

For example:

If the message is “All the Best, for your Best Performance”

The output from the program should be: P B B A

Output:

Que 2: Shalu has created a dictionary containing names and marks as key-value pairs of 6 students. Write a program, with separate user-defined functions to perform the following operations:

● Push the keys (name of the student) of the dictionary into a stack, where the corresponding value (marks) is greater than 75.

● Pop and display the content of the stack.

For example:

If the sample content of the dictionary is as follows:

R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, “ANU”:90, “TOM”:82}

The output from the program should be:

TOM ANU BOB OM

Output:

### Question 4 – Application-Based

(i) Evaluate the following postfix expression. Show the status of the stack after the execution of each operation separately.

T, F, NOT, AND, T, OR, F, AND

Answer:  Given postfix expression is T, F, NOT, AND, T, OR, F, AND

Output: F

(ii) Evaluate the following postfix expression. Show the status of the stack after the execution of each operation. 60, 6, /, 5, 2, *, 5, −, +

Answer: Given postfix expression is : 60, 6, /, 5,2, *, 5, −, +

### Question 5 – Conversion (Infix to Postfix) Based

Convert the following infix expression to its equivalent postfix expression. Showing stack contents for the conversion : (A + B * (C − D)/E)

Answer:  Given infix expression is :-  (A + B * (C − D)/E)

Output: Postfix Expression: A B C D – E / +