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]
2 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]2 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
Calculate the shear stress (lbf/in^2) for a given normal stress (lbf/in^2) that is applied to a material with a given cohesion (
LenaWriter [7]

MOHR-COULOMB FAILURE CRITERIA:

In 1900, MOHR-COULOMB states Theory of Rupture in Materials which defines as “A material fails due to because of a critical combination of normal and shear stress, not from maximum normal or shear stress”. Failure Envelope is approached by a linear relationship.

If you can not understand the below symbols see the attachment below

 f   f ()  

Where:      f = Shear Stress on Failure Plane  

       ´= Normal Stress on Failure Plane

 See the graph in the attachment

For calculating the shear stress, when Normal stress, cohesion and angle of internal friction are given. Use this formula:   shear stress =  f  c   tan 

Where,  

• f  is Shear Stress on Failure Plane

• c  is Cohesion

•  is Normal Total Stress on Failure Plane

•  is Friction Angle

8 0
3 years ago
Which of the following technologies uses the results of a scientific discovery?
belka [17]
D. All of these
Reason being, they wouldn't have been made if something hasn't been discovered about them.

4 0
2 years ago
Read 2 more answers
What is one effective way for employees to keep their skillsets current
iragen [17]
<span> Create a large personal network online</span>
4 0
3 years ago
MORE THAN ONE ANSWER!
borishaifa [10]

Answer:

YES to all the options given.

- Formatting rows and columns is similar to cell formatting.

- You can insert rows and columns into, or delete rows and columns from, a spreadsheet.

- You can hide or show rows and columns in a spreadsheet.

- You can adjust the height of rows and width of columns.

Explanation:

Formatting rows and columns is similar to cell formatting.

Yes, you can apply basically the same formats to columns and rows as you do with cells, like background, bold, text justification, number formats and much more.

You can insert rows and columns into, or delete rows and columns from, a spreadsheet.

Yes, you can easily add or delete rows and columns from a spreadsheet.

You can hide or show rows and columns in a spreadsheet.

Yes, that is common to hide rows or columns to mask some data, then to unhide them.

You can adjust the height of rows and width of columns.

Yes, absolutely, you can also specify to wrap text that is too long to fit in the width of the cells.

6 0
2 years ago
Read 2 more answers
Why do designers use tonal shading?
Simora [160]

Designers use tonal shading because tonal shading gives a drawling dimension.


Hopefully this will help you out! :)

4 0
2 years ago
Read 2 more answers
Other questions:
  • When did the silver market drop sharply, hurting Bolivia's income?
    7·2 answers
  • A(n) _____ is similar to a virus, except that it is an independent program that can be spread across computer networks without b
    11·1 answer
  • List and explain the error in the code
    14·1 answer
  • What is an input, output and storage device?
    12·1 answer
  • The "origin" of the cartesian plane in math is the point where x and y are both zero. Given a variable, origin of type Point-- a
    5·1 answer
  • What does ;-; mean during a text?
    8·2 answers
  • Subscript numbering always starts at what value?
    14·1 answer
  • Which shot is not the best for a widescreen image
    11·2 answers
  • 13. Place where names, addresses and email information<br> is stored
    6·1 answer
  • What is Japanese tradition?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!