Question
a) Write a simple program in pseudocode in C that receives a sequence of positive integers a1, , an as its input and determines if
a) Write a simple program in pseudocode in C that receives a sequence of positive integers a1, , an as its input and determines if the sequence contains three distinct terms x, y, and z such that x2 + y2 = z2 . Once it finds such terms, it prints them and terminates; it does not continue searching after the first find. If the program does not find any such terms, it prints out that it was unsuccessful and then terminates.
b) Describe the kind of input that causes worst-case time complexity for your algorithm (only count comparisons), and explain why this is the case.
c) Provide an equation for your algorithm that describes the number of required comparisons as a function of input length n in the worst case. For some algorithms, it may be a good idea to first use a sum notation, but at the end you should provide a closed-form equation, i.e., one that no longer uses the sum symbol but only operations such as multiplication or addition of individual numbers or variables.
d) Use the big-O-notation to describe the worst-case time complexity of your algorithm
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