0% found this document useful (0 votes)
42 views

Quiz 1

This quiz contains 5 problems related to algorithms and data structures: 1. Finding the minimum number of boots that must be selected to guarantee at least one matching pair, given different quantities of black, red, and brown boots. 2. Ordering functions by growth rate from slowest to fastest. 3. Computing the sums of several expressions. 4. Analyzing an unknown algorithm that finds the minimum and maximum elements of an array, and returns their ratio. 5. Designing an algorithm to rearrange pairs of men and women from an initial to final configuration by swapping neighboring pairs, and determining the number of swaps needed.

Uploaded by

Adilzhan Kenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Quiz 1

This quiz contains 5 problems related to algorithms and data structures: 1. Finding the minimum number of boots that must be selected to guarantee at least one matching pair, given different quantities of black, red, and brown boots. 2. Ordering functions by growth rate from slowest to fastest. 3. Computing the sums of several expressions. 4. Analyzing an unknown algorithm that finds the minimum and maximum elements of an array, and returns their ratio. 5. Designing an algorithm to rearrange pairs of men and women from an initial to final configuration by swapping neighboring pairs, and determining the number of swaps needed.

Uploaded by

Adilzhan Kenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Quiz 1

Design and Analysis of Algorithms


Dear Ladies and Gentlemen! Good Luck!
1st variant

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

a) What does this algorithm do? (3 points)


b) What is its basic operation? (3 points)
c) How may times the basic operation is executed? (9 points)
d) Running time of your algorithm? (9 points)

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:

Your main task it to reach the following result:

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)

d) Bonus task: (10 points)


Write a code in any programming language like C, C++, Java or Python for this
algorithm, and also show the number of swaps for particular 𝑛 and then prove that the
formula which were derive in part b) is correct.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy