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 is NOT a file format used for word processing documents? A. .ppt B. .rtf C. .doc D. .odt
ohaa [14]

Answer:

ppt

Explanation:

ppt is a PowerPoint document

Extra Notes:

rtf: Rich Text Format

odt: Open Doc Text

doc: Microsoft Word File (Compatibility File) .docx is newer standard

4 0
2 years ago
What environmental concern will hybrid cars address?
Over [174]
The answer to the above question is:
d. all of the above
5 0
3 years ago
Read 2 more answers
What is one advantage and disadvantage of designing a support security that might be based on a centralized model, where all sen
defon

Co-Ordination Difficulty: ...
Waste of Resources: ...
Larger Interests of the Enterprise Neglected: ...
Emergency Decision not Possible: ...
Lack of Qualified Managers: ...
Certain Activities Decentralization not Possible:
8 0
3 years ago
What are the factors that affect self-confidence?
denis-greek [22]

Answer:

The factors that affect self confidence are not having enough faith in yourself and letting what others say about you put you down

Explanation:

Plz mark brainlest it will help me so much

5 0
2 years ago
What is the process in which a server is partitioned into smaller components virtually
lilavasa [31]

The answer to your question is,

Server virtualization

-Mabel <3

3 0
3 years ago
Other questions:
  • Freya realizes she does not have enough in her bank account to use the debit card. She decides to use a credit card instead. Whi
    7·2 answers
  • Create a program that reads words.txt (link near top of our home page) in order to: determine the length of the longest word(s)
    14·1 answer
  • Which pattern is produced by the following code? for (int i = 1; i &lt;= 6; i++) { for (int j = 6; j &gt;= 1; j--) System.out.pr
    6·1 answer
  • You work in the Accounting department and have been using a network drive to post Excel workbook files to your file server as yo
    15·1 answer
  • Write a program to display the roll number of students who have scored 100 in math. display appropriate message if none have sco
    5·1 answer
  • Ok.,so i have a sopitify account and by accident i pressed the downlaod on button and it says start you free trial i pressed tha
    11·2 answers
  • Public class Main{ public static void main(String [] args){ String name=WelcomeJava; Runnable r1=() -&gt; System.out.println(nam
    12·1 answer
  • Write a program that takes a decimal number from the user and then prints the integer part and the decimal part separately. For
    13·1 answer
  • How did imperialism lead to WWI? A The debate of the morality of imperialism created tensions around Europe b Native people were
    12·1 answer
  • Bob has started a company and registered its name with the government as a private corporation. He tries to create a domain name
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!