Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q3. (20 pts] Designing and Implementing an Algorithm - Sum of three elements a. [8 pts) Write an algorithm that determines whether there are three

image text in transcribed
Q3. (20 pts] Designing and Implementing an Algorithm - Sum of three elements a. [8 pts) Write an algorithm that determines whether there are three elements in a given array of integers that sums to exactly a given integer value k. As input, you are given an array of n integers and an integer value k. (Note that the efficiency of your algorithm will be considered in grading). For example, given the array [1, 3, 7, 4) and k = 14, the answer is "yes", given k=6 the answer is 'no." b. 15 pts) Identify a basic operation for your algorithm and study the performance of your algorithm by giving its time complexity function. If it has an every-case time complexity, determine it. Otherwise, determine the worst-case time complexity. C. (2 pts] Identify the complexity category to which the algorithm belongs. d. [5 pts) Implement your algorithm using Java. Write a main method that asks the user to enter the integer value k and the size n of an array of integers. The main method must generate the array elements randomly. As output, the program must first print all elements of the array. Then, it should print "No" if the array does not contain three elements that sums to k or print "Yes" if there are three clements that sums to k. If the output is "Yes", the program must print these three elements and their location index in the array

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago