Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Dear students I talked in the class regarding activities that will be done in or outside the class. This is the first one which is
Dear students
I talked in the class regarding activities that will be done in or outside the class. This is the first one which is outside the class. Please make a group of people to work on the problem.
Consider the problem of three sum: Given an array of n integers and an integer t find indices of three integers x y and z in three different indices such that xyz t or return none if there are no such three integers.
The following algorithm solve the problem with time complexity of On
iterative version:
for i from to n
for j from i to n
for k from j to n
if AiAjAk t
return i j k
return none
recursive version:
ThreeSumAtijk
if i n
return none
else
if jn
return ThreeSumAti ii
if kn
return ThreeSum Ati jj
if Ai Aj Ak t
return ijk
else
return ThreeSum Ati jk
First, design a On algorithm for the three sum problem.
Second, program using C language the two algorithms and compare the number of comparisons and the time in seconds.
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