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

21 Multiple Choice - Algorithm Design and Programming II | CMP_SC 2050, Exams of Computer Science

Material Type: Exam; Professor: Uhlmann; Class: Algorithm Design and Programming II; Subject: Computer Science; University: University of Missouri - Columbia; Term: Fall 2009;

Typology: Exams

2010/2011

Uploaded on 02/28/2011

kingrah2009
kingrah2009 🇺🇸

12 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS2050 Exam 1 F09
Instructions: Mark the single best answer for each of the following questions. Although there are 23
questions, the exam will be scored out of a maximum of 20 points.
1. What is the complexity to read N integers from a file and write half of the integers into a file and the
other half of the integers into another file?
(1) O(N) (2) O(N4/3) (3) O(N1.5) (4) O(N2) (5) O(N2.5)
2. An algorithm reads a list of N cities from a file in O(N) time. Then it computes the distances between
each pair of cities in O(N2) time. Lastly, it creates a 2D array in which the entry in row i and column j
gives the distance between city i and city j. How does the overall running time of the algorithm scale
with N?
(1) O(N) (2) O(N2) (3) O(N3) (4) O(N4) (5) O(N5)
3. What is the space complexity of the previous algorithm, i.e., how much memory does it use?
(1) O(N) (2) O(N2) (3) O(N3) (4) O(N4) (5) O(N5)
4. What is the complexity to find the largest key and the smallest key in an array of size N?
(1) O(1) (2) O(2) (3) O(N) (4) O(N2) (5) O(2N)
5. What is the complexity to determine if the sum of the first k elements of an array of size N is greater
than the sum of last k elements of the array?
(1) O(1) (2) O(k) (3) O(N) (4) O(k+N) (5) O(k2)
6. Given an NxN 2dimensional array, what is the complexity to print the elements in the first row?
(1) O(1) (2) O(N1/2) (3) O(N) (4) O(N2) (5) O(2N)
7. What is the complexity to identify and print the four largest integers in an array of size N?
(1) O(1) (2) O(N1/4) (3) O(N) (4) O(N2) (5) O(N4)
8. Given an array of M objects, what is the complexity to determine how many of the M objects are in
another array of size N?
(1) O(M) (2) O(N) (3) O(M+N) (4) O(M*N) (5) O(NM)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download 21 Multiple Choice - Algorithm Design and Programming II | CMP_SC 2050 and more Exams Computer Science in PDF only on Docsity!

CS‐ 2050 Exam 1 F

