Exercises

  1. One of the classic problems is the Tower of Hanoi, inspired by Hindu temples, where priests are provided with three poles of 64 gold disks, and each disk is a little smaller than the one beneath it, as shown in the following figure:

    Exercises

    • The task is to transfer all 64 disks from one pole to another with two constraints, that is, only one disk can be moved at a time, and that they cannot place a larger disk on smaller one. Write a dynamic programming-based approach to solve the Tower of Hanoi problem.
  2. Implement a function that gets the edit distance of two input strings, where the edit distance is defined as insertion, deletion, and substitution. The function should determine the minimal number of edit distance required to modify one distance to another.
  3. Given a rope of length n, write a function to determine how to cut the rope into m parts with length l[0], l[1], and so on until l[m] so that the product of each part is maximum. The rope needs to be cut as an integer with a minimum of one cut.
  4. Construct an all-pair shortest distance matrix for the following graph:

    Exercises

  5. In a class, there are m students. An exam is conducted with 30 questions. The examiner picked random eight questions and graded them. The grades will be either A or D. A will be assigned if more than 50% questions are answered correctly; otherwise, grade D will be assigned. Set up a Monte Carlo simulation to determine the expected error for a person getting A instead of D.
  6. Write a function to delete a node from a skip list.
  7. Write a function to develop a skip list to contain numbers in the range [1, m] where m is not constant, and a support query to find an element e1 so that e1.key=q is a given pointer to an element e2, e2.key=p so that p<q in O(log k) expected time, where k is the distance between elements e1 and e2.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset