Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Data: String T with n lowercase letters Result: The number of palindrome substrings in string T clarr 0 ; for ilarr 0 to n -
Data: String with lowercase letters Result: The number of palindrome substrings in string clarr; for ilarr to do for jlarri to do substring to ; if isPalindromesubstring then clarrc end end end return a Prove that this algorithm is correct by providing the following: i marks Show that the algorithms terminates. Note: To prove that the algorithm terminates you cannot just give an example and show that the algorithm terminates on it; instead you must prove that when the algorithm is given any input string of length for any value of the algorithm will always end. ii marks Show that the algorithm always produces the correct answer. Note: To prove that the algorithm is correct you cannot just give an example and show that the algorithm computes the correct output. You must prove that when the algorithm is given any input string of length the algorithm correctly outputs the number of palindromes in the string. Assume that the function isPalindrome always produces correct output. iii. marks Compute the time complexity of this algorithm in the worst case. You must explain how you computed the time complexity, and you must give the order of the complexity. Assume that the function isPalindrome takes only a constant time to execute.
Data: String with lowercase letters
Result: The number of palindrome substrings in string
clarr;
for ilarr to do
for jlarri to do
substring to ;
if isPalindromesubstring then
clarrc
end
end
end
return
a Prove that this algorithm is correct by providing the following:
i marks Show that the algorithms terminates.
Note: To prove that the algorithm terminates you cannot just give an example and show that the algorithm terminates on it; instead you must prove that when the algorithm is given any input string of length for any value of the algorithm will always end.
ii marks Show that the algorithm always produces the correct answer.
Note: To prove that the algorithm is correct you cannot just give an example and show that the algorithm computes the correct output. You must prove that when the algorithm is given any input string of length the algorithm correctly outputs the number of palindromes in the string. Assume that the function isPalindrome always produces correct output.
iii. marks Compute the time complexity of this algorithm in the worst case. You must explain how you computed the time complexity, and you must give the order of the complexity. Assume that the function isPalindrome takes only a constant time to execute.
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