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
Ronald attended a seminar about the best practices to use when browsing the Internet. The presenter used the following statement
Salsk061 [2.6K]

Answer:

Ronald missed the words: One-time password, Secure  

Explanation:

Whenever we use public computer, there are possibilities to steal the user data by hackers. It might not be safe to use as like we have protection in personal or Office computers. But when a situation arises to use a public system, it is always recommended to use one-time password so that the logins are not misused thereafter.

Even if the hackers try to misuse, the user will get a message / authentication reply to use the login and thus we are safe. Also, always browse only secured website ie. “https”.

8 0
3 years ago
Read 2 more answers
Please help! No one is answering these correctly!
nataly862011 [7]

Answer:

it is either c or d

I'm 99.5% sure it is C tho

8 0
3 years ago
I need a 75 word Radio Ad on Why Technology should be kept in a schools budget.
babunello [35]

Answer:

You cant work without it

Explanation:

4 0
2 years ago
Design a class named Car that has the following fields:
snow_tiger [21]

Answer:

// The class car is defined

public  class Car {

  // instance variable yearModel

  private int yearModel;

  // instance variable make

  private String make;

  // instance variable speed

  private int speed;

 

  // empty constructor

  // with instances inside it

  // the instances are from the question

  public Car(){

      yearModel = 2000;

      make = "Nissan";

      speed = 4;

  }  

  // overloaded constructor

  // constructor defined with three arguments

  public Car(int yearModel, String make, int speed) {

      // the arguments are assigned to the object's variable

      this.yearModel = yearModel;

      this.make = make;

      this.speed =speed;

  }

  // setter(mutator) method

  public void setYearModel(int yearModel){

      this.yearModel = yearModel;

  }

  // setter(mutator) method

  public void setMake(String make){

      this.make = make;

  }

  // setter(mutator) method

  public void setSpeed(int speed){

      this.speed = speed;

  }

  // getter(accessor) method

  public int getYearModel(){

      return yearModel;

   }

  // getter(accessor) method

  public String getMake(){

      return make;

   }

  // getter(accessor) method

  public int getSpeed(){

      return speed;

   }  

  // toString is override to display the car object properties

  public String toString(){

      return "Car's year model: " + getYearModel() + ", make: " + getMake() + ", speed: " + getSpeed();

  }

}

Explanation:

The code is well commented.

4 0
3 years ago
The Thing method printMessage prints a string consisting of the name of the object followed by "_is_great". Suppose the name of
Harman [31]

Answer:

Written in C++

The statement that prints the required output is:

<em>printMessage(favFood); </em>

Explanation:

The full program is with comment is:

#include<iostream>

using namespace std;

//The method begins here

void printMessage(string favFood){

//This line prints the required output

cout<<favFood<<"_is_great";

}

//The main method starts here

int main()

{

//This line declares favFood as string

string favFood;

//This line prompts user for input

cout<<"Food: ";

//This line gets the input

cin>>favFood;

//This line calls the printMessage method

printMessage(favFood);

return 0;

}

4 0
3 years ago
Other questions:
  • For a list to be binary search-able, we need the following thing to be true, because... a. The list must be sorted, because chec
    11·1 answer
  • which one of these steps describe saving a newly created file. click on the save icon. minimize the file. name the file. select
    12·2 answers
  • Both successors to C++, _____ , by Sun Microsystems, and _______, by rival MicroSoft, are very similar.
    5·1 answer
  • Which is an advantage that electronic scheduling tools have over paper calendars?
    13·2 answers
  • 3. A vulnerability is: a. A hacker searching for open ports b. A known attack method c. An incorrectly implemented policy d. All
    7·1 answer
  • You will implement three different types of FFs with two different reset types. You have to show your results on your FPGA. You
    9·1 answer
  • A record is a specific piece of information state true or false​
    12·1 answer
  • Your program will be used by many departments at the university. Your comments will be important to their IT people. What would
    15·1 answer
  • (--BRAINLIEST--)<br>Explain the types of secondary memory on the basis of data access.​
    8·2 answers
  • Assume that students in a course are required to produce a written report on an ICT-related
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!