Instructions: Mark the single best answer for each of the following questions. Although there are 23 questions, the exam will be scored out of a maximum of 20 points.

  1. What is the complexity to read N integers from a file and write half of the integers into a file and the other half of the integers into another file? (1) O(N) (2) O(N4/3^ ) (3) O(N 1.5) (4) O(N 2 ) (5) O(N 2.5^ )
  2. An algorithm reads a list of N cities from a file in O(N) time. Then it computes the distances between each pair of cities in O(N 2 ) time. Lastly, it creates a 2D array in which the entry in row i and column j gives the distance between city i and city j. How does the overall running time of the algorithm scale with N? (1) O(N) (2) O(N 2 ) (3) O(N 3 ) (4) O(N 4 ) (5) O(N 5 )
  3. What is the space complexity of the previous algorithm, i.e., how much memory does it use? (1) O(N) (2) O(N 2 ) (3) O(N 3 ) (4) O(N 4 ) (5) O(N 5 )
  4. What is the complexity to find the largest key and the smallest key in an array of size N? (1) O(1) (2) O(2) (3) O(N) (4) O(N 2 ) (5) O(2 N^ )
  5. What is the complexity to determine if the sum of the first k elements of an array of size N is greater than the sum of last k elements of the array? (1) O(1) (2) O( k ) (3) O(N) (4) O( k +N) (5) O( k^2 )
  6. Given an NxN 2‐dimensional array, what is the complexity to print the elements in the first row? (1) O(1) (2) O(N 1/2) (3) O(N) (4) O(N 2 ) (5) O(2 N^ )
  7. What is the complexity to identify and print the four largest integers in an array of size N? (1) O(1) (2) O(N 1/4) (3) O(N) (4) O(N 2 ) (5) O(N 4 )
  8. Given an array of M objects, what is the complexity to determine how many of the M objects are in another array of size N? (1) O(M) (2) O(N) (3) O(M+N) (4) O(M*N) (5) O(N M)
  1. What is the complexity for the previous question if the array of size N is sorted? (1) O(log(N)) (2) O(M+log(N)) (3) O(Mlog(N)) (4) O(log(M)log(N)) (5) Sorted order doesn’t change the complexity, so the answer to the previous question still holds.
  2. Given a sorted array of size P and another sorted array of size S, what is the complexity to determine if a given key is in either of the two arrays? (1) O(log(P)+log(S)) (2) O(log(P)log(S)) (3) O(Plog(S) + Slog(P)) (4) O(Plog(P) + Slog(S)) (5) O((P+S)(log(P)+log(S)))
  3. Given three sorted arrays of size N, what is the complexity to determine if a given integer is in any of the three arrays? (1) O(log(N)) (2) O((log(N)) 3 ) (3) O(N*(log(N)) 2 ) (4) O(N^2 *log(N)) (5) O(N 3 )
  4. Alfred Snozzer is one of the world’s most respected wine sniffers. With one small sniff of a barrel of fermenting wine he can assess its level of maturity. Given M barrels of wine, each containing N gallons of wine, how many sniffs must Mr. Snozzer perform to determine which barrels are mature and ready for sale? (1) O(M) (2) O(N) (3) O(M+N) (4) O(M*N) (5) O(N M^ )
  5. Given a sorted array of N integers, what is the complexity to determine whether the median value is closer to the minimum value in the array or to the largest value in the array? (Note that the median, minimum, and largest values must be found.) (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N 2 )
  6. What is the answer to the previous question if “median” is replaced with “mean” (i.e., “average”)? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N 2 )
  7. Given a sorted array of N integers, what is the complexity of a binary search for the number 714 if the number is not in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N 2 )
  8. Given a sorted array of N integers, what is the complexity to find the smallest even, i.e., divisible by 2, number in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N 2 )

CS‐ 2050 Exam 1 F

