91.0k views
4 votes
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.

2 Answers

5 votes

Final answer:

Recursive definitions for binary strings with an even number of 1's involve a base case of the empty string and a recursive step that maintains the even count of 1's. For binary palindromes, the base cases include the empty string and single-character strings '0' and '1', and the recursive step involves building outward from a known palindrome.

Step-by-step explanation:

Recursive Definitions in Mathematics

The concept of recursion is utilized to define certain sets or sequences where the definition relies on previously defined terms within the sequence or set itself.

(a) Even Number of 1's in Binary Strings

A recursive definition for the set S, consisting of binary strings with an even number of 1's, can be given as follows:

Base case: The empty string "" (containing no numbers) is in S, as it has zero 1's, which is an even number.

Recursive step: If a string x is in S, then the strings "0" + x and "1" + x + "1" are also in S.

Restriction: If adding a "1" to a string x, that string is only in S if x initially had an odd number of 1's, to keep the total count even.

(b) Binary String Palindromes

A recursive definition for the set S of binary strings that are palindromes is:

Base case: The empty string "" and the strings "0" and "1" are in S, as they read the same forward and backward.

Recursive step: If a string x is in S, then the strings "0" + x + "0" and "1" + x + "1" are also in S, since palindromes read the same in both directions.

These definitions ensure that each string is constructed to fulfill the respective conditions of having an even number of 1's or being symmetrical as a palindrome.

User Vdi
by
5.9k points
3 votes

Answer:

this program was written in JAVA

Step-by-step explanation:

import java.util.Scanner;

public class RecursivePalindromeJava

{

public static boolean checkPalindrome(String str)

if(str.length() == 0

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();

)

)

User Brien Foss
by
5.6k points