Sie sind auf Seite 1von 6

IN2002 Data Structures and Algorithms (PRD1 A 2014/15)

Started on Saturday, 8 November 2014, 11:42 PM


State

Finished

Completed on Saturday, 8 November 2014, 11:44 PM


Time taken 1 min 37 secs
Marks

4.25/8.00

Grade

5.31 out of 10.00 (53%)

Feedback

You still need to improve your knowledge and skills.

Question 1
Correct
Mark 1.00 out of 1.00
Flag question

What is amortised time complexity of a function?


Select one:
a. The maximal time complexity over a number of calls to the function.
b. The overall of the time needed for a number calls to the function.
c. Do not know
d. The average time complexity over a number of calls to the function.
the average over a number of calls.

Yes, amortised means

e. The minimal time complexity over a number of calls to the function.

The correct answer is: The average time complexity over a number of calls to the function.

Question 2
Correct
Mark 1.00 out of 1.00

Flag question

The function foo operates on a linked list containing n > 1 elements. What is the time complexity of this
algorithm given in Pseudocode?
Function foo( list, x )

p <- list.head

WHILE NOT (p.next = null)

p <- p.next

p.next <- new Node(x)

Select one:
a. O(x)
b. O(n)
directly.

Yes, it will iterate over all n nodes in the list. It would be better to access the tail

c. O(log n)
d. O(log x)
e. Do not know

The correct answer is: O(n)

Question 3
Incorrect
Mark -0.25 out of 1.00
Flag question

What is the time complexity of adding an element at the head of a singly linked list of length n?
Select one:

a. O(log n)
b. O(n)

No, think of what needs to be done for adding at the head

c. Do not know
d. O(1)
e. O(n log n)

The correct answer is: O(1)

Question 4
Correct
Mark 1.00 out of 1.00
Flag question

What is the time complexity of appending an element at the tail of a singly linked list (with tail pointer)
of length n?
Select one:
1. O(n log n)
2. O(1)
pointers.

Yes, using the tail pointer, we just need to create a new node and rearrange two

3. Do not know
4. O(n)
5. O(log n)

The correct answer is: O(1)

Question 5
Correct
Mark 1.00 out of 1.00
Flag question

Function foo - given in Pseudocode below - operates on a singly linked list list containing n > 1
elements. How much additional memory is needed to execute it (additional meaning excluding the
memory consumed by list itself)?

Function foo( list, x ):


p <- list.head
WHILE NOT (p.next = null)
p <- p.next
p.next <- new Node(x)
Select one:
1. O(n log n).
2. Do not know
3. O(1).

Yes, foo only needs constant additional memory.

4. O(log n).
5. O(n).

The correct answer is: O(1).

Question 6
Incorrect
Mark -0.25 out of 1.00
Flag question

Consider this Java code (from lecture 5):


Mobile x = new Mobile(1234, +44 7887 4444444,Rupert);
Mobile y = new Mobile(1234, +44 7887 4444444,Rupert);
Mobile z = x;
Which of the following expressions will evaluate to false (assuming that compareTo compares the
objects' contents)?
Select one:
1. x != y

No, this will evaluate to true, as x points to a different object from y.

2. x.compareTo( z ) == 0
3. Do not know
4. x.compareTo( y ) == 0
5. x != z

The correct answer is: x != z

Question 7
Incorrect
Mark -0.25 out of 1.00
Flag question

Assume that list is a singly linked list with more than 1 element.
What does the following pseudocode do with list?
Function foo( list, x ):
p <- list.head
IF NOT(p = NULL) AND p.info = x THEN
list.head = p.next
WHILE NOT (p = null OR p.next = NULL)
IF p.next.info = x
p.next = p.next.next
ELSE p = p.next

Select one:
a. It stops when p.info = NULL.

No, the loop condition does not check the contents of p.info.

b. Do not know
c. It removes the last node containing x.
d. It removes the first node containing x.
e. It removes all nodes containing x.

The correct answer is: It removes all nodes containing x.

Question 8
Correct
Mark 1.00 out of 1.00
Flag question

Assume that list is a singly linked list with more n > 1 elements.
What is the time complexity of the following pseudocode?
Function foo( list, x ):
p <- list.head
IF NOT(p = NULL) AND p.info = x THEN
list.head = p.next

WHILE NOT (p = null OR p.next = NULL)


IF p.next.info = x
p.next = p.next.next
ELSE p = p.next

Select one:
a. O(n).

Yes, it does traverse the whole list.

b. O(log n).
c. O(n log n).
d. Do not know
e. O(1).

The correct answer is: O(n).

Finish review

Das könnte Ihnen auch gefallen