Quiz 1
Quiz 1
1) (15 points)
Suppose that you have a box which contains n pairs of boots: m pairs of black
boots, k pairs of red and q pairs of brown. Moreover, 𝑛 = 𝑚 + 𝑘 + 𝑞 and 𝑞 < 𝑘 < 𝑚.
You are going to select in the dark and you can check only after selection was
made. What is the smallest number of boots that you can select to have AT LEAST
ONE matching pair in the best case? What about worst case scenario?
Your answers should be expressed in terms of m, k or q.
Hint 1: Boots can be right-handed and left-handed
Hint 2: Subsitute some numbers into m, k and q in order to see some intuition.
2) (15 points)
Order the following functions according to their order of growth (from the lowest
to the highest):
5𝑛 , 4√(𝑛 + 1), 60𝑙𝑛(𝑛 + 10)200, 1000𝑛5 + 900𝑛3 + 800𝑛2 + 𝑛 + 600,
33𝑛 + 2𝑛+1 + 𝑛, (𝑛 + 8)!, 𝑙𝑛3(𝑛 + 1), (𝑛 + 1)2
Show all your proofs.
3) (24 points)
Compute the following sums:
a) 2+4+6+8+10+…+998 (4 points)
b) ∑𝑛+3
𝑖=4 1 (4 points)
c) 3+9+27+81+243+…+531441 (4 points)
d) ∑𝑛+3
𝑖=4 𝑖 (4 points)
𝑛 (
e) ∑𝑖=1 𝑖 + 1)(𝑖 + 2) (4 points)
f) ∑𝑛𝑖=1 ∑𝑛𝑗=1 𝑖(𝑗 + 1) (4 points)
4) (24 points)
Suppose that you have the following “Unknown” algorithm.
Algorithm Unknown
Input: Array with n elements 𝐴[0. . 𝑛 − 1]
1. min_element ← 𝐴[0]; max_element ← 𝐴[0]
2. for i ← 1 to 𝑛 − 1
3. if 𝐴[𝑖] <min_element
4. min_element← 𝐴[𝑖]
5. if 𝐴[𝑖] >max_element
6. max_element← 𝐴[𝑖]
7. endfor
8. return (min_element / max_element) *100
5) * (30 points)
Suppose that you have 𝑛 pairs of men (M) and women (W). Logically, there are
𝑛/2 men and 𝑛/2 women. Initially they are located as it is shown in the Figure below:
But you can interchange or swap only two neighboring people and you can swap
only man with woman or woman with man.
a) Design an algorithm for solving this problem (10 points)
b) Determine the number of swaps, which you can have. Solve for general
situation, exactly for n pairs. So, you need to derive some formula. (10 points)
c) Running time of your algorithm in O notation. (10 points)
P.S Instruction how to submit: If you solved part d, you can submit via Moodle or Teams the
screenshoots of your program with .cpp, .c, .py or .java files
P.S.S That’s all about Quiz 1. I hope that you really enjoyed during solving these interesting problems and derived
some useful information for yourself. Thank you for your accurate reading and for your attention until the end.