Instructions: Mark the single best answer for each of the following questions. Although there are 23 questions, the exam will be scored out of a maximum of 20 points.

  1. What is the complexity to read N integers from a file and write half of the integers into a file and the other half of the integers into another file? *(1) O(N) (2) O(N 4/3^ ) (3) O(N 1.5) (4) O(N 2 ) (5) O(N 2.5)
  2. An algorithm reads a list of N cities from a file in O(N) time. Then it computes the distances between each pair of cities in O(N 2 ) time. Lastly, it creates a 2D array in which the entry in row i and column j gives the distance between city i and city j. How does the overall running time of the algorithm scale with N? (1) O(N) *(2) O(N 2 ) (3) O(N^3 ) (4) O(N 4 ) (5) O(N 5 )
  3. What is the space complexity of the previous algorithm, i.e., how much memory does it use? (1) O(N) *(2) O(N 2 ) (3) O(N^3 ) (4) O(N 4 ) (5) O(N 5 )
  4. What is the complexity to find the largest key and the smallest key in an array of size N? (1) O(1) (2) O(2) *(3) O(N) (4) O(N 2 ) (5) O(2 N^ )
  5. What is the complexity to determine if the sum of the first k elements of an array of size N is greater than the sum of last k elements of the array? (1) O(1) *(2) O( k ) (3) O(N) (4) O( k +N) (5) O( k^2 )
  6. Given an NxN 2‐dimensional array, what is the complexity to print the elements in the first row? (1) O(1) (2) O(N 1/2) *(3) O(N) (4) O(N 2 ) (5) O(2 N^ )
  7. What is the complexity to identify and print the four largest integers in an array of size N? (1) O(1) (2) O(N 1/4) *(3) O(N) (4) O(N 2 ) (5) O(N 4 )
  8. Given an array of M objects, what is the complexity to determine how many of the M objects are in another array of size N? (1) O(M) (2) O(N) (3) O(M+N) (4) O(MN) (5) O(N M)
  1. What is the complexity for the previous question if the array of size N is sorted? (1) O(log(N)) (2) O(M+log(N)) (3) O(Mlog(N)) (4) O(log(M)*log(N)) (5) Sorted order doesn’t change the complexity, so the answer to the previous question still holds.
  2. Given a sorted array of size P and another sorted array of size S, what is the complexity to determine if a given key is in either of the two arrays? (1) O(log(P)+log(S)) (2) O(log(P)log(S)) (3) O(Plog(S) + Slog(P)) (4) O(Plog(P) + Slog(S)) (5) O((P+S)*(log(P)+log(S)))
  3. Given three sorted arrays of size N, what is the complexity to determine if a given integer is in any of the three arrays? (1) O(log(N)) (2) O((log(N)) 3 ) (3) O(N(log(N)) 2 ) (4) O(N 2 *log(N)) (5) O(N 3 )
  4. Alfred Snozzer is one of the world’s most respected wine sniffers. With one small sniff of a barrel of fermenting wine he can assess its level of maturity. Given M barrels of wine, each containing N gallons of wine, how many sniffs must Mr. Snozzer perform to determine which barrels are mature and ready for sale? (1) O(M) (2) O(N) (3) O(M+N) (4) O(MN) (5) O(N M^ )
  5. Given a sorted array of N integers, what is the complexity to determine whether the median value is closer to the minimum value in the array or to the largest value in the array? (Note that the median, minimum, and largest values must be found.) (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N 2 )
  6. What is the answer to the previous question if “median” is replaced with “mean” (i.e., “average”)? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N 2 )
  7. Given a sorted array of N integers, what is the complexity of a binary search for the number 714 if the number is not in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N 2 )
  8. Given a sorted array of N integers, what is the complexity to find the smallest even, i.e., divisible by 2, number in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N 2 )

CS‐ 2050 Exam 1 September 19, 2008

Directions : Mark the single best answer for each of the following questions. Do not make assumptions that are not explicitly stated in the question (e.g., don’t assume an array is sorted unless the question states that it is sorted).

  1. Given a sorted array of size N, what is the complexity to print the middle third of the elements (i.e., not the first third nor the last third of the array)? (1) O(1) (2) O(N 1/3 ) (3) O(N/3) (4) O(2*N/3) (5) O(N)
  2. Given N integers in an array, what is the complexity to identify and print all of the integers that are divisible by 5? (1) O(1) (2) O(N) (3) O(N*log(N)) (4) O(N^2 ) (5) O(N^5 )
  3. What is the answer to the previous question if the array is sorted? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  4. Given N integers in an array, what is the complexity to identify and print a message for every occurrence of the number 2? (Note that there may be multiple occurrences of the same integer) (1) O(1) (2) O(N) (3) O(N*log(N)) (4) O(N^2 ) (5) O(2 N )
  5. What is answer to the previous question if the array is sorted? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  6. What is answer to the previous question if the array is sorted and it is known that there are O(1) occurrences of the number 2 in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  7. What is the complexity to compute the mean of a set of integers stored in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  8. What is the complexity to compute the mean of a set of integers stored in sorted order in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  9. What is the complexity to compute the median of a set of integers stored in sorted order in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  1. Given N integers in an array, what is the complexity to identify and print all the values greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  2. What is the answer to the previous question if it is known that there are O(1) values in the array that are greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  3. Given N integers stored in sorted order in an array, what is the complexity to identify and print all of the values greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  4. What is the answer to the previous question if it is known that there are O(1) values in the array that are greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  5. Suppose you are given a sorted array of N real (i.e., non‐integer) numbers and are told that less than one percent of the numbers are less than the number 3.1415. What is the complexity to identify and print the values that are greater than 3.1415? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  6. What is the answer to the previous question if you are to print the values that are less than 3.1415? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  7. Given an array of N integers in ascending sorted order, what is the complexity to change the order of the values so that they are sorted in descending order? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  8. Given an array of N integers in ascending sorted order, what is the complexity required to determine if the number 8192 is in the array? (Note that there may be multiple occurrences of the same integer) (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )
  9. What is the answer to the previous question if it is only necessary to determine whether the number 8192 is not in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )

