Skip to main content
added 197 characters in body
Source Link
Egretta.Thula
  • 11.8k
  • 1
  • 12
  • 34

If you have $M$ marked element, then the number of iterations should be

$$\frac{\pi}{4}\sqrt{\frac{N}{M}} \text{where},\;\;\; N = 2^n $$

So, you need to replace this line

iterations = np.pi/4*np.sqrt(2**n)

with

iterations = np.pi/4*np.sqrt(2**n / 3)

Note also that, you should use floor() instead of round() to specify the number of iterations. Check out this answer for the details.

If you have $M$ marked element, then the number of iterations should be

$$\frac{\pi}{4}\sqrt{\frac{N}{M}} \text{where},\;\;\; N = 2^n $$

So, you need to replace this line

iterations = np.pi/4*np.sqrt(2**n)

with

iterations = np.pi/4*np.sqrt(2**n / 3)

If you have $M$ marked element, then the number of iterations should be

$$\frac{\pi}{4}\sqrt{\frac{N}{M}} \text{where},\;\;\; N = 2^n $$

So, you need to replace this line

iterations = np.pi/4*np.sqrt(2**n)

with

iterations = np.pi/4*np.sqrt(2**n / 3)

Note also that, you should use floor() instead of round() to specify the number of iterations. Check out this answer for the details.

Source Link
Egretta.Thula
  • 11.8k
  • 1
  • 12
  • 34

If you have $M$ marked element, then the number of iterations should be

$$\frac{\pi}{4}\sqrt{\frac{N}{M}} \text{where},\;\;\; N = 2^n $$

So, you need to replace this line

iterations = np.pi/4*np.sqrt(2**n)

with

iterations = np.pi/4*np.sqrt(2**n / 3)