1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lidiya [134]
3 years ago
12

Design and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Y

our algorithm must locate a pair of values in the list N that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm would output either of the two values (2, 18) or (3, 17). If your algorithm cannot find any pair of values that sum to the value SUM, then it should print the message ‘Sorry, there is no such pair of values’. Schneider, G.Michael. Invitation to Computer Science (p. 88). Course Technology. Kindle Edition.

Computers and Technology
1 answer:
satela [25.4K]3 years ago
6 0

Answer:

Follows are the code to this question:

def FindPair(Values,SUM):#defining a method FindPair  

   found=False;#defining a boolean variable found

   for i in Values:#defining loop for check Value  

       for j in Values:#defining loop for check Value

           if (i+j ==SUM):#defining if block that check i+j=sum

               found=True;#assign value True in boolean variable

               x=i;#defining a variable x that holds i value

               y=j;#defining a variable x that holds j value

               break;#use break keyword

       if(found==True):#defining if block that checks found equal to True

           print("(",x,",",y,")");#print value

       else:#defining else block

           print("Sorry there is no such pair of values.");#print message

Values=[3,8,13,2,17,18,10];#defining a list and assign Values

SUM=20;#defining SUM variable

FindPair(Values,SUM);#calling a method FindPair

Output:

please find the attachment:

Explanation:

In the above python code a method, "FindPair" is defined, which accepts a "list and SUM" variable in its parameter, inside the method "found" a boolean variable is defined, that holds a value "false".

  • Inside the method, two for loop is defined, that holds list element value, and in if block, it checks its added value is equal to the SUM. If the condition is true, it changes the boolean variable value and defines the "x,y" variable, that holds its value.
  • In the next if the block, it checks the boolean variable value, if the condition is true, it will print the "x,y" value, otherwise, it will print a message.  

You might be interested in
It is safe to interchange oxygen and fuel gas hoses. A. False B. True
Marat540 [252]
False.
If you were to interchange one another it would be VERY life threatening.
6 0
3 years ago
Read 2 more answers
Task 5: Create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer whose ID currently is sto
lidiya [134]

The SQL statement that would create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer is:

GET_CREDIT_LIMIT

SELECT CUST_ID 125

FROM FIRST_NAME, LAST_NAME, CREDIT_LIMIT

WHERE LAST_NAME ="Smith"

<h3>What is SQL?</h3>

This is an acronym that means Structured Query Language that is used in handling data in a database.

Hence, we can see that from the attached image, there is a table that contains the details of customers and their various data such as their first and last names, credit limits, address, etc, and the  GET_CREDIT_LIMIT procedure is shown above.

Read more about SQL here:

brainly.com/question/25694408

#SPJ1

3 0
1 year ago
When do you use FTP?
Sergeeva-Olga [200]
FTP (File Transfer Protocol) can be used for a variety of tasks. For instance, webmasters using FTP for pushing updates/files to their websites can provide easy and straightforward changes to their services without the need to physically transfer files onto the host server. FTP should be used when you must update a file or files on a host server for a variety of reasons and you do not have access to the host server physically. However, FTP also has some inherent security risks which is why some webmasters/hosts chose to opt out of pushing updates through FTP in favour of physical file transfer.
5 0
3 years ago
Read 2 more answers
Non-preemptive Shortest Job First (SJF) scheduling policy is not optimal if:
ivann1987 [24]

Answer:

The answer is A

Explanation:

Basically, Shortest job first (SJF) is a scheduling policy that selects jobs on queue for execution  within a short execution time.

From the definition of SJF above, it means that there are a lot of process on queue and the (SJF) job is to receive processes on queue to execute within a short execution time.

Therefore, if all the jobs or process arrives at the SJF at the same time, the SJF will forfeit one of its major purpose which is scheduling of jobs.

That will therefore not make Non-preemptive Shortest Job First (SJF) not function at its optimal point.

4 0
2 years ago
Match the parts of the software applications with what they do.
Lady_Fox [76]

1-h

2-f

3-e

4-g

5-d

6-c

7-b

8-a

4 0
2 years ago
Other questions:
  • What are the advantage of transistors over vacuum tubes?
    6·1 answer
  • Electronic files created on a computer using programs such as word software are considered to be
    15·1 answer
  • What important information is needed if you are installing an oem version of windows 7?
    6·1 answer
  • Analyze the following code. Number[] numberArray = new Integer[2]; numberArray[0] = new Double(1.5); Question 9 options: A) Sinc
    13·1 answer
  • You have added a table to your web page consisting of two columns and five rows, including the header row. in the first header c
    13·1 answer
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • Which of these programmers creates the core game engine?
    5·2 answers
  • For a parking payment app, what option would MOST likely connect a user to a third party/external gateway?
    10·1 answer
  • A location in memory which stores a value, the value can change as the program is running is
    12·1 answer
  • Your friend Cameron’s little sister is visually impaired. Cameron is worried that his sister will not be able to use technology
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!