CS‐ 2050 Exam 1 September 19, 2008

Directions : Mark the single best answer for each of the following questions. Do not make assumptions that are not explicitly stated in the question (e.g., don’t assume an array is sorted unless the question states that it is sorted).

  1. Given a sorted array of size N, what is the complexity to print the middle third of the elements (i.e., not the first third nor the last third of the array)? (1) O(1) (2) O(N 1/3 ) (3) O(N/3) (4) O(2*N/3) *(5) O(N)
  2. Given N integers in an array, what is the complexity to identify and print all of the integers that are divisible by 5? (1) O(1) (2) O(N) (3) O(Nlog(N)) (4) O(N^2 ) (5) O(N^5 )
  3. What is the answer to the previous question if the array is sorted? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  4. Given N integers in an array, what is the complexity to identify and print a message for every occurrence of the number 2? (Note that there may be multiple occurrences of the same integer) (1) O(1) (2) O(N) (3) O(Nlog(N)) (4) O(N^2 ) (5) O(2 N )
  5. What is answer to the previous question if the array is sorted? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  6. What is answer to the previous question if the array is sorted and it is known that there are O(1) occurrences of the number 2 in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  7. What is the complexity to compute the mean of a set of integers stored in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  8. What is the complexity to compute the mean of a set of integers stored in sorted order in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  9. What is the complexity to compute the median of a set of integers stored in sorted order in an array of size N? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  1. Given N integers in an array, what is the complexity to identify and print all the values greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  2. What is the answer to the previous question if it is known that there are O(1) values in the array that are greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  3. Given N integers stored in sorted order in an array, what is the complexity to identify and print all of the values greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  4. What is the answer to the previous question if it is known that there are O(1) values in the array that are greater than 1000? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  5. Suppose you are given a sorted array of N real (i.e., non‐integer) numbers and are told that less than one percent of the numbers are less than the number 3.1415. What is the complexity to identify and print the values that are greater than 3.1415? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  6. What is the answer to the previous question if you are to print the values that are less than 3.1415? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  7. Given an array of N integers in ascending sorted order, what is the complexity to change the order of the values so that they are sorted in descending order? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  8. Given an array of N integers in ascending sorted order, what is the complexity required to determine if the number 8192 is in the array? (Note that there may be multiple occurrences of the same integer) (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )
  9. What is the answer to the previous question if it is only necessary to determine whether the number 8192 is not in the array? (1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )

CS-2050 Exam 1 22 February 2008

Instructions: Mark the single best answer for each of the following questions. Assume that thevariable N represents the size of the dataset in question unless otherwise stated.

1. Given an integer array of size N (not necessarily sorted) and integer parameters min and max ,

what is the complexity to determine if min and max are both in the array?

(1) O(1) (2) O(N1/2^ ) (3) O(N) (4) O(N 2 ) (5) O(2N)

2. What is the complexity for the previous question if the array is sorted?

(1) O(1) (2) O(log(N)) (3) O((log(N))^2 ) (4) O(N) (5) O(2log(N))

