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

CSIS-385: Algorithm Analysis - Exam 2, Exams of Algorithms and Programming

A computer science exam focused on algorithm analysis. It includes multiple-choice questions about various sorting algorithms, search algorithms, and recurrence relations. The exam also asks students to write algorithms for specific problems and analyze their running time.

Typology: Exams

Pre 2010

Uploaded on 08/09/2009

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

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS-385: Algorithm Analysis Exam 2 Name ________________________
1. What type of algorithm strategy is used in bubblesort? Answer ___________
2. What type of algorithm strategy is used in sequential search? Answer ___________
3. What type of algorithm strategy is used in insertion sort? Answer ___________
4. What are the two algorithm strategies that can be used to solve the closest pair problem and
what is the running time in terms of Big-O?
Strategy 1 ________________________ Running Time _______________
Strategy 2 ________________________ Running Time _______________
5. Describe the efficiency of computing an in terms of a lower bound, i.e., Omega(?). In other
words, what is the efficiency of the best algorithm for computing an?
Answer _______________
6. Given an unsorted list of size n, write an algorithm to find the kth smallest value? Your
algorithm must be O(n2) in the worst case. You can not use a sorting algorithm. Describe your
algorithm using pseudo-code or a precise step-by-step description.
Answer:
7. Given an unsorted list of size n, do you think it is possible to find the kth smallest value in
O(n) time. Justify your answer with a sentence or two.
Answer:
1 of 6
pf3
pf4
pf5

Partial preview of the text

Download CSIS-385: Algorithm Analysis - Exam 2 and more Exams Algorithms and Programming in PDF only on Docsity!

  1. What type of algorithm strategy is used in bubblesort? Answer ___________
  2. What type of algorithm strategy is used in sequential search? Answer ___________
  3. What type of algorithm strategy is used in insertion sort? Answer ___________
  4. What are the two algorithm strategies that can be used to solve the closest pair problem and what is the running time in terms of Big-O? Strategy 1 ________________________ Running Time _______________ Strategy 2 ________________________ Running Time _______________
  5. Describe the efficiency of computing an^ in terms of a lower bound, i.e., Omega(?). In other words, what is the efficiency of the best algorithm for computing an? Answer _______________
  6. Given an unsorted list of size n, write an algorithm to find the kth^ smallest value? Your algorithm must be O(n^2 ) in the worst case. You can not use a sorting algorithm. Describe your algorithm using pseudo-code or a precise step-by-step description. Answer:
  7. Given an unsorted list of size n, do you think it is possible to find the kth^ smallest value in O(n) time. Justify your answer with a sentence or two. Answer:
  1. Given a sorted array of integers (size n), write a sequential search algorithm that terminates (i) when the item is found and (ii) when you know the item can not be found. Describe your algorithm using pseudo-code or a precise step-by-step description. a. Answer: b. In the worst case , how many comparisons are performed? Answer ____________ c. In the best case , how many comparisons are performed? Answer ____________ d. In the average case , how many comparisons are performed in the algorithm above? (Circle the most correct answer) (a) We can not answer that question unless we know the order in which the integers are arranged? (b) Assuming the target values are random, it will take n/2 comparisons on average to find the target values. Thus, we can say O(n) time in the average case. (c) Since the algorithm terminates early, it is not a brute force algorithm and we can say that it will be O(1) in the average case. (d) Since the list is sorted the algorithm will take O(log n).
  1. Circle the most correct statement. (a) Solving the traveling salesman problem requires an exhaustive search algorithm that computes every possible subset of a given set of vertices. (b) Solving the traveling salesman problem requires a brute force algorithm that computes every combination of vertices. (c) Solving the traveling salesman problem requires an exhaustive search of all the different permutations of the vertices starting at a given position. (d) Solving the traveling salesman problem requires sorting each edge by its weight an then traversing them in order from smallest largest.
  2. Knapsack Problem: Given a capacity of 50 lbs and the following packages, Package A = 25 lbs. $ Package B = 30 lbs. $ Package C = 15 lbs. $ Package D = 35 lbs. $ Package E = 60 lbs. $ Package F = 45 lbs. $ a. How many possible subsets could be considered in the worst case? Answer __________ b. Considering the weights, how many subsets are actually considered? List them. Answer: c. Which subset produces the optimal solution? Answer __________ d. Does there exist a metric for ordering the packages that will lead to an optimal solution if we use an O(n) greedy strategy (i.e., we order the packages according to the metric--highest to lowest--and try to fit the highest packages first and continue until we’ve considered all the packages)? (Circle the most correct statement) (a) No such metric exists for any input. (b) Yes, but the metric is different for different sets of packages and there exists no efficient algorithm for determining the metric based on the input. (c) Yes, as the problem size reaches infinity the cost-to-weight ratio’s solution approaches the optimal solution. (d) No, if you fail to consider every subset there is no way you’ll compute the optimal solution.
  1. The following recurrence relations describe the running time of four different divide-and- conquer algorithms. What is the Big-O running time of each? Which one is the most efficient? (Circle one) (a) T(n) = 2T(n/4) + n^2 ; Answer : O( ________) (b) T(n) = 8T(n/2) + n; Answer : O( ________) (c) T(n) = T(n/4) + n^3 ; Answer : O( ________) (d) T(n) = 4T(n/2) + n^2 ; Answer : O( ________)
  2. Given a sorted linked list of size n? What is the best case running time for binary search? Answer________________
  3. Given the following array, [0] [1] [2] [3] [4] [5] [6] 4 7 9 1 3 5 2 and the following code, i = 0; j = 7; pivot = 0; for (;;) { while (a[++i] < a[pivot]); while (a[--j] > a[pivot]); if (i < j) swap( &a[i], &a[j] ); else break; } swap( &a[j], &a[pivot] ); Show the contents of the array after each swap.