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
What is a way of telling the computer how to display certain content pls answer quick
coldgirl [10]
Machine language is the language understood by a computer. It is very difficult to understand, but it is the only thing that the computer can work with. All programs and programming languages eventually generate or run programs in machine language
4 0
3 years ago
During active listening, which response is NOT an example of providing feedback to the speaker to show that you understand his o
MaRussiya [10]

Answer:

The answer is D.

Explanation:

They/you are asking the speaker to clarify what they just said.

6 0
4 years ago
Which term refers to the technical structure of the software, how users interact with the software, and how the software is phys
mars1129 [50]
The Answer is <span> Architecture</span>
7 0
3 years ago
Is the hacker group project zorgo real or fake
Charra [1.4K]

It is real I hoped this help you

4 0
3 years ago
Read 2 more answers
Use the AND function with appropriate arguments in cell H11 to determine if there is a force out at third base. There is a force
Pie

Answer:

=AND($C11 = "Yes", $D11 = "Yes")

Explanation:

The AND function takes conditional inputs and tests if each of them are TRUE. If all of the inputs are TRUE, the function will output TRUE but if any one of them are not the function will output FALSE. This scales to multiple inputs but this example only has two conditions. It is important to remember that we want to compare a string so our condition must be "Yes", not just Yes.

We also use a relative cell reference, "$", on the columns C and D since we always want to use the "Runner on 1st" and "Runner on 2nd" columns.

6 0
3 years ago
Other questions:
  • Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow
    8·1 answer
  • Which of the following is an example of a query with an explicit location? Select all that apply. True False [walmart boston], E
    7·2 answers
  • Given two double variables, best value and second best value, write some code that swaps their values. declare any additional va
    13·1 answer
  • Which of the following Internet protocols is MOST important in reassembling packets and requesting missing packets to form compl
    11·1 answer
  • Your mom wants to purchase a computer. She has heard about how the Windows 8 operating system is best-geared for a touch-enabled
    10·2 answers
  • Linda is training to become a certified network design expert and consultant. While researching about the process of cellular ra
    12·1 answer
  • One line of code is missing (marked in
    5·1 answer
  • You use a Windows desktop system to edit and produce audio files. Your system has two hard disks installed. Your applications ar
    10·1 answer
  • Which web-authoring software enables users to create sophisticated web pages without knowing any html code?.
    15·1 answer
  • clinical outcomes and survival differences between primary, secondary and concomitants carcinoma in situ of urinary bladder trea
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!