3. What is the overall complexity required to read N integers from a file, put them into an array,

and then determine if the first integer in the array is duplicated elsewhere in the array?

(1) O(N) (2) O(N^2 ) (3) O(N^3 ) (4) O(N^4 ) (5) O(2 N)

4. What is the complexity to find and print the minimum value, median value, and maximum

value from a sorted array of size N?

(1) O(1) (2) O(log(N)) (3) O((log(N))^3 ) (4) O(N) (5) O(N^3 )

5. Given one integer array of size M, and another integer array of size N, what is the complexity

required to determine if the number 32 is in either array?

(1) O(M) (2) O(N) (3) O(M+N) (4) O(MN) (5) O((M N) 1/2^ )

6. What is the complexity to read P character strings, each of which has O(S) characters, from a

file?

(1) O(P) (2) O(S) (3) O(P+S) (4) O(P*S) (5) O(P S^ )

7. Suppose you are to write a method that takes a parameter k and an array of size N and printsall the values in the array that are less than k. What is the complexity of the method?

(1) O(k) (2) O(N) (3) O(k+N) (4) O(k*N) (5) O(N k^ )

8. What is the complexity required to print the first 2% of the elements of an array of size N

followed by the last 2% of the elements?

(1) O(1) (2) O(N0.02^ ) (3) O(N/50) (4) O(N) (5) O(N 2 )

9. Given a 2-dimensional array with N columns and 2*N rows, what is the complexity to

compute and print the sums of all of the rows?

(1) O(N) (2) O(N 2 ) (3) O(2*N^2 ) (4) O(N 3 ) (5) O(N 4 )

10. Assuming that the array of the previous question has a total of M elements, what is the

complexity required to print all the elements in the third row?

(1) O(1) (2) O(M 1/3^ ) (3) O(M 1/2) (4) O(M) (5) O(M 2 )

11. Suppose that N is greater than a billion for the array of the previous two questions. What is

the complexity required to print the first million elements of each row?

(1) O(1) (2) O(N 1/2^ ) (3) O(N) (4) O(N^2 ) (5) O(P)

12. What is the complexity of the following pseudocode?

sumfor =(i=0; 0; i < N; i += 1000) { for (j=1000;sum += i*j; j > 0; j -= 10) { } }

(1) O(1) (2) O(N 1/1000) (3) O(N1/100^ ) (4) O(N) (5) O(N 2 )

13. Given a sorted array of N real values, what is the complexity to print all the values in the

array that are greater than 284.33?

(1) O(1) (2) O(log(N)) (3) O(N) (4) O(N*log(N)) (5) O(N^2 )

14. Given an array containing N objects and a method for determining if two objects are

identical, what is the complexity required to determine if there are any duplicates in the array?

(1) O(1) (2) O(log(N)) (3) O(N) (4) O(N^2 ) (5) O(2 N)

15. Given a sorted array of size N, what is the complexity to print the first N1/2^ and last N1/

elements?

(1) O(log(N)) (2) O(N 1/2^ ) (3) O(N1/2^ log(N)) (4) O(N) (5) O(Nlog(N))

16. Given an integer N and an integer P, what is the complexity required to determine if N is

divisible by P?

(1) O(1) (2) O(N) (3) O(P) (4) O(N+P) (5) O(N*P)

17. Given a positive integer M, what is the complexity to print all of the positive, even integersthat are less than M?

(1) O(1) (2) O(M1/2^ ) (3) O(M) (4) O(M^2 ) (5) O(2M)

18. Given a 2-dimensional integer array with N rows and 2 columns, what is the complexity

required to determine if the number 714 is in the array?

(1) O(N) (2) O(N 2 ) (3) O(N^4 ) (4) O(2 N) (5) O(4 N)

CS-2050 Exam 1 22 February 2008

Instructions: Mark the single best answer for each of the following questions. Assume that thevariable N represents the size of the dataset in question unless otherwise stated.

