50% found this document useful (2 votes)
3K views

CS502 Assignment 1 Solution

1) The document describes an assignment to design a pseudocode algorithm to identify if a number is prime or not prime. 2) It asks to calculate the worst case time complexity T(n) of the algorithm. The answer provides that the algorithm tests all divisors up to the square root of n. 3) The time complexity is O(√nlog(n) log(log(n))log(log(log(n)))) or O(2^b/2 b logb loglogb) where b is the number of bits of the input number n.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
3K views

CS502 Assignment 1 Solution

1) The document describes an assignment to design a pseudocode algorithm to identify if a number is prime or not prime. 2) It asks to calculate the worst case time complexity T(n) of the algorithm. The answer provides that the algorithm tests all divisors up to the square root of n. 3) The time complexity is O(√nlog(n) log(log(n))log(log(log(n)))) or O(2^b/2 b logb loglogb) where b is the number of bits of the input number n.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS502 Assignment 1

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.

This gives a computational complexity of O(√𝑛log√𝑛log(log(√𝑛))loglog(log(√𝑛)))). We can


simplify this to O(√𝑛log(n) log(log(𝑛))log(log(log(𝑛)))).

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.

You might also like