CS 370 Exam 3/05/2014 Cierra Speight Answer “True” or “False”: 1

advertisement
CS 370 Exam 3/05/2014
Cierra Speight
Answer “True” or “False”:
1. A stack has at least these three operations: peek, pop, push.
2. A queue has at least these three operations: size, peek, pop, push.
3. A queue has two access points, head and tail.
4. A queue is a suitable structure to use for reversing the lines in a text file; just insert each line
until end-of-file is reached. Then remove each line until the queue is empty.
5. A stack is a suitable structure to for buffering input. Just insert each line until end-of-file is
reached. Then remove each line until the stack is empty.
6. The acronym "FIFO" stands for "Fast In Fast Out."
7. An array implementation of a queue is more difficult to manage than the array implementation
of a stack.
8. The linked list implementation of a queue is similar to that for a stack: always insert at the start
of the list.
9. A stack has two access points: front and back.
10. The array implementation of a stack is superior to the linked list implementation because the
array implementation's pop is faster.
11. The array implementation is inferior because we may have to recreate a larger array for the
data (or throw a stack full exception).
12. The linked list implementation requires that an object keep track of both its current size and
its capacity.
1 of 5
Multiple Choice
13. If the characters 'D', 'C', 'B', 'A' are placed in a stack (in that order), and then removed one at a
time, in what order will they be removed?
A. ABCD
B. ABDC
C. DCAB
D. DCBA
14. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a
time, in what order will they be removed?
A. ABCD
B. ABDC
C. DCAB
D. DCBA
15. I have implemented the queue with a linked list, keeping track of a front node and a rear node
with two reference variables. Which of these reference variables will change during an insertion
into an EMPTY queue?
A. Neither changes
B. Only front changes.
C. Only rear changes.
D. Both change.
16. Entries in a stack are "ordered". What is the meaning of this statement?
A. A collection of Stacks can be sorted.
B. Stack entries may be compared with the '<' operation.
C. The entries must be stored in a linked list.
D. There is a first entry, a second entry, and so on.
17. The operation for adding an entry to a stack is traditionally called:
A. add
B. append
C. insert
D. push
2 of 5
18. The operation for removing an entry from a stack is traditionally called:
A. delete
B. peek
C. pop
D. remove
Give the sum of each series.
19. n + (n-1) + (n-2) + (n-3) +...+ 3 + 2 + 1 =
20. n + n/2 + n/4 + n/8 +...+ 1
21. 1 + 2 + 4 + 8 +...+ n
22. 1 + 2 + 3 +...+ n
Prove using proof by induction.
23. N2 + N is divisible by 2
24. 2 + 4 + 6 +...+ 2N = N2 + N
25. Recursion. Write a recursive method that has one parameter which is an int value called x. The
method prints x asterisks, followed by x exclamation points. Do NOT use any loops. Do NOT
use any variables other than x
Eliminate recursion from the following function.
26.
int foo (int n) {
if (n < 3)
return n;
else
return foo ( 2*n/3);
}
3 of 5
Give the postifix expression for each of the following:
27. a + b * c - d / e
28. (f / g - h + i) * k
29. m - n / (p + r * s)
Evaluate the following postfix expressions
30.
31.
576- + 342- + *
68-75-42-39-+*+
Draw an expression tree for
32. the infix expression: a + b * c - d / e
33.
the postfix expression: 1 2 3 + - 4 5 6 * / +
Big-Oh analysis
34. What does it mean to say that a program runs in O(1) time?
35. Suppose an O(N) program runs for 10 msec with dataset of size 10. What's a good prediction
of the running time for datasize 20?
36. Suppose an O(N^2) program runs for 16 msec with dataset of size 4. What's a fair estimate of
the running time for datasize 10?
37. Put the following in order from smallest to largest
O(lg n)
O(n^2)
O(n)
O(1)
4 of 5
Give the big-Oh for the following
38.
int ffoo(int n) {
if (n==1)
return 0;
return ffoo(n/2)+1;
}
39.
int fbar(int n){
if (n < 2)
return n;
return fbar(n-1)+n;
}
40.What is the big-Oh for the infix calculator program? Discuss.
5 of 5
Download