Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Be sure to read the SPECIFICATIONS carefully! And write comments! Specifications and Notes ( for both parts ) : There should be no loops. There
Be sure to read the SPECIFICATIONS carefully! And write comments!
Specifications and Notes for both parts:
There should be no loops.
There should be no global variables ie no variables defined outside of all functions
You are only allowed to use the header iostream.
You are not allowed to use sequences, vectors, or any advanced data structure that can store an
arbitrarily long collection of integers.
No input prompts or additional output should be used.
Use the provided templates for each part the template file includes code that receives input and
displays output from the function call on the input.
Note: Each problem has three visible test cases on Gradescope. You will see if your code passes these
three test cases. In addition, each has two invisible test cases, which you will not be able to see until
after grades are released you will not see if your code passed or did not pass these To receive credit,
the execution must produce the correct results on invisible test cases. Additionally, your program must
include comments that clearly and concisely explain the reasoning and structure of your program.
a countValidBinaryWarmup.cpp
A binary string ie a string consisting of s and s is called separated if there is at least one
separating any two s For example, is a separated binary string of length whereas
is not.
Write a recursive function oneSeparated to count the number of separated binary strings of a
given positive integer length. The function should have two parameters: the length of the string
and the ending number or
You may assume that the input length will be a positive integer and the ending number will be
either or
Below are examples of what the function oneSeparated should return for the given input parameters.
oneSeparated should return since the binary string consisting of a single is separated.
oneSeparated should return since the binary strings of length ending in that are
separated are and
oneSeparated should return since the binary strings of length ending in that are
separated are and
b countValidBinary.cpp
This is a generalization of the previous part. Given a positive integer we call a binary string
kseparated if there are at least s separating any two s For example, for and string
length is a separated binary string, whereas is not.
Note that kseparated means if there are more than two s then they must be separated by at
least s So there need not be more than two s for the string to be kseparated. For example
is considered separated, separated, separated, and in fact, kseparated for any positive
integer
Write a recursive function kSeparated to count the number of kseparated binary strings of a given
positive integer length. The function should have three parameters: the value of the length of
the string, and the ending number or
You may assume that the input length and will be positive integers, and the ending number will
be either or
Below are examples of what the function kSeparated should return for the given input parameters.
For kSeparated returns and kSeparated returns since
and are the binary strings of length that are separated.
For kSeparated returns and kSeparated returns since the same
strings of length that are separated are also separated.
For kSeparated returns and kSeparated returns since
and are the binary strings of length that are separated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started