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
True or false? Main Content (MC) may include links on the page.
nevsk [136]
True. 
You can create a permalink which is also a link inside your main content to link your topic to another similar or helpful topic. Sometimes we can put it in a way that we only pasted the entire link or just used a work then insert the link inside that work to redirect to another page

3 0
3 years ago
Ron was asked to maintain a database to record the height of every student in class.
Fiesta28 [93]

B. =Compare(B3;B4)

hope I helped!!!

4 0
3 years ago
Read 2 more answers
A student is having trouble finding enough time in his busy schedule to work on his school science project. He has a demanding s
Katena32 [7]

Answer:c

Explanation:

got it rii

3 0
3 years ago
Read 2 more answers
Dr. Bloom is writing a test for a history class and wants to ask a question that will have a Boolean value for the answer. Which
Valentin [98]

Answer:

Example

If [variable] = true?

Print(True)

5 0
2 years ago
1 MB equals to how many GBs? Or 1 GB = how many MBs? i want to know how many MBs equal a GB, or how many GBs equal a MB; i'm get
Deffense [45]
Approximately 1,000 MBs are in a gigabyte
5 0
3 years ago
Other questions:
  • C programming question:
    12·1 answer
  • Consider the following code segment. for (int a = 0; a < 10; a++) { for (int b = 10; b > a; b--) { System.out.print("#");
    6·1 answer
  • Making sure that your business has something special and distinct to offer is known as?
    12·1 answer
  • Help please<br>x + 1 = –x + (–5)​
    7·1 answer
  • Can someone help me get spotify premium
    7·2 answers
  • Modify your main.c file so that it allocates a two dimensional array of integers so that the array has 20 rows of 30 integers in
    14·1 answer
  • What is the total number of time zones that can be configured to show by default in a calendar in Outlook 2016?
    13·1 answer
  • ZipCar uses cutting edge wireless technology combined with sophisticated data management and security techniques to assure that
    5·1 answer
  • Kenny is asked to submit a photo for the annual photographic competition. He decided to capture a photo with the light-painting
    15·1 answer
  • Continue your S3 and S4 assignment for a young soccer league with the following specification. Do not include the previous queri
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!