Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

Chapter 5: Linked Lists


Multiple Choice Questions:
1) When you declare a variable that refers to an object of a given class, you
are creating a(n) ______ to the object.
a. interface
b. reference
c. method
d. ADT
2) In the following code segment:
Integer maxNum;
maxNum = new Integer (15);
______ is a reference variable.
a.
b.
c.
d.

Integer
maxNum
new
15

3) If you attempt to use a reference variable before it is instantiated, a(n)


______ will be thrown.
a. IndexOutOfBoundsException
b. InstantiationException
c. IllegalAccessException
d. NullPointerException
4) A linked
another.
a.
b.
c.
d.

list contains components, called ______, which are linked to one


nodes
arrays
vectors
references

5) According to the principle of information hiding, the data fields of a class


must be declared as ______.
a. public
b. protected
c. private
d. abstract
1 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

6) In Java, every class is ultimately derived from the class _____ through
inheritance.
a. String
b. Object
c. Math
d. Exception
7) The last
a.
b.
c.
d.

node of a linear linked list ______.


has the value null
has a next reference whose value is null
has a next reference which references the first node of the list
cannot store any data

8) A reference variable whose sole purpose is to locate the first node in a


linked list is called ______.
a. top
b. front
c. head
d. first
9) Which of the following will be true when the reference variable curr
references the last node in a linear linked list?
a. curr == null
b. head == null
c. curr.getNext() == null
d. head.getNext() == null
10) If a linked list is empty, the statement head.getNext() will throw a(n)
______.
a. IllegalAccessException
b. ArithmeticException
c. IndexOutOfBoundsException
d. NullPointerException
11)

To delete a node N from a linear linked list, you will need to ______.
a. set the reference next in the node that precedes N to reference
the node that follows N
b. set the reference next in the node that precedes N to reference
N
c. set the reference next in the node that follows N to reference the
node that precedes N
2 of 15

MCSC502 Spring 2015

Test 2

Name:_____________________________
d. set the reference next in N to reference the node that follows N
12) Which of the following statements deletes the node that curr
references?
a. prev.setNext(curr);
b. curr.setNext(prev);
c. curr.setNext(curr.getNext());
d. prev.setNext(curr.getNext());
13) Which of the following statements deletes the first node of a linear
linked list that has 10 nodes?
a. head.setNext(curr.getNext());
b. prev.setNext(curr.getNext());
c. head = head.getNext();
d. head = null;
14)

In a reference-based implementation of an ADT list ______.


a. increasing the size of the list can waste storage and time
b. less memory is required to store an item than in an array-based
implementation
c. an item explicitly references the next item
d. the location of the item after a particular item is implied

15) Which of the following statements is used to insert a new node,


referenced by newNode, at the end of a linear linked list?
a. newNode.setNext(curr);
prev.setNext(newNode);
b. newNode.setNext(head);
head = newNode;
c. prev.setNext(newNode);
d. prev.setNext(curr);
newNode.setNext(curr);

16)

In a linear linked list, ______.


a. the next reference of each node has the value null
b. the last node references the first node
c. the precede reference of the dummy head node references the
last node
d. the next reference of the last node has the value null
3 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

17)

In all circular linked lists, ______.


a. every node references a predecessor
b. every node references a successor
c. the next reference of the last node has the value null
d. each node references both its predecessor and its successor

18)

Which of the following is NOT true about all circular linked lists?
a. every node references a successor
b. the last node references the first node
c. the precede reference of each node references the node that
precedes it
d. no node contains null in its next reference

19)

Which of the following is true about all doubly linked lists?


a. each node references both its predecessor and its successor
b. the precede reference of the last node has the value null
c. the last node references the first node
d. the precede reference of the first node references the last node

20)

Which of the following is true about a circular doubly linked list?


a. inserting into the first position of the list is a special case
b. deleting from the last position of the list is not a special case
c. the precede reference of the last node has the value null
d. the next reference of the last node has the value null

21) A _______ can be used to facilitate adding nodes to the end of a linear
linked list.
a. head record
b. dummy head node
c. tail reference
d. precede reference
Short Answer Questions:
22) What is the difference between a linked list and an array in terms of
their capacity to store data?
4 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

23)

What information is stored in a reference to an object?

24)

In Java, when is an object marked for garbage collection?

25)

What does a node of a linear linked list contain?

26)

What does a traversal operation do?

27) Write the code segment which is used to insert a new node, referenced
by the reference variable newNode, between the nodes referenced by the
reference variables prev and curr in a linear linked list.

