Quiz 1 - Data Structures & Algorithms (EL3101)
Quiz 1 - Data Structures & Algorithms (EL3101)
(EL3101)
20 Marks | B. Tech. ELC 5th Semester | 3:10 PM to 3:40 PM
* Required
2. Registration Number *
Algorithm
1.Initialize a variable total_sum to 0. This variable will store the
cumulative sum of the marks.
2.___________________________________.
3.For each mark, add its value to total_sum.
4.After the loop ends, total_sum will contain the sum of all the
marks. * (1 Point)
Statement 1 is correct
Statement 2 is correct
Statement 3 is correct
Statement 1 is correct
Statement 2 is correct
Statement 3 is correct
O(1)
O(n^2)
O(2^n)
8. Calculate the Big O notation time complexity for the following
code snippet:
def example(arr):
n = len(arr)
for i in range(n):
for j in range(n):
print(i, j)
* (1 Point)
O(n^2)
O(n)
O(2^n)
O(1)
#include <stdio.h>
int sum_recursive(int n) {
if (n == 0) {
return 0;
} else {
return n + sum_recursive(n - 2);
}
}
int main() {
int n = 10;
printf("%d\n", sum_recursive(n));
return 0;
} * (1 Point)
30
55
Error
10. What will come in the fill in the blank of the following Code such
that the output is 35.
#include <stdio.h>
int drs(int n) {
if (n == 0) {
return 0;
} else {
return __________ + drs(n - 1);
}
}
int main() {
int n = 10;
printf("%d\n", drs(n));
return 0;
} * (1 Point)
11. What will come in the fill in the blank of the following Code such
that the output is 360.
#include <stdio.h>
int drs(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= _________;
}
return result;
}
int main() {
int n = 4;
printf("%d\n", drs(n));
return 0;
} * (2 Points)
12. Consider a software firm developing a tool to generate a unique
password every time a user logs in some platform. Suppose
following code snippet generates a unique password at every
execution. What will come in the fill in the blanks A and B?
#include <stdlib.h>
#include <time.h>
int main() {
_______A______; // Fill in the blank A
printf("%d\n", _______B______); // Fill in the blank B
return 0;
} * (2 Points)
A is srand(time(0))
B is rand()
A is rand()
B is srand(time(0))
A is time(0)
B is time(rand())
{4,5,6,7}
Depends on Memory
256
1000
Unlimited
2
16. What is the result of the expression sizeof(int) in C? * (1 Point)
16
17. How do you access the last element of an array arr with n elements
in C? * (1 Point)
arr[n]
arr[n-1]
arr[n+1
arr[last]
3,2,15
2,3,20
2,1,15
1,2,5
This content is neither created nor endorsed by Microsoft. The data you submit will be sent to the form owner.
Microsoft Forms