Assignment Two

In this assignment, pratice using loops to deal with arrays and use recursion to solve problems. Use loops to solve question (1-2) and use recursion to solve the rest of the problems.
  1. Write a function to find the intersection of two integer sets. For example, the intersection of {1,3,5} and {1,5,10} is {1,5}. Use arrays to represent sets and you may assume that the elements in each set have been sorted.
  2. Write functions to compute the union and the difference of two interger sets. You can also use arrays and assume the numbers are sorted. As an example, the union of {1,3,5} and {1,5,10} is {1,3,5,10} and their difference {1,3,5}-{1,5,10} is {3}.
  3. In the class, we discussed the path finding problem in which a robot walks from the top left corner of a board to the right bottom corner. The robot can only move one step to the right or one step down. Now we put some obstacles on the way. Write a recursive program to print out all the possible paths by which the robot can reach the target.
  4. On a telephone key pad, each key corresponds to a number and a few letters (some have special characters). Given a sequence of numbers, we want to print out all the corresponding letter sequences. For example, "23" can be interpreted as "ad", "ae", "cf", etc.. Write a recursive function to achieve the goal.
  5. Write a recursive function to match regular expressions. In regular expression, a "*" matches zero or any number of characters, a "." matches any single character. Thus "a*c" will match "ac" and "aabc", and "a.c" matches "abc". Your function should take a string and a regular expression as the input and return true if they match and otherwise return false.