UCS301 Quiz 1 With Solutions
UCS301 Quiz 1 With Solutions
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11
1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 2 marks 2 marks 2 marks 2 marks
D A B C A C B & 30 and 2 12 9 and 23
1. Consider a two-dimensional array C[7][6] where each element occupies 2 bytes of memory. The address
of the first element C[0][0] is 200. Which of the following options provides the correct memory address
for C[5][3] when the storage is in row-major order?
A) O(N2) and O(N) B) O(N2) and O(N2) C) O(N) and O(N) D) O(N log N) and O(N)
4. What does the following function fun() do?
void fun(struct Node* head)
{
struct Node* current = head;
int xyz;
while (current != NULL && current -> next != NULL) {
xyz = current -> data;
current -> data = current -> next -> data;
current -> next-> data = xyz;
current = current -> next-> next;
}}
A) It swaps the first and last elements of the linked list
B) It reverses the elements of the linked list
C) It swaps the adjacent elements of the linked list
D) It does not modify the linked list.
5. Suppose an initially empty stack S has executed a total of n push operations, n/3 top operations, n/6 peek
operations and n/2 pop operations but n/6 of pop operations raised empty errors that were caught and
ignored. What is the current size of S?
A) 2n/3 B) 3n/2 C) n/3 D) n/2
6. Consider an array implementation of circular queue of size MAX (indexing starts from 0), you are given
2 statements to check if circular queue is full.
S1: if ((FRONT == REAR+1) || (FRONT == 0 && REAR == MAX-1) then Queue is full
S2: if (FRONT == (REAR+1) % MAX) then Queue is full
What can you say about the above statements? Choose the correct option.
A) Only S1 is true B) Only S2 is true
C) Both S1 and S2 are true D) Both S1 and S2 are false
7. Assume that a Node of singly linked list has data void fun(int v1, int v2) {
field as data and next pointer as next. The code Node* n = new Node();
snippet is meant to insert a Node with data value n->data = v2;
v2 into a linked list after a specific Node identified n->next = NULL;
by the data value v1. However, there are two Node* p = head;
missing lines of code within the else block. You if (head == NULL) {
need to fill in the blanks with the correct option. head = n;
A) p->next = n; //Line 1 return;}
n->next = p->next; //Line 2 while (p != NULL && p->data != v1)
B) n->next = p->next; //Line 1 p = p->next;
p->next = n; //Line 2 if (p == NULL)
C) p->next = n-> next; //Line 1 cout << " Node cannot inserted." << endl;
n->next = p-> next; //Line 2 else {
D) n->next = p->next; //Line 1 ________________ //Line 1
p->next = n->next; //Line 2 ________________ //Line 2
}}
8. The following six items @, #, %, ^, &, * are pushed in a stack one after the starting from @. The stack
is popped three times and each element is inserted into queue. Then 2 elements are deleted from queue
and pushed back on stack one after the other. The element popped from the stack will be ___________.
9.
Consider the function fun1() that takes reference to void fun1(Node* head) {
head of a Singly Linked List as parameter. Assume int ans = 0, count=0;
that a Node of singly linked list has data field Node* temp=head;
as data and next pointer as next. while (temp -> next != NULL) {
The List is 10 -> 15 -> 20 -> 45 -> 55. The output ans += temp -> data;
of the function fun1() is _______________. count++;
if(temp == NULL || temp -> next == NULL)
break;
temp = temp -> next -> next;
}
cout << ans << endl <<count;
}
11. Consider a deque with maximum size of 5 (indexing starts from 0) and all the values are initialized with
-1. After performing the following operations (in sequence) on deque (a) Insert 20, 45, and 18 (in given
order) at the rear end, (b) Delete an element from the front end, (c) Insert 9, 23 (in given order) at the
front end, and (d) Delete an element from the rear end, what will be the elements at index 0 and 4
________ and ________ respectively.
Group: _____________ Name: __________________ Roll Number:__________________
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11
1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 2 marks 2 marks 2 marks 2 marks
A C D B D B C * 85 & 3 10 10 & 19
1. Consider a two-dimensional array C[7][6] where each element occupies 2 bytes of memory. The address
of the first element C[0][0] is 200. Which of the following options provides the correct memory address
for C[5][5] when the storage is in row-major order?
3. The worst case complexity of optimized Bubble sort and Bubble sort is _____________ respectively.
A) O(N2) and O(N) B) O(N) and O(N) C) O(N log N) and O(N) D) O(N2) and O(N2)
4. What does the following function fun() do?
void fun(struct Node* head)
{
struct Node* current = head;
int xyz;
while (current != NULL && current -> next != NULL) {
xyz = current -> data;
current -> data = current -> next -> data;
current -> next-> data = xyz;
current = current -> next-> next;
}}
A) It swaps the first and last elements of the linked list
B) It swaps the adjacent elements of the linked list
C) It reverses the elements of the linked list
D) It does not modify the linked list.
5. Suppose an initially empty stack S has executed a total of 2n push operations, 2n/3 top operations, n/3
peek operations and n pop operations but n/3 of pop operations raised empty errors that were caught and
ignored. What is the current size of S?
A) 3n B) n C) 2n/3 D) 4n/3
6. Consider an array implementation of circular queue of size MAX (indexing starts from 0), you are given
2 statements to check if circular queue is full.
S1: if ((REAR == FRONT+1) || (FRONT== 0 && REAR == MAX-1) then Queue is full
S2: if (FRONT == (REAR+1) % MAX) then Queue is full
What can you say about the above statements? Choose the correct option.
A) Only S1 is true B) Only S2 is true
C) Both S1 and S2 are true D) Both S1 and S2 are false
7. Assume that a Node of singly linked list has data void fun(int v1, int v2) {
field as data and next pointer as next. The code Node* n = new Node();
snippet is meant to insert a Node with data value v2 n->data = v2;
into a linked list after a specific Node identified by n->next = NULL;
the data value v1. However, there are two missing Node* p = head;
lines of code within the else block. You need to fill if (head == NULL) {
in the blanks with the correct option. head = n;
A) p->next = n; //Line 1 return;}
n->next = p->next; //Line 2 while (p != NULL && p->data != v1)
B) p->next = n-> next; //Line 1 p = p->next;
n->next = p-> next; //Line 2 if (p == NULL)
C) n->next = p->next; //Line 1 cout << " Node cannot inserted." << endl;
p->next = n; //Line 2 else {
D) n->next = p->next; //Line 1 ________________ //Line 1
p->next = n->next; //Line 2 ________________ //Line 2
}}
8. The following six items @, #, %, ^, *, & are pushed in a stack one after the starting from @. The stack is
popped three times and each element is inserted into queue. Then 2 elements are deleted from queue and
pushed back on stack one after the other. The element popped from the stack will be ___________.
9. Consider the function fun1() that takes reference to void fun1(Node* head) {
head of a Singly Linked List as parameter. Assume int ans = 0, count = 0;
that a Node of singly linked list has data field Node* temp=head;
as data and next pointer as next. while (temp != NULL) {
The List is 10 -> 15 -> 20 -> 45 -> 55. The output ans += temp -> data;
of the function fun1() is _______________. count++:
if(temp == NULL || temp -> next == NULL)
break;
temp = temp -> next -> next;
}
cout << ans<<endl<<count;
}
11. Consider a deque with maximum size of 5 (indexing starts from 0) and all the values are initialized with
-1. After performing the following operations (in sequence) on deque (a) Insert 45, 10, and 18 (in given
order) at the rear end, (b) Insert 19 and 20 (in given order) at the front end, (c) Delete an element from
the front end, and (d) Delete an element from the rear end, the elements at index 1 and 4 are ________
and ________ respectively.
Group: ____________ Name: __________________ Roll Number:__________________
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11
1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 2 marks 2 marks 2 marks 2 marks
C B A D B A D ^ 35 & 2 8 36 & 32
1. Consider a two-dimensional array C[7][6] where each element occupies 2 bytes of memory. The address
of the first element C[0][0] is 200. Which of the following options provides the correct memory address
for C[5][1] when the storage is in row-major order?
3. The best case complexity of optimized Bubble sort and Bubble sort is _____________ respectively.
A) O(N) and O(N2) B) O(N2) and O(N2) C) O(N) and O(N) D) O(N log N) and O(N)
4. What does the following function fun() do?
void fun(struct Node* head)
{
struct Node* current = head;
int xyz;
while (current != NULL && current -> next != NULL) {
xyz = current -> data;
current -> data = current -> next -> data;
current -> next-> data = xyz;
current = current -> next-> next;
}}
A) It swaps the first and last elements of the linked list
B) It reverses the elements of the linked list
C) It does not modify the linked list
D) It swaps the adjacent elements of the linked list
5. Suppose an initially empty stack S has executed a total of 3n push operations, n top operations, n/2 peek
operations and 3n/2 pop operations but n/2 of pop operations raised empty errors that were caught and
ignored. What is the current size of S?
A) n B) 2n C) 2n/3 D) 3n/2
6. Consider an array implementation of circular queue of size MAX (indexing starts from 0), you are given
2 statements to check if circular queue is full.
S1: if ((FRONT == REAR+1) || (FRONT== 0 && REAR == MAX-1) then Queue is full
S2: if (REAR == (FRONT+1) % MAX) then Queue is full
What can you say about the above statements? Choose the correct option.
A) Only S1 is true B) Only S2 is true
C) Both S1 and S2 are true D) Both S1 and S2 are false
7. Assume that a Node of singly linked list has data void fun(int v1, int v2) {
field as data and next pointer as next. The code Node* n = new Node();
snippet is meant to insert a Node with data value n->data = v2;
v2 into a linked list after a specific Node identified n->next = nullptr;
by the data value v1. However, there are two Node* p = head;
missing lines of code within the else block. You if (head == nullptr) {
need to fill in the blanks with the correct option. head = n;
A) p->next = n; //Line 1 return;}
n->next = p->next; //Line 2 while (p != nullptr && p->data != v1)
B) n->next = p->next; //Line 1 p = p->next;
p->next = n->next; //Line 2 if (p == nullptr)
C) p->next = n-> next; //Line 1 cout << " Node cannot inserted." << endl;
n->next = p-> next; //Line 2 else {
D) n->next = p->next; //Line 1 ________________ //Line 1
p->next = n; //Line 2 ________________ //Line 2
}}
8. The following six items @, #, %, &, ^, * are pushed in a stack one after the starting from @. The stack
is popped three times and each element is inserted into queue. Then 2 elements are deleted from queue
and pushed back on stack one after the other. The element popped from the stack will be ___________.
9.
Consider the function fun1() that takes reference to void fun1(Node* head) {
head of a Singly Linked List as parameter. Assume int ans = 0, count = 0;
that a Node of singly linked list has data field Node* temp=head;
while (temp -> next != NULL) {
as data and next pointer as next.
ans += temp -> data;
The List is 10 -> 15 -> 25 -> 45 -> 55. The output count++;
of the function fun1() will be _____________ if(temp == NULL || temp -> next == NULL)
break;
temp = temp -> next -> next;
}
cout << ans<<endl<<count;
}
10. The value of the given postfix expression 4 2 / 5 3 4 - + * is ______________
11. Consider a deque with maximum size of 5 (indexing starts from 0) and all the values are initialized with
-1. After performing the following operations (in sequence) on deque (a) Insert 2 and 89 (in given order)
at the rear end, (b) Delete an element from the front end, (c) Insert 36, 32, and 50 (in given order) at the
front end, and (d) Delete an element from the rear end, the elements at index 0 and 4 are ________ and
________ respectively.
Group: ____________ Name: __________________ Roll Number:__________________
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11
1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 1 mark 2 marks 2 marks 2 marks 2 marks
B D C A A D C # 90 & 3 6 34 & 26
1. Consider a two-dimensional array C[7][6] where each element occupies 2 bytes of memory. The address
of the first element C[0][0] is 200. Which of the following options provides the correct memory address
for C[5][2] when the storage is in row-major order?
A) O(N) and O(N) B) O(N2) and O(N2) C) O(N2) and O(N) D) O(N log N) and O(N)
4. What does the following function fun() do?
void fun(struct Node* head)
{
struct Node* current = head;
int xyz;
while (current != NULL && current -> next != NULL) {
xyz = current -> data;
current -> data = current -> next -> data;
current -> next-> data = xyz;
current = current -> next-> next;
}}
A) It swaps the adjacent elements of the linked list
B) It swaps the first and last elements of the linked list
C) It reverses the elements of the linked list
D) It does not modify the linked list
5. Suppose an initially empty stack S has executed a total of n push operations, n/3 top operations, n/6 peek
operations and n/3 pop operations but n/12 of pop operations raised empty errors that were caught and
ignored. What is the current size of S?
A) 3n/4 B) 2n/3 C) n D) 11n/12
6. Consider an array implementation of circular queue of size MAX (indexing starts from 0), you are given
2 statements to check if circular queue is full.
S1: if ((REAR == FRONT+1) || (FRONT== 0 && REAR == MAX-1) then Queue is full
S2: if (REAR == (FRONT+1) % MAX) then Queue is full
What can you say about the above statements? Choose the correct option.
A) Only S1 is true B) Only S2 is true
C) Both S1 and S2 are true D) Both S1 and S2 are false
7. Assume that a Node of singly linked list has data void fun(int v1, int v2) {
field as data and next pointer as next. The code Node* n = new Node();
snippet is meant to insert a Node with data value n->data = v2;
v2 into a linked list after a specific Node identified n->next = NULL;
by the data value v1. However, there are two Node* p = head;
missing lines of code within the else block. You if (head == NULL) {
need to fill in the blanks with the correct option. head = n;
A) p->next = n; //Line 1 return;}
n ->next = p->next; //Line 2 while (p != NULL && p->data != v1)
B) p->next = n-> next; //Line 1 p = p->next;
n->next = p-> next; //Line 2 if (p == NULL)
C) n->next = p->next; //Line 1 cout << " Node cannot inserted." << endl;
p->next = n; //Line 2 else {
D) n->next = p->next; //Line 1 ________________ //Line 1
p->next = n->next; //Line 2 ________________ //Line 2
}}
8. The following six items @, %, ^, &, #, * are pushed in a stack one after the starting from @. The stack
is popped three times and each element is inserted into queue. Then 2 elements are deleted from queue
and pushed back on stack one after the other. The element popped from the stack will be ___________.
9.
Consider the function fun1() that takes reference to void fun1(Node* head) {
head of a Singly Linked List as parameter. Assume int ans = 0, count =0;
that a Node of singly linked list has data field Node* temp=head;
while (temp != NULL) {
as data and next pointer as next.
ans += temp -> data;
The List is 10 -> 15 -> 25 -> 45 -> 55. The output count++;
of the function fun1() will be _______________. if(temp == NULL || temp -> next == NULL)
break;
temp = temp -> next -> next;
}
cout << ans<<endl<<count;
}
10. The value of the given postfix expression 4 2 / 4 3 4 - + * is ______________.
11. Consider a deque with maximum size of 5 (indexing starts from 0) and all the values are initialized with
-1. After performing the following operations (in sequence) on deque (a) Insert 34 and 74 (in given
order) at the rear end, (b) Insert 7, 26, and 50 (in given order) at the front end, (c) Delete an element
from the front end, and (d) Delete an element from the rear end, the elements at index 0 and 3 are
________ and ________ respectively.