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
maksim [4K]
3 years ago
10

Design and implement an algorithm that gets a list of k integar values N1, N2,...Nk as well as a special value SUM. Your algorit

hm 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
Computers and Technology
1 answer:
Fittoniya [83]3 years ago
6 0

Answer:

The algorithm is as follows:

1. Start

2. Input List

3. Input Sum

4. For i = 0 to length of list - 1

4.1 num1 = List[i]

5. For j = i to length of list - 1

5.1 num2 = List[j]

6. If SUM = num1 + num2

6.1 Print(num1, num2)

6.2 Break

The algorithm is implemented in python as follows:

def checklist(mylist,SUM):

     for i in range(0, len(mylist)):

           num1 = mylist[i]

                 for j in range(i+1, len(mylist)):

                       num2 = mylist[j]

                       if num1 + num2== SUM:

                             print(num1,num2)

                                   break;

Explanation:

I'll explain the Python code

def checklist(mylist,SUM):

This line iterates from 0 to the length of the the last element of the list

     for i in range(0, len(mylist)):

This line initializes num1 to current element of the list

           num1 = mylist[i]

This line iterates from current element of the list to the last element of the list

                 for j in range(i+1, len(mylist)):

This line initializes num1 to next element of the list

                       num2 = mylist[j]

This line checks for pairs equivalent to SUM

                       if num1 + num2== SUM:

The pair is printed here

                             print(num1,num2)

                                   break;

You might be interested in
Which of the following can you use to add a picture to your presentation?
Advocard [28]
You can use photo art to help show a product or a certain piece of technology to help give a better idea of a product or thing you're trying to demonstrate to your class or people.
7 0
3 years ago
What has information technology made piracy possible?
Bond [772]
Well, more and more people are buying products and then uploading them online so that other people, who may not have the money or just don't want to buy them can download them for free. Of course, this is illegal, however it is a common practice all over the globe. Even if you are not downloading, but rather just watching a show on a website where you don't have to pay for it - it is still piracy.
5 0
3 years ago
Suppose that the following elements are added in the specified order to an empty binary search tree: Kirk, Spock, Scotty, McCoy,
patriot [66]

Answer:

Pre-order: Kirk, Chekov, Khaaaan, Spock, Scotty, McCoy, Sulu, Uhuru

In-order: Chekov, Khaaaan, Kirk, McCoy, Scotty, Spock, Sulu, Uhuru

Post-order: Khaaaan, Chekov, McCoy, Scotty, Sulu, Uhuru, Spock, Kirk

Explanation:

The binary search tree is described in the diagram below.

The pre-order traversal of the binary tree gets the root, then the left node and right node. The in-order traversal picks the left node, the root node, and then the right node while the post-order traversal of the binary tree follows the left node, right node, and then the root node.

6 0
3 years ago
Python program: Develop a program that will keep track of inventory for a local retail store. Fortunately, the store only offers
EastWind [94]
333 Sweater 500 The better programs will only process data
7 0
3 years ago
Read 2 more answers
How do i unblock a website on a school computer if a school blocks it?
tresset_1 [31]

Answer:

look up ultrasurf and just follow the thingy and it will download a vpn ive had it on my computer for a fat min

Explanation:

4 0
2 years ago
Other questions:
  • USB keys can store terabytes of data. Of the five key factors that contribute to the increasing vulnerability of organizational
    13·1 answer
  • If a computer is capable only of manipulating and storing integers, what di themselves? How are these difficulties overcome
    13·1 answer
  • Which of these are forms of data? Check all that apply.
    8·2 answers
  • ________ programming is a method of writing software that centers on the actions that take place in a program.
    8·1 answer
  • What is required to contain warnings, after several studies that have shown that they are a suffocation risk?
    15·2 answers
  • 2. Which property is used for hiding text of the textbox?
    14·1 answer
  • What should you do if your computer is running slower
    12·1 answer
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • What does business informWhat does business information management do?
    12·1 answer
  • a(n) is an object that defines a screen element used to display information or allow the user to interact with a program in a ce
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!