|
Announcements
Check here periodically.
7/8/2014 |
Homework assigned.
To ask questions about the homework and see questions posed by other students
and their answers, go to:
https://piazza.com/wisc/summer2014/cs3672
and sign-in using your wisc.edu account. |
|
|
Questions
Homework assignments must be done individually. Collaboration on homework assignments is
not allowed.
Question 1:
Assume you are comparing three different algorithms to solve some problem and have determined
the worst-case time equations for each:
- Algorithm 1: T(N) = 48Nlog2N + 16N + 40
- Algorithm 2: T(N) = 2N2 + 4N + 32
- Algorithm 3: T(N) = 80N + 64
- What is the worst-case time complexity for each algorithm?
- Which algorithm has the lowest worst-case time complexity?
- Should the algorithm with the lower order of complexity always be used? Briefly explain why/why not?
Question 2:
Consider the following two code fragments:
Code fragment 1:
for (int k = list1.size() - 1; k >= 0; k--) {
list2.add(list1.remove(k));
}
Code fragment 2:
while (!list1.isEmpty()) {
list2.add(list1.remove(0));
}
In this question you will be asked to analyze the worst-case time complexity of each of the code fragments given different implementations of the List ADT. For each analysis, you should assume that list1 starts out with N items and list2 starts out empty. You may further assume that each implementation includes a numItems data member that is updated and used appropriately.
Express your complexities using "Big-O" notation and briefly justify your answers.
- Assume that list1 and list2 are ArrayLists where both arrays have enough unused space so that they never need to be resized during the operations performed by either of the code fragments.
- What is the worst-case time complexity of code fragment 1?
- What is the worst-case time complexity of code fragment 2?
- Assume that list1 and list2 are LinkedLists where the LinkedList class has been implemented as a circular, singly-linked chain of nodes with a reference to the tail.
- What is the worst-case time complexity of code fragment 1?
- What is the worst-case time complexity of code fragment 2?
- Assume that list1 and list2 are LinkedLists where the LinkedList class has been implemented as a doubly-linked chain of nodes with references to the head and to the tail.
- What is the worst-case time complexity of code fragment 1?
- What is the worst-case time complexity of code fragment 2?
|
|
Handing in
Please include your name at the top your file.
Put your answers to the questions into one file named Homework4 with the appropriate file extension, e.g., Homework4.pdf (see File Format for acceptable file formats).
Electronically submit your work to the Homework 4 Dropbox on Learn@UW.
|
Last Updated: 7/8/2014
© 2014 Beck Hasti
|