Recursive definitions for subsets of binary strings. About Give a recursive definition for each subset of the binary strings. A string x should be in the recursively defined set if and only if x has the property described.

(a) The set S consists of all strings with an even number of 1's.
(b) The set S is the set of all binary strings that are palindromes. A string is a palindrome if it is equal to its reverse. For example, 0110 and 11011 are both palindromes.

Respuesta :

Answer:

this program was written in JAVA

Explanation:

import java.util.Scanner;

public class RecursivePalindromeJava

{

public static boolean checkPalindrome(String str)

{

if(str.length() == 0 || str.length() == 1)

return true;

if(str.charAt(0) == str.charAt(str.length() - 1))

return checkPalindrome(str.substring(1, str.length() - 1));

return false;

}

public static void main(String[]args)

{

Scanner sc = new Scanner(System.in);

System.out.println("Please enter a string : ");

String strInput = sc.nextLine();

if(checkPalindrome(strInput))

{

System.out.println(strInput + " is palindrome");

}

else

{

System.out.println(strInput + " not a palindrome");

}

sc.close();

)

)