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 does the proofreading mark "..." mean?
scZoUnD [109]

Answer:

I believe "..." means that you need to go further in depth with your writing.

3 0
3 years ago
Read 2 more answers
Which of the following statements is/are true by definition.
Rudik [331]

Answer:2. electrical equipment shall be considered readily accessible to those to whom ready access is requisite when it is capable of being reached quickly for operation by using a portable ladder.

Explanation:

3 0
3 years ago
Task 2
USPshnik [31]
4.
3.
1.
5.
2.
I rearranged them so the program would make sense by arranging the interaction in a logical order then placing input statements in between
6 0
2 years ago
Read 2 more answers
Really desperate!
bija089 [108]

Answer: Sorry to break this to you but you can't.

Explanation:

7 0
3 years ago
Read 2 more answers
What is an entity supertype, and why is it used?
marissa [1.9K]

Answer:

Correct answer is option B (The reason for using supertypes is to minimize the number of nulls and to minimize the likelihood of redundant relationships)

Explanation:

Entity supertype

A  entity supertype is a generic entity type which is related with one or more subtypes.

Use of entity supertype:

The reason for using entity supertype is to reduce redundant relationships and it is also used to minimize the number of nulls.

5 0
3 years ago
Other questions:
  • Which of the following is not true about managing your privacy settings? (select all that apply)
    9·2 answers
  • A cooler with heat pipes, which contain a small amount of liquid that becomes a vapor when heated, allowing heat to be drawn awa
    10·1 answer
  • Differentiate among a color display, gray scale display, and a black-and-white display​
    7·1 answer
  • To open the dialog box for modifying styles, which step must you first complete in the Navigation pane?
    11·2 answers
  • Which advertising medium has the widest reach on a global front?
    12·1 answer
  • knowledge contributes vitally to the development of __________ memory, or recollections of personally experienced events that oc
    12·1 answer
  • When individuals not involved in the development process are asked to test the game, this is called ________ group testing.
    11·1 answer
  • Q13. On which option do you click to
    12·1 answer
  • Which phrase is the best definition of sparklines in Excel 2016?
    8·2 answers
  • Is e commerce a challenge or opportunity to the freight forwarder
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!