wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

QUIZ 1 DS1E

Total questions: 10

Worksheet time: 9mins

Name
Class
Date
1.

Encapsulation combines an ADT’s data with its operations to form a(n) ______.

a)

exception

b)

method

c)

object

d)

variable

2.

What does the following recursive algorithm display?


writeBack(in s:string)

if (s is empty)

return

else

{

Write the first character of s

writeBack(the string beginning at the second character of s)

}

a)

nothing

b)

the first character of s a number of times equal to the length of s

c)

the string s

d)

the string s backward

3.

A stack is initially empty, then the following commands are performed:

push 5, push 7, pop, push 10, push 5, pop


which of the following is the correct stack after those commands (assume the top of the stack is on the left)?

a)

5 10 7 5

b)

5 10

c)

7 5

d)

10 5

4.

4. If the array [6, 2, 7, 13, 5, 4] is added to a stack, in the order given, which number will be the first number to be removed from the stack?

a)

6

b)

2

c)

5

d)

4

5.

What is the value of the following postfix expression: 5 2 – 8 4 + * ?

a)

-9

b)

28

c)

35

d)

36

6.

What behaviour does the ADT stack exhibit?

a)

first in, first out

b)

first in, never out

c)

last in, first out

d)

last in, last out

7.

Which of the following statements inserts a new node, pointed to by newPtr, at the end of a linear linked list?

a)

newPtr->next = cur;

prev->next = newPtr;

b)

newPtr->next = head;

head = newPtr;

c)

newPtr->next = NULL;

d)

prev->next = cur;

newPtr->next = cur;

8.

Below is a function, countNode, to calculate the number of nodes in a list. Fill in the blank with a proper statement.

int linkedList:: countNode (linkedList *list)

{

int count = 0;

ptr = list->head;

while (FILL IN THE BLANK)

{

count++;

ptr = ptr->next;

}

return count;

}

a)

ptr != ptr->next

b)

ptr = ptr ->next

c)

ptr != NULL

d)

ptr = NULL

9.

Which of the following operations of the ADT stack accepts a parameter?

a)

push

b)

isEmpty

c)

peek

d)

destroyStack

10.

How many asterisks are printed by the function call quiz (5) ?


void quiz(int i)

{

if (i > 1)

{

quiz(i / 2);

quiz(i / 2);

}

cout << "*";

}

a)

5

b)

6

c)

7

d)

8