CSCI 5454 - Algorithms - Spring 2015

Problem Set #3

Due: 1pm, Feb 25th, 2015



1. Text problem 1.16.

2. Text problem 1.20. Do not use a computer; show your work.

3. Write a python function nextprime(i) to find the next prime ≥ i. What is nextprime(2015**50)? Include the answer along with your source code.

4. Using your code from above, write a python program that computes the average distance from a random 100-digit integer to the nextprime after it. Use 1 thousand samples to obtain your average. In other words, define a function getrand100() that generates random 100-digit random positive integers and let s=getrand100(); then compute the average value of nextprime(s)-s using 1000 samples. Include source code with your answer.