Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Questions for Analysis of Algorithms - Quiz III | CSIS 385, Quizzes of Algorithms and Programming

Material Type: Quiz; Class: Analysis of Algorithms; Subject: Computer Science; University: Siena College; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 08/09/2009

koofers-user-5pt
koofers-user-5pt 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS-385: Quiz 3 Name____________________________________
1. Given the following code:
a and b are integers
n is the size of the input
basic_op is a basic operation
Mystery(a,b) {
if (a == b) {
for (x = 1 to n)
basic_op;
for (x = 1 to 2*n)
basic_op;
}
else {
for (x = 1 to n)
for (y = 1 to x)
basic_op;
}
}
a. What is the worst case running time,
i.e., f(n)=O(?)
Answer:
b. What is the best case running time,
i.e., f(n) = (?)
Answer:
c. Can we describe the average case
running time, i.e., f(n) = (?). If yes,
what is it? If no, explain why you can’t.
Answer:
2. Given the following code:
a and b are integers
n is the size of the input
basic_op is a basic operation
Mystery(a,b) {
if (a == b) {
for (x = 1 to n+n)
basic_op;
for (x = 1 to n*n)
basic_op;
}
else {
for (x = 1 to 10)
for (y = 1 to x)
basic_op;
}
}
a. What is the worst case running time,
i.e., f(n)=O(?)
Answer:
b. What is the best case running time,
i.e., f(n) = (?)
Answer:
c. Can we describe the average case
running time, i.e., f(n) = (?). If yes,
what is it? If no, explain why you can’t.
Answer:
pf3
pf4

Partial preview of the text

Download Questions for Analysis of Algorithms - Quiz III | CSIS 385 and more Quizzes Algorithms and Programming in PDF only on Docsity!

CSIS-385: Quiz 3 Name____________________________________

  1. Given the following code: a and b are integers n is the size of the input basic_op is a basic operation Mystery(a,b) { if (a == b) { for (x = 1 to n) basic_op; for (x = 1 to 2n)* basic_op; } else { for (x = 1 to n) for (y = 1 to x) basic_op; } } a. What is the worst case running time, i.e., f(n)=O(?) Answer : b. What is the best case running time, i.e., f(n) = (?) Answer : c. Can we describe the average case running time, i.e., f(n) = (?). If yes, what is it? If no, explain why you can’t. Answer:
    1. Given the following code: a and b are integers n is the size of the input basic_op is a basic operation Mystery(a,b) { if (a == b) { for (x = 1 to n+n) basic_op; for (x = 1 to nn)* basic_op; } else { for (x = 1 to 10) for (y = 1 to x) basic_op; } } a. What is the worst case running time, i.e., f(n)=O(?) Answer : b. What is the best case running time, i.e., f(n) = (?) Answer : c. Can we describe the average case running time, i.e., f(n) = (?). If yes, what is it? If no, explain why you can’t. Answer:
  1. What is the best (tightest) upper bound, i.e., f(n) = O(?) for the following functions?

a. 

n i f n n i 1 4 4 ( ) ( ) Answer : b. f^ ( n ) 12 n^4  15 n^3  21 n^2  28 n  35 Answer : c. (^2) 3 5 3 6 9 log 2 ( ) n n n n n f n  

Answer :

  1. State the definition of Big-O and then use it show convincing evidence that the following statements are either true or false. a. ) log ( 2 2 n n nO