Lecture 4 - Problems

  1. A palindrome is a string that reads the same backwards as forwards. For example, civic, radar, deed, and racecar are all palindromes. The definition I just gave is a non-recursive one: the string is equal to its reverse. Come up with a recursive definition of a palindrome, and write pseudocode for the following method. You can use indexing and range indexing to refer to characters and substrings of s.

  2. Here’s the pseudocode for a factorial function:

    What is the asymptotic runtime class of this function in terms of n?

  3. Recall the count_e method, which processed the string one character at a time (i.e., in an incremental fashion):

    Write a different version of this method that has the same spec, but solves the problem using the divide-and-conquer paradigm.