Search Header Logo

DSA QUIZ 2

Authored by PUSHPALATHA C2114

Computers

University

Used 1+ times

DSA QUIZ 2
AI

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

30 sec • 1 pt

1.What will be the output of the following code snippet?

void solve() { int a[] = {1, 2, 3, 4, 5}; int sum = 0; for(int i = 0; i < 5; i++) { if(i % 2 == 0) { sum += a[i]; } } cout << sum << endl; }

5

15

9

12

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

2.
What is the output of the following code snippet?

void solve()

{

stack<int> s;

s.push(1);

s.push(2);

s.push(3);

for(int i = 1; i <= 3; i++)

{

cout << s.top() << “ “; s.pop();

}

}

3 2 1

1 2 3

3

1

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

3.What will be the output of the following code snippet?

void solve()

{

int n = 24;

int l = 0, r = 100, ans = n;

while(l <= r)

{

int mid = (l + r) / 2;

if(mid * mid <= n)

{

ans = mid;

l = mid + 1;

}

else

{

r = mid - 1;

}

}

cout << ans << endl;

}

5

4

6

3

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

4.What will be the value of “sum” after the following code snippet terminates?

void solve(ListNode* root)

{ /* The LinkedList is defined as:

root-> val = value of the node

root-> next = address of next element from the node The List is 1 -> 2 -> 3 -> 4 -> 5 */

int sum = 0;

while(root -> next != NULL)

{

sum += root -> val;

root = root -> next;

}

cout << sum << endl;

}

10

20

5

1

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

5.Which data structure is mainly used for implementing the recursive algorithm?

stack

queue

array

list

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

6.Consider a situation where a client receives packets from a server. There may be differences in speed of the client and the server. Which data structure is best suited for synchronization?

  • Circular Linked List

  • Queue

  • Stack

  • Priority Queue

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

7.A list of n strings, each of length n, is sorted into lexicographic order using merge - sort algorithm. The worst case running time of this computation is :

  • O(n log n)

  • O(n2log n)

  • O(n2 + log n)

  • O(n3)

Access all questions and much more by creating a free account

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

Already have an account?