Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your objective in this project is to develop a Theta(nlogn) algorithm to determine the number of integer pairs in an array (of size n) that

image text in transcribed
Your objective in this project is to develop a Theta(nlogn) algorithm to determine the number of integer pairs in an array (of size n) that add to a target value (t). You would create an array of 'n' random integers whose values range from 1 to 500. You also have a set T of target values, T = {500,..., 1000}. Your task is to find the number of integer pairs (say, denoted [x, y]) in the array such that they add up to a particular target value t elementof T (i.e., x + y = t). Note that x and y could be either distinct or the same values as long as they occupy two different locations (indices) in the array. In the following example, I show the contents of an array of n = 7 random integers whose values range from 1 to 10. The set T of target values is T = {10,..., 20}. The number of [x, y] pairs whose sum is equal to a target value in T is shown alongside. For clarity, I have distinguished the two 10s in this example by representing the 10 at index 3 with an underscore (10). Tasks: Your specific tasks are as follows: (1) Provide a detailed description of the working of the algorithm along with an example. (2) Provide a pseudo code for the algorithm. (3) Analyze the theoretical run-time complexity of the algorithm and show that it is Theta(nlogn). (4) Analyze the theoretical space complexity of the algorithm. (5) Discuss the correctness of your algorithm (6) Implement the algorithm (7) Run simulations of your algorithm for array sizes of 100, 1000 and 10000. You could fill the contents of all of these arrays with random integers ranging from 1 to 500. For each array size, run the simulation for 50 runs and average the results for the number of {x, y} pairs with respect each of the target sum values in the set T = {500,..., 1000}. Plot the results as follows: (a) The integer target values in the set T = {500, ....., 1000} vs. the average number of {x, y} pairs that add to each of these target values (b) The array size vs. {average execution time and the theoretical run-lime complexity that is supposed to be nlogn}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started