Paper1 Solution
Paper1 Solution
Mandal’s
Maharashtra Institute of Technology, Aurangabad
(An Autonomous Institute)
Department of Computer Science and Engineering
Class: SYCSE
Course: Data Structures
Solution
Q. 1
Questions Marks
a) Linear: Snake Game, Movie ticket booking 2
Text editor cut copy paste, Line in ticket counter
Q. 2
a) 1. Insertion in Stack/Push Operation 5
The process of putting a new data element onto stack is known as a Push Operation.
Push operation involves a series of steps −
• Step 1 − Checks if the stack is full.
• Step 2 − If the stack is full, display “stack is FULL”and exit.
• Step 3 − If the stack is not full, increments top to point next empty space.
• Step 4 − Adds data element to the stack location, where top is pointing.
• Step 5 − Returns success.
Example
void push(int data) { if(!isFull())
{
top = top + 1; stack[top] = data;
}
else
{
printf("Could not insert data, Stack is full.\n");
}
}
2. Deletion/Pop Operation
Accessing the content while removing it from the stack, is known as a Pop Operation. In
an array implementation of pop() operation, the data element is not actually removed,
instead top is decremented to a lower position in the stack to point to the next value.
A Pop operation may involve the following steps −
• Step 1 − Checks if the stack is empty.
• Step 2 − If the stack is empty, produces an error and exit.
• Step 3 − If the stack is not empty, accesses the data element at which top is
pointing.
Example
int pop(int data) { if(!isempty()) {
data = stack[top]; top = top - 1;
return data;
}
else
{
printf("Could not retrieve data, Stack is empty.\n");
}
}
Algorithm
o Step 1: IF FRONT = -1 or FRONT > REAR Write UNDERFLOW
ELSE
SET VAL = QUEUE[FRONT] SET FRONT = FRONT + 1 [END OF IF]
o Step 2: EXIT
int main() {
int size = 10;
int myArray[size];
int newElement = 5;
myArray[size] = newElement;
size++;
for(int i=0;i<size;i++)
printf("%d ",myArray[i]);
return 0;
}
•
Remove
Step 1: Input the size of the array arr[] using num, and then declare the pos variable to
define the position, and i represent the counter value.
Step 2: Use a loop to insert the elements in an array until (i < num) is satisfied.
Step 3: Now, input the position of the particular element that the user or programmer
wants to delete from an array.
Step 4: Compare the position of an element (pos) from the total no. of elements (num+1).
If the pos is greater than the num+1, the deletion of the element is not possible and jump
to step 7.
Step 5: Else removes the particular element and shift the rest elements' position to the left
side in an array.
Step 6: Display the resultant array after deletion or removal of the element from an array.
Q. 3
a) 1. Conversion of Infix to Postfix 6
Algorithm for Infix to Postfix
1 /(- 33*41
) - 33*41-
+ + 33*41-/
6 + 33*41-/6
* +* 33*41-/62
2 +* 33*41-/62
Empty 33*41-/62*+
So, the Postfix Expression is 33*41-/62*+