0
0
DSA Pythonprogramming~5 mins

Check if Number is Prime in DSA Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a prime number?
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Click to reveal answer
intermediate
Why do we only check divisors up to the square root of a number when testing for primality?
Because if a number has a divisor larger than its square root, it must also have a smaller divisor below the square root. So checking up to the square root is enough to find any divisor.
Click to reveal answer
beginner
What is the simplest method to check if a number is prime?
Try dividing the number by all integers from 2 up to the number minus one. If none divide evenly, the number is prime.
Click to reveal answer
beginner
What should you return if the number is less than 2 when checking for primality?
Return False because numbers less than 2 are not prime by definition.
Click to reveal answer
advanced
How can you improve the efficiency of prime checking beyond checking all numbers up to sqrt(n)?
You can skip even numbers after checking 2, or use advanced methods like the Sieve of Eratosthenes or probabilistic tests for large numbers.
Click to reveal answer
Which number is NOT a prime number?
A2
B3
C4
D5
When checking if a number n is prime, up to which number should you check for divisors?
ASquare root of n
Bn/2
Cn+1
Dn-1
What should the function return for input 1 when checking primality?
AFalse
BError
CTrue
DNone
Which of these is a quick way to skip unnecessary checks when testing primality?
ACheck only even numbers
BCheck only odd numbers after 2
CCheck all numbers up to n
DCheck only multiples of 3
What is the smallest prime number?
A3
B1
C0
D2
Explain how to check if a number is prime using a simple loop.
Think about dividing the number by smaller numbers to find factors.
You got /4 concepts.
    Why is it unnecessary to check divisors beyond the square root of a number when testing primality?
    Consider how multiplication pairs work.
    You got /3 concepts.