Prime Number Detection: Running Time of Algorithm

  • Thread starter zak100
  • Start date
  • #1
zak100
462
11
TL;DR Summary
From the internet, I found that the running time of algorithm to find prime number is O(sqrt(N)).
I have 3 questions: Can we say that the running time is O(log^2N) for detection of Prime number? For large values of N, can we say that its a pseudo-polynomial algorithm? Is this true for Sorting algorithms also?

Zulfi.
Hi,

I want to know if the algorithm to find prime number has running time O(sqrt(N)) or O(log^2N). log^2N is better than sqrt(N). Also for large values can it become a pseudo polynomial algorithm?

Zulfi.
 

Answers and Replies

  • #2
41,324
18,944
From the internet, I found that the running time of algorithm to find prime number is O(sqrt(N)).

First, you need to give a specific reference; "from the internet" is not enough.

Second, there are multiple different possible algorithms for finding prime numbers; you need to say which one you are talking about. (Giving a reference will naturally help with that.)
 
  • #3
sysprog
2,611
1,783
The running time of primality testing is polynomial with respect to the size of the input -- it's not NP-complete or (worse-yet) NP-hard -- detecting whether a number is prime can be done in polynomial time -- https://en.wikipedia.org/wiki/Primality_test
 
Last edited:
  • #4
zak100
462
11
Hi,

Thanks for your response.
https://softwareengineering.stackex...f-the-algorithm-to-check-if-a-number-is-prime
In terms of magnitude of Number it is O(sqrt(N)) and also the worst case:but average case is O(sqrt(N))/log N.

What is your answer?

The running time of primality testing is polynomial with respect to the size of the input -- it's not NP-complete or (worse-yet) NP-hard -- detecting whether a number is prime can be done in polynomial time -
-
For some algorithms like knapsack, the running time changes from polynomial to pseudopolynomial when the input size is large, why is this different for prime number and sorting algorithms?

Zulfi.
 
  • #5
sysprog
2,611
1,783

Suggested for: Prime Number Detection: Running Time of Algorithm

Replies
0
Views
416
  • Last Post
Replies
14
Views
1K
Replies
6
Views
1K
Replies
46
Views
3K
  • Last Post
Replies
0
Views
366
Replies
4
Views
619
  • Last Post
Replies
0
Views
353
Replies
9
Views
791
Replies
0
Views
525
Replies
22
Views
541
Top