Docsity

Exam Questions on Countable and Uncountable Sets, Algorithms, and Number Theory - Prof. Ro, Exams of Computer Science

Toggle sidebar
bg1
Sample Exam for Study Groups
1. Are the following sets countable or uncountable. If you say “countable,” please give a (rough outline
of a) bijection with the natural numbers. If you say “uncountable,” please give a proof.
a. The set of all finite sequences of letters from the set {A, B, C}, such as ABBAB,
BBBBBBBB, A, BBABACCCACBAC, CCC, etc...
b. The set of all infinite sequences of letters from the set {A, B, C}
c. The set of all infinite sequences of letters from the set {A, B} that contain only a finite
number of B’s. (This one is a bit tricky, and is too hard for the test. But you should be able
to do it with some help, and with all this time before the test.)
d. The set of integers
e. The set of rational numbers
2. Evaluate the following sums: Express each as either an integer or as a simple fraction.
a. 1 + 2 + 3 + 4 + ... + 80
b. 2 + 6 + 18 + 54 + 162 + ... + 118098
c. 312 + 322 + 332 + ... + 812
d. 1 + ½ + 1/4 + 1/8 + ... + 1/2048
e.
()ii
i
2
1
30
3
+
=
∑
Recall that an algorithm is a finite sequence of steps which will solve a given problem:
CEach step must be well-defined and deterministic
CEach step should take a finite amount of time
CThe algorithm must terminate after a finite number of steps (in a finite amount of time)
3. Which of the following are algorithms: For those that you say are not algorithms, say which of the
three principles cited above is violated
a. Given a list of integers:
i scan the list left-to-right and locate the greatest integer in the list.
ii Swap that integer with the first entry in the list.
iii Repeat steps i. and ii. until the greatest integer is the last element in the list
b. Given a list of integers a1, ..., an:
iSet found to false
ii Set k = 1
iii Consider the pair ak and ak+1. If ak < ak+1, then swap them and set found to true
iv If k < n – 1, then increment k and go to step ii.
vif found is true then go back to step i.
c. Given a positive integer n
iSet k = 0
ii If n is even, then cut it in half, otherwise triple it and add 1
iii Increment k
iv If n > 1 then go to step i.
For this problem, just give your best guess about what you think will happen. A sample
sequence of what happens, if n = 3, is 3 ! 10 ! 5 ! 16 ! 8 ! 4 ! 2 ! 1.
pf3

Partial preview of the text

Download Exam Questions on Countable and Uncountable Sets, Algorithms, and Number Theory - Prof. Ro and more Exams Computer Science in PDF only on Docsity!

Sample Exam for Study Groups

  1. Are the following sets countable or uncountable. If you say ìcountable,î please give a (rough outline of a) bijection with the natural numbers. If you say ìuncountable,î please give a proof. a. The set of all finite sequences of letters from the set {A, B, C}, such as ABBAB, BBBBBBBB, A, BBABACCCACBAC, CCC, etc... b. The set of all infinite sequences of letters from the set {A, B, C} c. The set of all infinite sequences of letters from the set {A, B} that contain only a finite number of Bís. (This one is a bit tricky, and is too hard for the test. But you should be able to do it with some help, and with all this time before the test.) d. The set of integers e. The set of rational numbers
  2. Evaluate the following sums: Express each as either an integer or as a simple fraction. a. 1 + 2 + 3 + 4 + ... + 80 b. 2 + 6 + 18 + 54 + 162 + ... + 118098 c. 312 + 32^2 + 33^2 + ... + 81 2 d. 1 + Ω + 1/4 + 1/8 + ... + 1/

e. (^) ( i i ) i

2 1

30

  • 3 =

Recall that an algorithm is a finite sequence of steps which will solve a given problem: C Each step must be well-defined and deterministic C Each step should take a finite amount of time C The algorithm must terminate after a finite number of steps (in a finite amount of time)

  1. Which of the following are algorithms: For those that you say are not algorithms, say which of the three principles cited above is violated a. Given a list of integers: i scan the list left-to-right and locate the greatest integer in the list. ii Swap that integer with the first entry in the list. iii Repeat steps i. and ii. until the greatest integer is the last element in the list

b. Given a list of integers a 1 , ..., an : i Set found to false ii Set k = 1 iii Consider the pair a (^) k and ak +1. If ak < ak +1, then swap them and set found to true iv If k < n ñ 1, then increment k and go to step ii. v if found is true then go back to step i.

c. Given a positive integer n i Set k = 0 ii If n is even, then cut it in half, otherwise triple it and add 1 iii Increment k iv If n > 1 then go to step i. For this problem, just give your best guess about what you think will happen. A sample sequence of what happens, if n = 3, is 3! 10! 5! 16! 8! 4! 2! 1.

d. Given an integer n > 1 which is congruent to 1 (mod 4): i Find all pairs of positive integers a and b , with a > b , such that a^2 + b^2 = n ii If there is exactly one such pair, then print ìPrimeî, otherwise print ìCompositeî

  1. For each of the parts of question 3 which you said gave algorithms, what were those algorithms supposed to accomplish?
  2. What is the time complexity of each of the parts of question 3 which you said were algorithms?
  3. Given a list of n integers, where n is even, what does the following algorithm do?
  4. What is the worst case number of steps performed by the algorithm above?
  5. Given a positive input integer n , what does the following algorithm do: (Hint: It prints a particular divisor of n ... which one?)
  6. Prove that the number of steps require in problem 8 is at most O(log 2 n ).
  7. Given a positive input integer n , what does the following algorithm do:
  8. What is the time complexity of the algorithm in problem 10?
  9. Give another algorithm to accomplish what the algorithm in problem 10 does but which is much better time complexity. Give an argument to show that yours will accomplish the same task.

pos = n / jump = 1 dir = 1 while ( pos < n ){ if ( apos mod 2 = 0){ print “Position =“ pos exit } else { pos = pos + dir * jump jump = jump + 1 dir = – dir } print “No even numbers in list” }

while n is even n = n / 2 print n

for a = 1 to n { for b = 1 to n { if a 2 + b 2 = n print a and b } }