28) Write the code segment that is used to insert a new node, referenced
by the reference variable newNode, at the beginning of a linear linked list.

29) What are two advantages of using a reference-based implementation


of the ADT list instead of an array-based implementation?

30)

Why is a loop necessary to find an arbitrary node in a linked list?

31) Suppose we want to write a loop that traverses a doubly-linked circular


linked list. Assume that each node has a prev and a next reference, and
5 of 15

MCSC502 Spring 2015

Test 2

Name:_____________________________
the list itself maintains a reference to a head node. What is wrong with
this loop header?
for (Node curr = head; curr != head.prev; curr = curr.next)

Chapter 6: Problem Solving with Abstract Data Types


Multiple Choice Questions:
32) ______ is a problem-solving technique that involves guesses at a
solution.
a.
b.
c.
d.

Recursion
Backtracking
Iteration
Inductio

33)

A language is a set of strings of ______.


a. numbers
b. letters
c. alphabets
d. symbols

34)

In a grammar, the symbol x | y means ______.


a. x or y
b. x followed by y
c. x out of y
d. x divided by y

35)

In a grammar, the symbol x y means ______.


a. x or y
b. x followed by y
c. x or y or both
d. x multiplied by y

36)

Which of the following is a fully parenthesized expression?


a. x * y + z
b. (x * y) + z
c. ((x * y) + z)
d. (x) * (y) + (z)
6 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

37)

Which of the following is an infix expression?


a. / a + b c
b. a b c + /
c. a b / + c
d. a / (b + c)

38)

What
a.
b.
c.
d.

39)

Which of the following is a postfix expression?


a. / a + b c
b. a b c + /
c. * a b c / +
d. a / (b + c)

40)

Which of the following is a prefix expression?


a. / a + b c
b. a b c + /
c. a * b + c
d. a / (b + c)

41)

What
a.
b.
c.
d.

is the value of the infix expression: 8 * (5 2)?


16
24
38
40

42)

What
a.
b.
c.
d.

is the value of the prefix expression: * 3 8 + 6 5?


11
23
13
21

is the value of the postfix expression: 6 7 + 8 2 *?


-3
-10
48
78

7 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

43) Which of the following is the prefix form of the infix expression: (8 +
6) / (16 4)?
a. + 8 6 / 16 4
b. / 8 6 + 16 4
c. / + 8 6 16 4
d. / + 8 6 16 4
44) Which of the following is the postfix form of the infix expression: a * b
(c + d)?
a. a b c d + *
b. a b * c d +
c. a b c * d +
d. a b c d + *
45) Which of the following is the postfix form of the prefix expression: * +
a b c?
a. a + b * c
b. a + b c *
c. a b + c *
d. a b * c +
Chapter 7: Stacks
Multiple Choice Questions:
46) What is the corrected input if the following line is typed on a keyboard:
ywwdshrwde
(where represents the backspace character)?
a.
b.
c.
d.

ywdswe
ywwdwde
ywdshwe
ywdswd

47) 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?
8 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

a.
b.
c.
d.

6
2
5
4

48) The item that is removed first from a stack is called the ______ of the
stack.
a. front
b. top
c. base
d. prime
49) If the array:
6, 21, 35, 3, 6, 2, 13
is added to a stack, in the order given, which of the following is the top of
the stack?
a.
b.
c.
d.
e.

2
6
3
13
35

50) The ______ method of the ADT stack adds an item to the top of the
stack.
a. createStack
b. push
c. pop
d. peek
51) The ______ method of the ADT stack retrieves and then removes the
top of the stack.
a. createStack
b. push
c. pop
d. peek
52) The ______ method of the ADT stack retrieves the top of the stack, but
does not change the stack.
a. createStack
b. push
c. pop
9 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

d. peek

53)

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


a. push
b. pop
c. createStack
d. peek

54)

Which of the following strings contains balanced braces?


a. ab{cde{fg}hi{jkl}
b. ab{cde{fghi}j}kl}
c. {abc{de}{fg}hij}kl
d. {ab{cde{fgh}ijkl}

55)

The pop operation throws a StackException when it tries to ______.


a. add an item to an empty stack
b. add an item to an array-based implementation of a stack that is
already full
c. delete an item from an array-based implementation of a stack
that is already full
d. delete an item from an empty stack

56)

The push operation throws a StackException when it tries to ______.


a. add an item to an empty stack
b. add an item to an array-based implementation of a stack that is
already full
c. delete an item from an array-based implementation of a stack
that is already full
d. delete an item from an empty stack