1. Given an integer array of size N (not necessarily sorted) and integer parameters min and max ,

what is the complexity to determine if min and max are both in the array?

(1) O(1) (2) O(N1/2^ ) *(3) O(N) (4) O(N^2 ) (5) O(2 N)

2. What is the complexity for the previous question if the array is sorted?

*(1) O(1) *(2) O(log(N)) (3) O((log(N)) 2 ) (4) O(N) (5) O(2 log(N))

3. What is the overall complexity required to read N integers from a file, put them into an array,

and then determine if the first integer in the array is duplicated elsewhere in the array?

*(1) O(N) (2) O(N^2 ) (3) O(N^3 ) (4) O(N^4 ) (5) O(2 N)

4. What is the complexity to find and print the minimum value, median value, and maximum

value from a sorted array of size N?

*(1) O(1) (2) O(log(N)) (3) O((log(N)) 3 ) (4) O(N) (5) O(N 3 )

5. Given one integer array of size M, and another integer array of size N, what is the complexity

required to determine if the number 32 is in either array?

(1) O(M) (2) O(N) (3) O(M+N) (4) O(MN) (5) O((M* N) 1/2^ )

6. What is the complexity to read P character strings, each of which has O(S) characters, from a

file?

(1) O(P) (2) O(S) (3) O(P+S) (4) O(PS) (5) O(P S^ )

7. Suppose you are to write a method that takes a parameter k and an array of size N and printsall the values in the array that are less than k. What is the complexity of the method?

(1) O(k) (2) O(N) (3) O(k+N) (4) O(kN) (5) O(Nk^ )

8. What is the complexity required to print the first 2% of the elements of an array of size N

followed by the last 2% of the elements?

(1) O(1) (2) O(N0.02^ ) (3) O(N/50) *(4) O(N) (5) O(N^2 )

9. Given a 2-dimensional array with N columns and 2*N rows, what is the complexity to

compute and print the sums of all of the rows?

(1) O(N) (2) O(N 2 ) (3) O(2N^2 ) (4) O(N 3 ) (5) O(N^4 )

10. Assuming that the array of the previous question has a total of M elements, what is the

complexity required to print all the elements in the third row?

(1) O(1) (2) O(M 1/3^ ) *(3) O(M 1/2^ ) (4) O(M) (5) O(M 2 )

11. Suppose that N is greater than a billion for the array of the previous two questions. What is

the complexity required to print the first million elements of each row?

(1) O(1) (2) O(N 1/2^ ) *(3) O(N) (4) O(N^2 ) (5) O(P)

12. What is the complexity of the following pseudocode?

sumfor =(i=0; 0; i < N; i += 1000) { for (j=1000;sum += i*j; j > 0; j -= 10) { } }

(1) O(1) (2) O(N 1/1000) (3) O(N1/100^ ) *(4) O(N) (5) O(N 2 )

13. Given a sorted array of N real values, what is the complexity to print all the values in the

array that are greater than 284.33?

(1) O(1) (2) O(log(N)) (3) O(N) (4) O(Nlog(N)) (5) O(N^2 )

14. Given an array containing N objects and a method for determining if two objects are

identical, what is the complexity required to determine if there are any duplicates in the array?

(1) O(1) (2) O(log(N)) (3) O(N) *(4) O(N 2 ) (5) O(2 N)

15. Given a sorted array of size N, what is the complexity to print the first N1/2^ and last N1/

elements?

(1) O(log(N)) *(2) O(N1/2^ ) (3) O(N1/2^ log(N)) (4) O(N) (5) O(Nlog(N))

16. Given an integer N and an integer P, what is the complexity required to determine if N is

divisible by P?

(1) O(1) (2) O(N) (3) O(P) (4) O(N+P) (5) O(NP)

17. Given a positive integer M, what is the complexity to print all of the positive, even integersthat are less than M?

