130 likes | 316 Views
CSE 1030: Recursion. Mark Shtern. Summary. Recursion. Search. Write a method that searches a single element in a List. Ex 801. Write a method which is called sumOfDigits and returns the sum of the digits of an integer. Greatest common divisor. Ex 803.
E N D
CSE 1030: Recursion Mark Shtern
Summary • Recursion
Search • Write a method that searches a single element in a List
Ex 801 • Write a method which is called sumOfDigits and returns the sum of the digits of an integer
Ex 803 • Write a recursive method that prints all the elements of a List, one per line • Write a recursive method that prints reverse order all the elements of a List, one per line
Ex 803 • Find the minimum element in a List. Use recursion.
Ex805 • Given a string, return recursively a "cleaned" string where adjacent chars that are the same have been reduced to a single char. So "yyzzza" yields "yza".
Search • Write a method that searches a single element in a List • If the list is of length 0 then ... • If the list is of length 1 then ... • the list into two sublists of about half the size • Search sublist recursively by re-applying the search method.
Ex806 • Given a string, compute recursively the number of times lowercase "hi" appears in the string, however do not count "hi" that have an 'x' immediately before them.
Ex807 • Given a string, return true if it is a nesting of zero or more pairs of parenthesis, like "(())" or "((()))". nestParen("(())") → truenestParen("((()))") → truenestParen("(((x))") → false
Ex808 • Given an list of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target?
Ex808 • Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length. strDist("catcowcat", "cat") → 9strDist("catcowcat", "cow") → 3strDist("cccatcowcatxx", "cat") → 9