Assignment#1 Dbms
Assignment#1 Dbms
2) (10 points)
a) (5 points)
Write a recursive algorithm that return the sum of first 𝑛 terms of Fibbonachi
sequences:
Input 1: 𝑛 = 5
Output 1: 7 // because 0+1+1+2+3 = 7
Input 2: 𝑛 = -4
Output 2: “Enter positive n”
b) (5 points)
Write an iterative analogue of the above algorithm with the same condition
3) (15 points)
Write a recursive algorithm of calculating the sum of digits of given positive
or negative integer 𝑛. When solving this problem, you cannot use strings, lists, arrays
and cycles, of course.
Input 1: 𝑛 = 285
Output 1: 15 // 2+8+5 = 15
Input 2: 𝑛 = −18
Output 2: 9 // 1+ 8 = 9
Input 3: 𝑛 = 2.8
Output 3: “It is not integer. Please try again”
4) (20 points)
Suppose that you have the following recursive algorithm for finding sum of
two integers 𝑎 and 𝑏 without directly using “+” operator.
import java.util.Random;
public class BubbleSort {
public static int randomNumberInRange(int min, int max) {
Random random = new Random();
return random.nextInt((max - min) + 1) + min;
}
Processor
RAM
Type of system
Operating
System
b) (5 points)
By changing size of your array 𝑛, it is necessary to fulfill the following table:
𝑛 𝑇(𝑛) in ms
100
200
400
800
1600
3200
6400
12800
P.S Here it is expected that each student should have the unique table, because of
you are running on your personal computers and logically you will have different
computer characteristics. More generally, computers with high RAM can execute
the above code faster. Logically, low RAM computers should give you long
runnning time. But of course, there are also exists other characteristics as how many
parallel processes your computer runs and etc.
c) (5 points)
Now it is necessary to display the above table in terms of 2D-graph. Hint: for
example, I used MS Excel, you can see demonstration below:
You can use any tools for visualizing your graph: Python, Excel, yotx.ru and
etc. (it’s time for your creativity:))
P.S I hope that your graph more or less will have the same behaviour.
d) (5 points)
Then it is necessary to convert 𝑁 and 𝑇(𝑁) into log(𝑁) and log(𝑇(𝑁)). And
again display in terms of graph:
Figure 3 – 2D graph representation in terms of log-scale.
You can use any tools for visualizing your graph: Python, Excel, yotx.ru and
etc. (it’s time for your creativity:))
P.S I hope that your graph more or less will have the same behaviour.
e) (5 points)
Now, it is necessary to derive a hypothesis (mathematical model). And then
try to predict for 𝑛 = 25600. Now you have predicted value.
f) (2 points)
This step is related to V&V (verification and validation). It is necessary to run
your code for 𝑛 = 25600. By running your code and measuring time you can find
real value.
P.S If you have weak computer characteristics, please be patient because running process can take
some time (even up to 2 mins for example).
g) (3 points)
Accept or reject your hypothesis. As a main indicator you can take relative
error. If relative error does not exceed 10% then accept, otherwise reject. Hint:
|𝑝𝑟𝑒𝑑𝑖𝑐𝑡𝑒𝑑−𝑟𝑒𝑎𝑙|
𝑅𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝐸𝑟𝑟𝑜𝑟 = ∗ 100%
𝑟𝑒𝑎𝑙
That’s all about 1st Assignment. 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. If you have any questions, please do not hesitate to contact me
via MS Teams.
Kind Regards,
Ruslan Omirgaliyev
Senior-Lecturer of Department of Computer Engineering
Astana IT University