Книга: A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 2 (for True Epub)
Назад: Wrapping Up
Дальше: Chapter 10: Designing Great Hash Tables with Randomization

Exercises

The following exercises provide you with the opportunity to practice with Monte Carlo algorithms. The solutions to these exercises are found in the section .

  1. Say that we have a large array of integers, and we want to determine what percentage of the integers are even and what percentage are odd. Write code that performs random sampling to approximate these percentages.

  2. Let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times. Three times the result was 1, and one time the result was 2. What are the odds that N is prime?

  3. Now, let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times, and all four times the result was 1. What are the odds that N is prime?

Назад: Wrapping Up
Дальше: Chapter 10: Designing Great Hash Tables with Randomization