wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA QUIZ - 2 (17-06-23)

Total questions: 40

Worksheet time: 58mins

Name
Class
Date
1.

Which of the following items are present in the function header?

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

2.

Fill in the line of code for calculating the factorial of a number.


def fact(num):

if num == 0:

return 1

else:

return _____________________

a)

num*fact(num-1)

b)

(num-1)*(num-2)

c)

num*(num-1)

d)

fact(num)*fact(num-1)

3.

What is the output of the following piece of code?


def test(i,j):

if(i==0):

return j

else:

return test(i-1,i+j)


print(test(4,7))

a)

13

b)

7

c)

Infinite Loop

d)

17

4.

what is a variable defined outside all the function referred to as?

a)

A static variable

b)

A global variable

c)

A local variable

d)

An automatic variable

5.

Pick one from the following statements to correctly complete the function body to get the output 5 in the given code snippet:


def f(number):

#missing function body


print(f(5))

a)

return "number"

b)

print(number)

c)

print("number")

d)

return number

6.

What happens if the base condition isn’t defined in recursive programs?

a)

Program gets into an infinite loop

b)

Program runs once

c)

Program runs n number of times where n is the argument given to the function

d)

An exception is thrown

7.

_____________ specifies how we enter data into our programs and what type of data we enter.

a)

data type

b)

data

c)

datum

d)

all of above

8.

In ___________ data structure data items are not in sequence.

a)

non linear

b)

linear

c)

non-homogeneous

d)

all of above

9.

What will be the postfix form of the above expression -

(A+B)∗(C∗D-E)∗F/G

a)

None of these

b)

A B + C D ∗ E − F G ∗ / ∗

c)

A B + C D E ∗ − F G / ∗ ∗

d)

A B + C D ∗ E − F G / ∗ ∗

10.

The following postfix expression with single digit operands is evaluated using a stack:

8 2 3 ^ / 2 3 * + 5 1 * -

a)

6,1

b)

5,7

c)

3,2

d)

1,5

11.

What is the value of the postfix expression 6 3 2 4 + – *

a)

1

b)

40

c)

74

d)

-18

12.

User perform following operations on stack of size 5 then -

push(1);

pop();

push(2);

push(3);

pop();

push(2);

pop();

pop();

push(4);

pop();

pop();

push(5);

a)

Overflow Occurs

b)

Stack Operations will be performed Smoothly

c)

Underflow Occurs

d)

None of these

13.

If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be removed?

a)

a) ABCD

b)

b) DCBA

c)

c) DCAB

d)

d) ABDC

14.

Example of linear data structure except

a)

array

b)

tree

c)

queue

d)

stack

15.
Which of the following is NOT a Type of Data Structures?
a)
Arrays
b)
Tables
c)
Stacks
d)
Trees
16.
What kind of Data structure would you expect to find utilised to store operations in a CPU?
a)
Stack
b)
Queue
c)
List
d)
Tree
17.

A series of values stored in memory is called ___

a)

an array

b)

a tree

c)

a matrix

d)

a struct

18.

Complex data structures built on top of linked lists, that use First-In First-Out behaviour, are called ___

a)

vectors

b)

strings

c)

queues

d)

stacks

19.

What is a data structure?

a)

A method of arranging data

b)

A way of keeping data without an order?

c)

A "stack" only

d)

There is no formal definition for "Data Structure"

20.

Which is the correct operation for:

"Add a item to the rear of the queue."

a)

enQueue(item)

b)

Append.Queue(item)

c)

enQueue()

d)

AddItem(EnQueue())

21.

Select operations that can be performed on a Queue Data Structure...

a)

isEmpty()

b)

pop()

c)

push()

d)

isFull()

e)

Append(Item)

22.

Where would pointers be pointing if...

  1. Eli leaves the Queue.
  2. Hanna joins the Queue.
  3. Adam joins the Queue.
  4. Jason leaves the Queue.
a)

front = 0 rear = 5

b)

front = 1 rear = 4

c)

front = 2 rear = 4

d)

front = 0 rear = 4