57) Given the language L, where:


L = {w$w : w is a possibly empty string of characters other than $,
w = reverse(w) }
which of the following strings is NOT in L?
a. XY$YX
b. Z$Z
10 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

c. $
d. XYZ$ZXY
58)

StackInterface provides the specifications for ______.


a. only the array-based implementation of a stack
b. only the reference-based implementation of a stack
c. only an implementation of a stack that uses the ADT list
d. all the implementations of a stack

59) Which of the following is the postfix form of the infix expression: (a +
b) * c / d
a. a b + c * d /
b. a b * c / d +
c. a + b * c / d
d. a b + c d * /
60)

What
a.
b.
c.
d.

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


-9
28
35
36

Short Answer Questions:


61)

What is the difference between the stack pop and peek operations?

62)
Suppose we begin with an empty stack, and perform the
following operations: push 7, push 2, push 9, push 6, pop, pop, peek,
push 1, push 3, peek, push 8, pop, peek, pop, pop, push 5, push 4, pop,
pop, pop, push 8. What is contained on the stack when we are done?
Write out the contents from top to bottom.

Chapter 8: Queues
Multiple Choice Questions:
63)

Which of the following ADTs is like a line of people?


11 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

a)
b)
c)
d)

list
stack
queue
tree

64)

In a queue, items can be added ______.


a) only at the front of the queue
b) only at the back of the queue
c) either at the front or at the back of the queue
d) at any position in the queue

65)

Operations on a queue can be carried out at ______.


a) its front only
b) its back only
c) both its front and back
d) any position in the queue

66)

Which of the following is NOT an ADT queue operation?


a) enqueue
b) isEmpty
c) pop
d) peek

67)

The ______
a)
b)
c)
d)

operation retrieves and removes the front of a queue.


isEmpty
enqueue
dequeue
peek

68)

The ______
a)
b)
c)
d)

operation adds a new item to a queue.


enqueue
dequeue
push
peek

69)

The ______ operation retrieves the item that was added earliest to a queue,
but does not remove that item.
a) enqueue
b) dequeue
c) dequeueAll
d) peek
12 of 15

MCSC502 Spring 2015


70)

Test 2

Name:_____________________________
Which of the following operations leaves a queue unchanged?
a) enqueue
b) dequeue
c) dequeueAll
d) peek

71)

A reference-based implementation of a queue that uses a linear linked list


would need at least ______ external references.
a) one
b) two
c) three
d) four

72)

If a queue is implemented as the ADT list, which of the following queue


operations can be implemented as list.remove(1)?
a) enqueue()
b) dequeue()
c) isEmpty()
d) peek()

73)

If a queue is implemented as the ADT list, which of the following queue


operations can be implemented as list.get(1)?
a) enqueue()
b) dequeue()
c) isEmpty()
d) peek()

74)

In an implementation of a queue uses the ADT list, which of the following can
be used to implement the operation enqueue(newItem)?
a) list.add(list.size(), newItem)
b) list.add(list.size()+1, newItem)
c) list.add(newItem.size(), newItem)
d) list.add(newItem.size()+1, newItem)

75)

The ADT ______ allows you to insert into, delete from, and inspect the item at
any position of the ADT.
a) stack
b) queue
c) list
d) array

13 of 15

MCSC502 Spring 2015


76)

Test 2

Name:_____________________________
Which of the following is an operation of the ADT stack?
a) enqueue
b) push
c) add
d) get

.
77)

The pop operation of the ADT stack is similar to the ______ operation of the
ADT queue.
a) isEmpty
b) enqueue
c) dequeue
d) peek

78)

The enqueue operation of the ADT queue is similar to the ______ operation of
the ADT stack.
a) isEmpty
b) peek
c) push
d) pop

79)

In the ADT
a)
b)
c)
d)

80)

Which of the following is an operation of the ADT list?


a) pop
b) dequeue
c) peek
d) remove

81)

The line of
a)
b)
c)
d)

list, items can be added ______.


only at the front of the list
only at the back of the list
either at the front or at the back of the list
at any position in the list

customers in a bank can be represented as a(n) ______.


list
queue
stack
array

Short Answer Questions:


82)
Define the problem of rightward
implementation of a queue.

drift in an array-based
14 of 15

MCSC502 Spring 2015

Test 2
Name:_____________________________

83)
If an object is inserted into a queue, how soon can it be
removed?

15 of 15

You might also like