Laboratory Exercise 02: Problems on Recurrence Relations

Laboratory Exercise 02: Problems on Recurrence Relations

<p> CmSc 250 Intro to Algorithms Laboratory Exercise 02: Problems on Recurrence Relations Due 10/08</p><p>1. von Neumann’s neighborhood. How many one-by-one squares are generated by the algorithm that starts with a single square and on each of its n iterations adds new squares all round the outside. How many one-by-one squares are generated on the nth iteration? The results for n = 0, 1, and 2 are illustrated below:</p><p>Find the number of cells in the von Neumann neighborhood of range n by setting up and solving a recurrence relation</p><p>2. Write a pseudocode for a recursive algorithm for finding the position of the largest element in an array of n numbers. Set up and solve a recurrence relation for the number of key comparisons made by your algorithm. How does this algorithm compare with the iterative algorithm for this problem? </p><p>3. Write a pseudocode for a recursive algorithm that determines whether a given word is a palindrome. A given word is a palindrome if it can be read backwards, for example pop, rotor, noon. Set up and solve a recurrence relation for the number of comparisons made by your algorithm. How does this algorithm compare with the iterative algorithm for this problem?</p><p>4. Write a pseudocode for a recursive algorithm that reverses the contents of an array. Set up and solve a recurrence relation for the number of swaps made by your algorithm. How does this algorithm compare with the iterative algorithm for this problem? </p><p>Optional: 5. There are n bacteria and 1 virus in a Petri dish. Within the firs minute, the virus kills one bacterium and produces another copy of itself, and all of the remaining bacteria reproduce, making 2 viruses and 2*(n-1) bacteria. In the second minute, each of the viruses kills a bacterium and produces a new copy of itself (resulting in 4 viruses and 2*(2*(n-1) -2) = 4*n – 8 bacteria; again, the remaining bacteria reproduces. This process continues every minute. Will the viruses eventually kill all the bacteria? If so, design and implement an algorithm that will compute how many steps it will take. How does the running time of your algorithm depend on n?</p><p>1 2</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us