Prime Number Detection: Running Time of Algorithm

Click For Summary

Discussion Overview

The discussion revolves around the running time of algorithms for detecting prime numbers, exploring different complexities associated with various algorithms, including O(sqrt(N)) and O(log^2N). Participants also touch upon the implications of input size on algorithm performance, particularly in relation to polynomial and pseudo-polynomial classifications.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • Some participants propose that the running time for finding prime numbers is O(sqrt(N)), while others suggest that O(log^2N) may be better.
  • One participant notes that primality testing is polynomial with respect to input size and is not NP-complete or NP-hard.
  • Another participant mentions that the average case running time for primality testing can be O(sqrt(N))/log N.
  • There is a question raised about why algorithms like knapsack can change from polynomial to pseudo-polynomial with large input sizes, while prime number detection does not exhibit the same behavior.
  • The time complexity of the sieve of Eratosthenes is mentioned as O(n log log n), suggesting a different approach to prime detection.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the running time complexities of prime number detection algorithms, with multiple competing views presented regarding the classifications and implications of different algorithms.

Contextual Notes

Participants express uncertainty regarding the specific algorithms being referenced and the conditions under which different complexities apply. There are also unresolved questions about the relationship between input size and algorithm performance.

zak100
Messages
462
Reaction score
11
TL;DR
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.
 
Technology news on Phys.org
zak100 said:
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.)
 
  • Like
Likes   Reactions: sysprog
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:
  • Like
Likes   Reactions: Klystron
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.
 

Similar threads

Replies
14
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
7K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K