Question

In python... All functions must use recursion. Do not use any iteration or slicing. 1. Return...

In python...

All functions must use recursion. Do not use any iteration or slicing.

1. Return the reverse of the given string. Use the index argument to keep track of position, which starts at zero.

reverse_string(chars: str, index: int) -> str

2. Return the highest number in the list of integers. Use the index argument to keep track of position, which starts at zero.

find_max(ints: List[int], index: int) -> int

3. Return True if the given string is a palindrome and False otherwise. A palindrome is a symmetric sequence of characters, reading the same forward and backward. Use the index argument to keep track of position, which starts at zero. Do not call reverse_string.

is_palindrome(chars: str, index: int) -> bool

0 0
Add a comment Improve this question Transcribed image text
Answer #1
from typing import *


def reverse_string(chars: str, index: int = 0) -> str:
    if index < len(chars):
        return reverse_string(chars, index + 1) + chars[index]
    return ""


# Testing the function here. ignore/remove the code below if not required
print(reverse_string("hello"))
print(reverse_string("how are you?"))


def find_max(ints: List[int], index: int = 0) -> int:
    if index == len(ints) - 1:
        return ints[index]
    else:
        large = find_max(ints, index + 1)
        if ints[index] > large:
            large = ints[index]
        return large


# Testing the function here. ignore/remove the code below if not required
print(find_max([4, 9, 2]))
print(find_max([14, 9, 2]))
print(find_max([4, 9, 21]))


def is_palindrome(chars: str, index: int = 0) -> bool:
    if index >= len(chars):
        return True
    else:
        return is_palindrome(chars, index + 1) and chars[index] == chars[len(chars) - index - 1]


# Testing the function here. ignore/remove the code below if not required
print(is_palindrome("hello"))
print(is_palindrome("radar"))
print(is_palindrome("mom"))
print(is_palindrome("palindrome"))

Add a comment
Know the answer?
Add Answer to:
In python... All functions must use recursion. Do not use any iteration or slicing. 1. Return...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • Write a recursive function called sumover that has one argument n, which is an unsigned integer....

    Write a recursive function called sumover that has one argument n, which is an unsigned integer. The function returns a double value, which is the sum of the reciprocals of the first n positive integers. (The reciprocal of x is the fraction 1/x.) For example, sumover(1) returns 1.0 (which is 1/1); sumover(2) returns 1.5 (which is 1/1 + 1/2); sumover(3) returns approximately 1.833 (which is 1/1 + 1/2 + 1/3). Define sumover(0) to be zero. Do not use any local...

  • Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all...

    Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • /** * Notes: * You must use RECURSION to solve the problems. Your code may not...

    /** * Notes: * You must use RECURSION to solve the problems. Your code may not contain any loops. * You may not change any of the fields, nor the constructor, nor the insertAtFront method. * You may not modify the method headers given to you in any way nor may you change the name of the class or the package. */ package hw8; import java.util.NoSuchElementException; public class MyList<Item> {    private class MyListNode {        public Item item;...

  • Fix this C++ below so does not use any loops at all. Use recursion instead. here...

    Fix this C++ below so does not use any loops at all. Use recursion instead. here is some guides given. Create a directory to hold assignment 3. Copy files hailstone.cpp, Makefile and dotestassignment 2 to the assignment 3 directory. Edit the comments at the top of hailstone.cppto say that this is assignment 3. You should be able to keep the same contracts, 'next' function and 'main' function from assignment 2, unless they contained errors that needed to be fixed. If...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of...

    In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of lists and functions with multiple inputs and multiple outputs. Your task is to implement the separate_and_sort function. This function takes two input parameters: 1. A list containing strings and integers in any order. 2. An optional integer parameter size which controls how many items in the list the function will process. If the length of the list is smaller than the value of size,...

  • STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

    STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...

  • STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

    STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT