Question: Exercise 3 : Compare the efficiency of your algorithm with the brute force using following empirical approach: Implement the brute force algorithm to find the
Exercise :
Compare the efficiency of your algorithm with the brute force using following empirical
approach:
Implement the brute force algorithm to find the minimum distance between any two points
Implement the transform and conquer algorithm to do the same Exercise above
Run above two codes on randomly generated different numbers of input points for
example, points, points, points, points, points and note down the
execution times. Make sure that in each trial you generate a random input and then run both
codes on that same input.
Plot the times taken by both algorithms as function of the input size, on the same plot.
Explain the plot which algorithm is faster and why?
Select N number of points
Generate N random numbers make sure all numbers are unique, ie no two numbers
are same
For brute force, use two loops and calculate distance of each point from every other
point.
For Transform and Conquer, sort the points first and then use one loop to find distance
between consecutive points.
Run both codes and note down the execution time Each language has a builtin function
for this. For example, tic toc in MATLABOctave ctime in C
Repeat above five steps for different values of N and plot the times vs N
Brute force algorithm has On complexity whereas Transform and Conquer has On
log n for sorting On for finding minimum distance, which overall is On log n So
Transform and Conquer will show lower execution times.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