e)

front = 2 rear = 5

23.

What would happen if...

deQueue()

enQueue(Hanna)

enQueue(Steve)

enQueue(Jack)

a)

front = 1 rear = 0

*and Steve would be unable to be added to position 0.

b)

front = 1 rear = 5

*and Jack would be unable to be added to position 0

c)

front = 0 rear = 5

d)

front = 0 rear = 4

e)

front = 1 rear = 4

24.

A Queue can only store 6 data items. The Queue is sent 4 data items: Bert, Cynthia, Cedric and Albert. Where does the "Front" pointer point if a deQueue operation is performed.

a)

Bert

b)

Cynthia

c)

Cedric

d)

Albert

25.

A Queue can only store 6 data items. The Queue is sent 4 data items: Bert, Cynthia, Cedric and Albert. Where does the "Rear" pointer point?

a)

0

b)

1

c)

2

d)

3

26.

a QUEUE in a computer acts just like people queuing for a bus - the first person in queue is going to be the first to get on the bus.

a)

True

b)

False

27.

What advantage does a linked list have over an array?

a)

Size of the list doesn't need to be mentioned at the beginning of the program

b)

You can add or remove elements from the middle of the list.

c)

The linked list doesn't have a size limit

d)

All of these are true.

28.

Complete the code in the red column

a)

string info; int link;

b)

int info; NodeType link;

c)

int info; string link;

d)

int info; NodeType * link;

29.

struct node *current = start->next

what will "current" contain if it is a pointer to a variable of type struct node ?

a)

Address of 2nd Node

b)

Data Field of 2nd Node

c)

Address of 1st Node

d)

None of these

30.

How to delete node B?

a)

head->next=TempPtr; free(TemPtr);

b)

free(TemPtr); head->next=TempPtr->next;

c)

head->next=TempPtr->next;free(TemPtr)r;

d)

free(head); head->next= TempPtr->next

31.

How many null pointers exists in a circular linked list?

a)

0

b)

1

c)

2

d)

3

32.

To display data of the linked list:

a)

LinkedList *ptr; while (ptr!=NULL){ cout<<ptr->data;}

b)

LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;cout<<ptr->Data};

c)

LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;}

d)

LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;cout<<ptr->Next;}

33.

The situation when in a linked list START=NULL is

a)

underflow

b)

overflow

c)

list full

d)

saturated

34.

What advantage does a linked list have over an array?

a)

A linked list can give you the data faster

b)

It is easier to use

c)

A linked list is not of a fixed size

d)

It's better

35.
In this tree, where would the new value "7" be placed?
a)
On the left "leaf" of "4"
b)
On the right "leaf" of "6"
c)
On the left "leaf" of "15"
d)
Over the top of the current number "5"
36.

When traversing a binary tree, which diagram is post-order?

a)
b)
c)
37.

Given a sequence of number below:

50,60,40,70,45,55,30,80,65,35,25,75,85


When creating a binary search tree, what is the height of the tree?

a)

3

b)

4

c)

5

d)

6

38.

Given a binary search tree, insert 27, 15, 63, 99, 70 and 85 (in this order) into the binary search tree. What is the post-order traversal?

a)

5,15,27,34,47,54,63,70,72,75,83,85,88,94,99,101

b)

72,54,34,5,27,15,47,63,70,83,75,88,85,101,94,99

c)

15,27,5,47,34,70,63,54,75,85,99,94,101,88,83,72

d)

15,27,5,47,34,63,54,70,75,85,99,94,101,88,83,72

e)

none of the above

39.

The postfix form of the expression (A+ B)*(C*D- E)*F / G is?

a)

AB+ CD*E – FG /**

b)

AB + CD* E – F **G /

c)

AB + CD* E – *F *G /

d)

AB + CDE * – * F *G /

40.

Which of the following statement about binary tree is CORRECT?

a)

Every binary tree is either complete or full

b)

Every complete binary tree is also a full binary tree

c)

Every full binary tree is also a complete binary tree

d)

A binary tree cannot be both complete and full