(1) O(1) (2) O(M1/2^ ) *(3) O(M) (4) O(M^2 ) (5) O(2M)

18. Given a 2-dimensional integer array with N rows and 2 columns, what is the complexity

required to determine if the number 714 is in the array?

*(1) O(N) (2) O(N^2 ) (3) O(N 4 ) (4) O(2N) (5) O(4 N)

CS 2050 - Exam 1 - 14 September 2007

Instructions: Mark the single best answer for each of the following 21 questions. Do not makeany assumptions not explicitly stated in the question, e.g., don't assume an array is sorted unless

the question says so. For the purposes of this exam it should be assumed that files must be read

sequentially. The exam will be scored out of 20, so you can miss one question and still get a

perfect score.

1. Suppose that you are given an array of N integers. What is the complexity required to print the

first 100 elements (i.e., integers at array indices 0-99)?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

2. In the array of the previous question, what is the complexity to print values at array indices

that are divisible by 257?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

3. In the array of the previous questions, what is the complexity to print the first, middle, and last

elements?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

4. In the array of the previous questions, what is the complexity to print elements with odd (notdivisible by 2) indices?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

5. In the array of the previous questions, what is the complexity to print elements with odd (not

divisible by 2) indices followed by the elements with even indices?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

6. In the array of the previous questions, what is the complexity to determine how many of the

integers are less than 23?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

7. In the array of the previous questions, what is the complexity to determine how many of the

integers are less than N/2?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

8. In the array of the previous questions, what is the complexity required to determine if the

number 714 is included in the first 1000 elements of the array or the last 1000 elements?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

9. Suppose the array of the previous questions is sorted, what is the complexity to determinewhether or not all of the keys are identical?

(1) O(1) (2) O(log(N)) (3) O(N1/2^ ) (4) O(N) (5) O(N^2 )

10. What is the complexity to read a file containing 1000 lines of data with 100 integers per line?

(1) O(1) (2) O(100) (3) O(1000) (4) O(100,000) (5) O(N^2 )

11. What is the complexity to read a file containing 1000 lines of data with N integers per line?

(1) O(1) (2) O(1000) (3) O(N) (4) O(1000*N) (5) O(N^2 )

12. What is the complexity to read a file containing N lines of data with 1000 integers per line?

(1) O(1) (2) O(1000) (3) O(N) (4) O(1000*N) (5) O(N^2 )

13. What is the complexity to read a file containing N lines of data with N integers per line?

(1) O(1) (2) O(N 1/2^ ) (3) O(N) (4) O(N^2 ) (5) O(N N)

14. What is the complexity to read M files, each containing N lines with P integers per line?

(1) O(MN) (2) O(MP) (3) O(NP) (4) O(M(N+P)) (5) O(MNP)

15. Given the files in the previous question, what is the complexity required to print only theintegers in the first line of each file?

(1) O(MN) (2) O(MP) (3) O(NP) (4) O(M(N+P)) (5) O(MNP)

16. Given the files in the previous two questions, what is the complexity required to print only

the integers in the first file?

(1) O(MN) (2) O(MP) (3) O(NP) (4) O(M(N+P)) (5) O(MNP)

17. Assuming that files must be read sequentially, what is the complexity required to identify and

print only the last integer in each of the files of the previous three questions?

(1) O(M) (2) O(MN) (3) O(MP) (4) O(NP) (5) O(MN*P)

18. Suppose that you are hired by the Computer Dating Services of America (CDSA), a

consortium of computer dating companies. The CDSA tasks you to develop a Java program thattakes as input an array of N questionnaire objects, each of which contains an array of answers to

P "compatibility" questions for a particular person. Your program must determine if any two

people answered all questions identically and thus are "perfectly compatible". What is the

complexity required to do this?

(1) O(N) (2) O(N*P) (3) O(N 2 P) (4) O(NP^2 ) (5) O(N^2 *P^2 )