CS502 Assignment 1 Solution
CS502 Assignment 1 Solution
Statement:
In mathematics Prime is a number which can be only divisible by 1 and itself. Examples of prime
numbers are, 1 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 etc. When these numbers get large, then
it is very difficult to manually identify them as to be prime or not prime. For example the
numbers like, 443 and 44371 cannot easily identify as Prime.
Question No 01:
You are required to design (write) a simple algorithm (Only Pseudo code) which can identify a
number to be Prime or Not Prime.
Answer:
Question No 02:
You are required to calculate (Step by Step) the worst case time complexity T(n) of the
algorithm designed in Question No. 01.
Answer:
When ‘n’ is the input, we test √𝑛 divisors. However, we also have to take into account the
complexity of division itself. For a number with ‘b’ bits, this
takes O(𝑏 log 𝑏 log log 𝑏) operations, when we are using the Schönhage–Strassen algorithm.
Since half of the numbers below √𝑛 have log(√𝑛) digits, we may assume the all have this
1
amount of digits. It only matters a factor 2 at most, and that is absorbed in the O.
However, when notating it using the number of bits ‘b’ of a number, which is more standard
usage, we get a computational complexity of O(2𝑏/2 𝑏 𝑙𝑜𝑔𝑏 𝑙𝑜𝑔𝑙𝑜𝑔𝑏).
You also need to compute √𝑛 but that has only complexity O(blog blog logb) when using
Newton's method and the Schönhage-Strassen algorithm.