wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Data Structure and Algorithm

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

#include<stdio.h>


int main()

{

int a[] = {1, 2, 3, 4, 5, 6};

int *ptr = (int*)(&a+1);

printf("%d ", *(ptr-1) );

return 0;

}

a)

1

b)

2

c)

6

d)

Runtime Error

2.

Assume

that the size of an integer is 4 bytes, predict the output of following

program.

#include <stdio.h>

int main()

{

int i = 12;

int j = sizeof(i++);

printf("%d , %d", i, j);

return 0;

}

a)

0, 4

b)

12 , 4

c)

13, 4

d)

Compile Time Error

3.

void main()

{

int const * p=5;

printf("%d",++(*p));

}

a)

5

b)

6

c)

Compile Time Error

d)

Runtime Error

4.

#include <stdio.h>

int main()

{

printf("%d", 1 << 2 + 3 << 4);

return 0;

}

a)

52

b)

112

c)

512

d)

0

5.

#define square(x) x*x

void main()

{

int i;

i = 64/square(4);

printf("%d",i);

}

a)

1

b)

4

c)

Compile Time Error

d)

64

6.

What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

#include<stdio.h>

int main()

{

int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));

return 0;

}

a)

448, 4, 4

b)

1006, 2, 2

c)

520, 2, 2

d)

Error

7.

What is the output of the following code

#include<stdio.h>

void main()

{

int x = 5;

if(x==5)

{

if(x==5) break;

printf("Hello");

}

printf("Hi");

}

a)

Hi

b)

HiHello

c)

HelloHi

d)

Compile Time Error

8.

What will be the output of the following ‘C’ code?

void main ( )

{

int x = 128;

printf (“n%d”, 1 + x ++);

}

a)

128

b)

129

c)

130

d)

131

9.

#include<stdio.h>

int main()

{

int n;

for (n = 9; n!=0; n--)

printf("%d ", n--);

return 0;

}

a)

9 8 7 6 5 4 3 2 1

b)

9 7 5 3

c)

9 7 5 3 1

d)

Infinite loop

10.

Predict the output of following program?

# include <stdio.h>

int main()

{

int x = 10;

int y = 20;

x += y += 10;

printf (" %d %d", x, y);

return 0;

}

a)

40 20

b)

40 30

c)

30 30

d)

30 40

11.

What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)

{

if(head == NULL)

return;

fun1(head->next);

printf("%d ", head->data);

}

a)

Prints all nodes of linked lists

b)

Prints all nodes of linked list in reverse order

c)

Prints alternate nodes of Linked List

d)

Prints alternate nodes in reverse order

12.

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

a)

Insertion Sort

b)

Quick Sort

c)

Merge Sort

d)

Heap Sort

13.

What is the output of following function for start pointing to first node of following linked list?

1->2->3->4->5->6


void fun(struct node* start)

{

if(start == NULL)

return;

printf("%d ", start->data);

if(start->next != NULL )

fun(start->next->next);

printf("%d ", start->data);

}

a)

1 4 6 6 4 1

b)

1 3 5 5 3 1

c)

1 2 3 5

d)

1 3 5 1 3 5

14.

In the worst case, the number of comparisons needed to search a singly linked list of length N for a given element is:

a)

Log 2 N

b)

N/2

c)

Log 2 N - 1

d)

N

15.

Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node x from the list?

a)

O(n)

b)

O(log 2 n)

c)

O(n/2)

d)

O(1)