DSA quiz 3 set 1

DSA quiz 3 set 1

University

10 Qs

quiz-placeholder

Similar activities

INTRODUCCION A LA PROGRAMACION

INTRODUCCION A LA PROGRAMACION

6th Grade - University

10 Qs

2025 python class first quiz

2025 python class first quiz

9th Grade - University

10 Qs

Q2 - Python

Q2 - Python

University

10 Qs

Jetpack Workshop

Jetpack Workshop

University

10 Qs

Programação Web - PHP

Programação Web - PHP

University

12 Qs

SENATIC Parcial Guía 3_PseInt

SENATIC Parcial Guía 3_PseInt

10th Grade - University

15 Qs

T02: Python - The Basics

T02: Python - The Basics

University

10 Qs

CCIS 104 Quiz # 1.3

CCIS 104 Quiz # 1.3

University

11 Qs

DSA quiz 3 set 1

DSA quiz 3 set 1

Assessment

Quiz

Computers

University

Medium

Created by

Shubham (M21CS016)

Used 5+ times

FREE Resource

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.

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

By signing up, you agree to our Terms of Service & Privacy Policy

Already have an account?