
DSA quiz 3 set 1
Authored by Shubham (M21CS016)
Computers
University
Used 5+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider a directed, weighted graph G = (V, E) with weight function w: E→R. For some function f: V→R, for each edge (u, v) ∈ E, define w'(u, v) as w(u, v) + af(u) - bf(v), where a and b are two constants.
Which one of the options completes the following sentence so that it is TRUE?
“The shortest paths in G under w are the shortest paths under w’ too, ______”.
If a = b
If a<b
If a>b
Any value of a and b
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Let G be a graph with 100! vertices, with each vertex labeled by a distinct permutation of the numbers 1, 2, …, 100. There is an edge between vertices u and v if and only if the label of u can be obtained by swapping two adjacent numbers in the label of v. Let y denote the degree of a vertex in G, and z denote the number of connected components in G. Then y + z = _______ .
100
110
109
None of these
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider BFS on a binary tree starting from the root node. There is a vertex t at a distance 6 from the root. If t is the nth vertex in this BFS traversal, then the minimum and maximum possible values of n are ________
32,64
31,63
64,127
127,128
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider following statements written in C
i) sizeof(int)
ii) sizeof(int*)
iii) sizeof(int**)
Consider the size of int as 4 bytes and size of pointer as 4 bytes. Pick the correct option -
Only i) would compile successfully, and it would return size as 4.
i), ii) and iii) would compile successfully and the size of each would be same i.e. 4
i), ii) and iii) would compile successfully, but the size of each would be different and would be decided at run time
ii) and iii) would result in compile error but i) would compile and result in size as 4.
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following code snippet.
#include <stdlib.h>
int main()
{
int *ptr;
int **ptr1;
int **ptr2;
ptr = (int*)malloc(sizeof(int));
ptr1 = (int**)malloc(10*sizeof(int*));
ptr2 = (int**)malloc(10*sizeof(int*));
free(ptr);
free(ptr1);
free(*ptr2);
return 0;
}
Pick the Correct option -
malloc() for ptr1 and ptr2 isn’t correct. It’ll give a compile time error.
free(*ptr2) is not correct. It’ll give a run time error.
free(*ptr2) is not correct. It’ll give a compile time error.
No issue with any of the malloc() and free() i.e. no compile/run time error.
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Which data structure is best suited to print the documents in the printer?
Queue
Stack
Linked List
Array
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following code snippet.
#include <stdio.h>
int func(int *a, int data)
{
*a = data;
return a;
}
int main()
{
int *x = malloc(sizeof(int));
if (NULL == x) return;
x = func(x, 0);
if(x)
{
x = (int*) malloc(sizeof (int));
if (NULL == x) return;
x = func(x, 10);
}
printf("%d\n", *x);
free(x);
}
compiler error because the comparison should be made as x==NULL and not as shown.
compiler error as the return of malloc is not typecast appropriately.
compiles successfully but execution may result in memory leak.
compiles successfully but execution may result in dangling pointer.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?