Professional Documents
Culture Documents
A. n = ( n)
B. n = ( n)
C. n = ( n)
D. n = O( n)
2 of 11
Page 2
3 of 11
11. (1pts) Let A be an ordered array of n numbers and capacity > n. The worst case complexity
of inserting an element x in its proper position is
A. O(1)
B. O(log n)
C. O(n log n)
D. O(n)
12. (1pts) The complexity of computing the expression xn is at most
A. O(1).
B. O(log n).
C. O(n).
D. O(n log n).
13. (1pts) In a stack the elements are accessed in (check all that apply)
A. First in first out
B. Last in first out
C. First in last out
D. Last in last out
14. (1pts) In a queue the elements are accessed in (check all that apply)
A. First in first out
B. Last in first out
C. First in last out
D. Last in last out
Page 3
4 of 11
15. (1pts) When comparing the doubly and singly linked list implementations we find the doubly
linked list implementation
A. Saves space at the expense of some additional time
B. Saves time on some operations at the expense of additional space
C. Saves neither space nor time but it is easier to implement.
D. Saves both space and time.
16. (1pts) When the sequence push(1),push(2),push(3),pop(),push(4),push(5),push(6),pop(),push(7)
the stack, from bottom(left) to top(right) will look like
A. 1,2,3,4,5
B. 1,2,4,5,7
C. 1,2,4,5,6
D. 1,3,5,6,7
17. (1pts) Let L be a linked-list and head be the pointer to its first node. The worst case complexity of printing the k th element given head is
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
18. (1pts) Let A[n] be an array. The worst case complexity of printing the k th element in an array
is
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Page 4
Page 5
5 of 11
6 of 11
Page 6
A. O(log2 n)
B. O(n log3 n)
C. O(n3 )
D. O(nlog2 3 )
Page 7
7 of 11
8 of 11
Page 8
9 of 11
30. (1pts) Let t be a pointer to a node. What is the complexity of finding the node that is previous
to t when using a singly-linked list
A. O(n log n)
B. O(n)
C. O(log n)
D. O(1)
Page 9
10 of 11
31. A list ADT is implemented as a singly-linked list of Nodes WITHOUT sentinel nodes. A node
is declared as
s t r u c t Node {
Node n e x t ;
int data ;
Node ( i n t x , Node n ) : d a t a ( x ) , n e x t ( n ) { }
};
The variable head is a pointer to the first node of the list. An empty list has head=NULL.
Also head is a global variable that is accessible by all functions including the ones you are
asked to write.
(a) (6pts) Write the C++ code for the function insert to insert a new value after a given
node whose pointer is t.You can assume that t is a valid pointer in the list.
(b) (6pts) Write the C++ code for the function erase to delete a node whose pointer is t.
You can assume that t is a valid pointer in the list.
Page 10
11 of 11
(c) (6pts) Write the C++ code for the function printPrevious to print the value of the node
previous to a given node whose pointer is t. You can assume that t is a valid pointer in
the list.
Page 11