Homework 14
CSSE 221 – Fundamentals of Software Development Honors
Fall 2008–2009
Recall the
Due Dates
and
(from the syllabus)
the
Late (and early) Assignment Policy
and guidelines for
maintaining Academic Integrity.
Also recall that you can get help on any of these problems during the
CSSE lab assistant hours,
and you can use the Assignments Discussion Forum
on Angel to discuss, clarify, or get help on these problems.
Things to do
- Continue working on your CarsTrucksTrains project,
using pair programming throughout (except for implementing
the Truck and Train classes, which you should do separately).
Strive to complete most of this project by the due date of this homework.
- Do the written problems below.
Written problems
Write your answers to these questions.
Turn your answers in via the appropriate Homework Drop Box on Angel.
- Fill in the blank in the most appropriate way:
17m5 + 200m4 + 300 is O(____________).
- Fill in the blank in the most appropriate way:
17r5 + 200r4 + 300 is O(____________).
- Fill in the blank in the most appropriate way:
3003 is O(____________).
- Fill in the blank in the most appropriate way:
40 2n is O(____________).
- Fill in the blank in the most appropriate way:
40n log n is O(____________).
- Fill in the blank in the most appropriate way:
40n log n2 is O(____________).
- Fill in the blank in the most appropriate way:
40n log2 n is O(____________).
- Which of the following is "smaller"?
O(n3) or O(n3.2)
- Which of the following is "smaller"?
O(n3) or O(2n)
- Which of the following is "smaller"?
O(n3) or O(n2log n)
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n; ++k) {
System.out.println("hello");
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n; ++k) {
for (int j = 20; j < 143; ++j) {
System.out.println("hello");
}
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < 200; ++k) {
for (int j = 20; j < 143; ++j) {
System.out.println("hello");
}
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n; ++k) {
for (int j = 0; j < n; ++j) {
System.out.println("hello");
}
for (int j = 0; j < n; ++j) {
System.out.println("hello");
}
for (int j = 0; j < n; ++j) {
System.out.println("hello");
}
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = n/2; k < n * 4; ++k) {
System.out.println("hello");
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n; ++k) {
for (int j = 0; j < k; ++j) {
System.out.println("hello");
}
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n * n; ++k) {
for (int j = 0; j < n * n * n; ++j) {
System.out.println("hello");
}
}
- What is the run-time of the following code snippet, in terms of n?
for (int k = 0; k < n * n * n; ++k) {
for (int j = 20; j < k; ++j) {
System.out.println("hello");
}
}
- A block of code is characterized as O(n)
and runs in 23 milliseconds on a certain input.
From this information alone, what would you estimate as the runtime of the code
if the size of the input were increased by a factor of 8?
- A block of code is characterized as O(n2)
and runs in 400 milliseconds on a certain input.
From this information alone, what would you estimate as the runtime of the code
if the size of the input were increased by a factor of 3?