Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A strictly increasing consecutive subsequence is a part of a sequence in which every element is strictly greater than the previous element. Because strictly increasing
A strictly increasing consecutive subsequence is a part of a sequence in which every element is strictly greater than the previous element. Because strictly increasing consecutive subsequence is a bit long, we will call this a streak. For example, in the sequence the subsequences and are streaks. Of course, by definition, any subsequence of a streak is also a streak. is the longest streak among all streaks of that input sequence. Below is a function that takes as argument a sequence of numbers, and it aims to return the length of the longest streak of the input sequence: def longeststreakseq: i counter narray #base case if lenseq: return while i lenseq: if seqi seqi: countercounter ii else: narray.appendcounter counter ii if lennarray: returncounter else: returnmaxnarray However, the function above is not correct. a Provide an example of argument, of correct types, that makes this function return the wrong answer or that causes a runtime error. The argument must be a sequence of numbers. b Explain the cause of the error that you have found, ie what is wrong with this function. Your answer must explain what is wrong with the function as given. Writing a new function is not an acceptable answer, regardless of whether it is correct or not.
A strictly increasing consecutive subsequence is a part of a sequence in which every element is strictly greater than the previous element. Because strictly increasing consecutive subsequence is a bit long, we will call this a streak. For example, in the sequence the subsequences and are streaks. Of course, by definition, any subsequence of a streak is also a streak. is the longest streak among all streaks of that input sequence.
Below is a function that takes as argument a sequence of numbers, and it aims to return the length of the longest streak of the input sequence:
def longeststreakseq:
i
counter
narray
#base case
if lenseq:
return
while i lenseq:
if seqi seqi:
countercounter
ii
else:
narray.appendcounter
counter
ii
if lennarray:
returncounter
else:
returnmaxnarray
However, the function above is not correct.
a Provide an example of argument, of correct types, that makes this function return the wrong answer or that causes a runtime error. The argument must be a sequence of numbers.
b Explain the cause of the error that you have found, ie what is wrong with this function. Your answer must explain what is wrong with the function as given. Writing a new function is not an acceptable answer, regardless of whether it is correct or not.
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