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
Rose has a list of two columns of information separated by tabs. She wants to input this information into a table. What is the f
andreev551 [17]
I gotchu my bro!!
it would be D. " clicking Convert Text to Table"
7 0
3 years ago
Read 2 more answers
Demonstrate the register addressing mode for the following instructions. Also what addressing mode belongs to these instructions
kotykmax [81]

Answer:

Demonstrate the register addressing mode for the following instructions. Also what addressing mode belongs to these instructions?

1. MOV CX, [BX+DI]

2. MOV AX, ARRAY[CX]

3. MOV BX, [CX+DI+6]

4 0
3 years ago
A company has recently learned of a person trying to obtain personal information of employees illegally. According to which act
Juli2301 [7.4K]

Answer

Digital Millennium Act

Explanation

The Digital Millennium Copyright Act  is a United States copyright law that implements two  treaties of the World Intellectual Property Organization . The aim of this ACT is to protect the rights of both copyright owners and consumers. The law complies with the World Intellectual Property Organization  Copyright. The law has two basic functions. First, it protects copyright owners by providing them with a mechanism to enforce their rights without having to directly sue the infringer

7 0
2 years ago
Read 2 more answers
New trends, tools, and languages emerge in the field of web technology every day. Discuss the advantages of these trends, tools,
ikadub [295]

Answer:

Explanation:However, with the emergence of several new web development technologies, tools, frameworks, and languages in the last few years, it has now become quite .

7 0
2 years ago
What characteristics need to be exhibited by an organisation to improve its software process?
aalyn [17]

Answer:  Defined , Controllable ,  Measured , Effective ,  Institutionalized are some of the characteristics needed to be exhibited by an organisation to improve its software process

Explanation:

Software process improvement(SPI)  helps in achieving goals of software products for an organization. Some of its characteristics are Defined , Controllable ,  Measured , Effective ,  Institutionalized.

It goals must be defined, and must also be controlled and it performance must be measured at regular intervals and any reforms carried out to achieve goals must be effective. Lastly it should implement all goals in an institutional framework to be followed by every one in the organization.

6 0
3 years ago
Other questions:
  • What is the role of the constructor for an object?
    5·1 answer
  • When selecting text in word, holding down the ctrl key while clicking the mouse button will select the?
    15·1 answer
  • Digital dashboards provide the decision makers with a quick overview of key performance indicators and other key operational sta
    13·1 answer
  • Keyboard question: <br> How do I make the 'congruent to' symbol on this keyboard?
    8·1 answer
  • An interface does not have ____.
    13·1 answer
  • What icons in the toolbar change the look of the presentation text? It’s either Drawing, Formatting,Presentation, or Standard
    9·2 answers
  • Which web browser was created by Google?
    5·2 answers
  • A computer game allows a player to repeat a level until they run out of lives. Which two of the following loops would work corre
    8·2 answers
  • When James added a date field to a PivotTable, Excel grouped the date values into quarters, months, and years. He does not want
    13·1 answer
  • Define a function that will return the length of a list
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!