1 / 13

CSE 1030: Recursion

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.

argus
Download Presentation

CSE 1030: Recursion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 1030: Recursion Mark Shtern

  2. Summary • Recursion

  3. Search • Write a method that searches a single element in a List

  4. Ex 801 • Write a method which is called sumOfDigits and returns the sum of the digits of an integer

  5. Greatest common divisor

  6. 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

  7. Ex 803 • Find the minimum element in a List. Use recursion.

  8. 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".

  9. 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.

  10. 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.

  11. 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

  12. 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?

  13. 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

More Related