You are on page 1of 4

ICT 4303- FUNDAMENTALS OF DATA STRUCTURE & ALGORITHMS

INSEMESTER EXAMINATION-2
SCHEME

Type: MCQ
Q1. In Circular Singly Linked List last node's address field contains the address of the first
node ? (0.5)
a. **True
b. False
Q2. Select output of the following code:
#include <iostream> using
namespace std;
int main() {
char arr[] = { 'Z', 'Y', 'X', 'W' };
char* ptr = &arr[0]; ptr++;
cout<<*ptr++<<*--ptr;
} (0.5)
a. ** YY
b. XX
c. XY
d. YX
Q3. Which data structure is required to convert the infix to prefix notation? (0.5) a.
**Stack
b. Circular Linked list
c. Binary tree
d. Queue
Q4. Which of the following is the infix expression? (0.5)
a. ** A+B*C

b. +A*BC
c. ABC+*
d. None of the above
Q5. Which of the following principle does Queue use? (0.5)
1. LIFO principle
2. **FIFO principle

3. LILO
4. Ordered or sequential
Q6. Which one of the following is the overflow condition if linear queue is implemented
using an array with a size MAX_SIZE? (0.5)
1. rear = front
2. rear = front+1
3. **rear=MAX_SIZE -1
4. rear = MAX_SIZE
Q7. Consider the following code snippet:
struct node
{ int
data;
struct node *next;
} node
*ptr;
Which one of the following is the correct option to create a new node? (0.5)
1. ptr= (node*)malloc(sizeof(node*))
2. ptr=(node)malloc(sizeof(node))
3. **ptr= (node*)malloc(sizeof(node))
Q8. What is the postfix form of A*B+C/D is ? (0.5)
1. *AB/CD+
2. **AB*CD/+
3. A*BC+/D
4. ABCD +/*

Q9. If the elements “6”, “3”, “4” and “1” are placed in a queue one at a time, in what order
they will be removed?(0.5)
1. 1436
2. **6341
3. 1463
Q10. _____________________ can be used in web page navigation in both forward and
backward directions. (0.5)
1. **Doubly linked list
2. Singly linked list
3. Circular linked list
4. Stack

Type: DES
Q11. Write the prefix and postfix expressions for the expression a/b^c+d*e-f*g . Show all
the conversion steps . (2)
[infix to prefix: 1m, infix to postfix: 1m]
a/b^c+d*e-f*g
a/ bc^ +d*e-f*g
abc^/ + de* - fg*
abc^/de*+ - fg*
postfix: abc^/de*+fg*-

a/b^c+d*e-f*g
a/ ^bc + *de - *fg
/a^bc + *de - *fg
+/a^bc *de - *fg
Prefix: -+/a^bc*de*fg
Q12. Evaluate the expression 2 3 * 4 5 + * using stack. Illustrate each step with contents of
the stack. (2)
[Each step illustration with correct answer: 2m]
Token Operation Stack
2 2
3 23
* 2*3 6
4 64
5 645
+ (4+5) 69
* 6*9 54
Answer is 54

Q13. Is the matrix defined below sparse? If yes, write a c++ program to obtain the sparse
representation. If no, write a c++ program to find the sum of all the values in the matrix.
int Matrix[4][5] = {
{0 , 0 , 3 , 0 , 4 },
{0 , 0 , 5 , 7 , 0 },
{0 , 0 , 0 , 0 , 0 },
{0 , 2 , 6 , 0 , 0 } }; (3)
[Identifying sparse or not: 0.5m, Finding size code: 0.5m, sparse matrix representation
code: 2m]
Given matrix is sparse as it has more number of zeros [14 zeroes among 20 (4x5) elements].
// C++ program for Sparse Matrix Representation
int main()
{ // Assume 4x5 sparse matrix
int sparseMatrix[4][5] =
{ {0 , 0 , 3 , 0 , 4 },
{0 , 0 , 5 , 7 , 0 },
{0 , 0 , 0 , 0 , 0 },
{0 , 2 , 6 , 0 , 0 }
};
int size = 0;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 5; j++)
if (sparseMatrix[i][j] != 0) size++;
int compactMatrix[3][size]; // Making of new matrix
int k = 0;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 5; j++){
if (sparseMatrix[i][j] != 0)
{
compactMatrix[0][k] = i;
compactMatrix[1][k] = j;
compactMatrix[2][k] = sparseMatrix[i][j];
k++;
}
}
}
for (int i=0; i<3; i++)
{
for (int j=0; j<size; j++) cout <<" "<< compactMatrix[i][j];
cout <<"\n";
}
return 0;
}

Q14. Write a menu driven c++ program to implement a queue using an array. Write only the
enqueue , dequeue function and the main method . (3)
[enque: 1m, deque: 1m, main: 1m]
int queue[100], n = 100, front = - 1, rear = - 1;
void enqueue() { int val;
if (rear == n - 1) cout<<"Queue Overflow"<<endl;
else {
if (front == - 1) front = 0;
cout<<"Insert the element in queue : "<<endl; cin>>val;
rear++;
queue[rear] = val;
}
}
void deque() {
if (front == - 1 || front > rear) { cout<<"Queue Underflow "; return ; }
else {
cout<<"Element deleted from queue is : "<< queue[front] <<endl;
front++;
}}
int main() {
int ch;
cout<<"1) Insert element to queue"<<endl;
cout<<"2) Delete element from queue"<<endl;
cout<<"4) Exit"<<endl;
do { cout<<"Enter your choice : "<<endl; cin>>ch;
switch (ch) {
case 1: enqueue(); break;
case 2: deque(); break;
case 4: cout<<"Exit"<<endl; break;
default: cout<<"Invalid choice"<<endl;
}
} while(ch!=4);
return 0;
}

You might also like