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
USPshnik [31]
3 years ago
6

An integer x and a sequence b,...b, of integers is given. The problem is to find indices i, j, such that b,+b, = x . Suggest a d

ata structure and/or an algorithm for answering such questions and analyze their complexity. (Try to optimize the asymptotic complexity of your solution.)
Computers and Technology
1 answer:
stepladder [879]3 years ago
8 0

Answer:

Algorithm -

1.Firstly, Sort(b)

2.Then, Set i=0,j=n-1,flag=1

3.When, while(i<j)

4.Then, Set if b[i] + b[j] == x

5.Then, flag=0

6.Then, break the following condition.

7.Set if b[i] + b[j] < x //when the following condition is true

8.Then, the value of i increase i=i+1

9.Either, else

10Then, the value of j decrease j=j-1

11.Then, Set if flag == 0

12.And print b[i],b[j]

13.Otherwise else

14. no such pair exists.

Time complexity analysis -

Sort - O(nlogn)

while loop - O(n)

Total - O(nlogn)+O(n) = O(nlogn)

Explanation:

Firstly, sort these sequence(array) of the integers. It takes O(N log N) time if done with the Merge Sort or the Heap Sort or any other sorting the algorithm within less time complexity.

After that, take two indices one at the start and one at the end. Traverse these array from the start to the end based on the sum of the values.

You might be interested in
So this is what i use to code and all of that
givi [52]

Answer: yeah!

Explanation:

Have a good day!

5 0
3 years ago
Can someone help my friend play over-watch she new do it. I can't help her on Friday (p.s she play on Xbox she will get it on Fr
ss7ja [257]

There should be a place on the Xbox where you can download games. Go there and type in overwatch.

Hope this helped!

5 0
3 years ago
Pls help! 7th grade pythin fyi
larisa [96]

Answer:

There should be a colon at the end of the if statement, ie:

<h2>if x > 100:</h2><h2>  print("...")</h2>

8 0
3 years ago
Read three numbers from user input. Then, print the product of those numbers. Ex: If input is 2 3 5, output is 30. Note: Our sys
Murrr4er [49]

Answer:

This is written in Python 3. And I am assuming that since the output is "30", which is derived from the inputs 2, 3, and 5, these three are multiplied to get the final output.

<em>fnum = int(input('Enter first number: '))</em>

<em>snum = int(input('Enter second number: '))</em>

<em>tnum = int(input('Enter third number: '))</em>

<em />

<em>output = (fnum * snum) * tnum</em>

<em>print ("The output is:", output)</em>

Explanation:

For the first three lines, we ask the user to input 3 numbers. At the same time, we are also converting these inputs into int type.  

  • fnum = int(input('Enter first number: '))
  • snum = int(input('Enter second number: '))
  • tnum = int(input('Enter third number: '))

The breakdown here is as follows:

  • fnum, snum, and tnum are user-defined variables which will hold the user's inputs.
  • int() is needed to define that everything inside it is an integer. If we don't first convert the input to integers, we will receive an error during multiplication saying that we cannot multiply non-int type variables. You can also choose to use Float here instead of Int - in which case, it will be float().
  • input('Enter first number:' )) - this is the part where we ask the user to enter the number they want.

Put together, it looks like this:

<em>variable = int(input('Your Custom Text Here: '))</em>

<em />

The next block would be:

  • output = (fnum * snum) * tnum

This is where we multiply the first, second, and third number to get to the output.

Finally, we print it with:

  • print ("The output is:", output)

Concatenating a string and variable looks like this.

print("text here", output) - when concatenating a string and a variable, simply add a comma after the quotation marks of the string.

8 0
3 years ago
//TO-DO: Fill in the Authors Name Here//TO-DO: Fill in the current date here//CS1428 Lab//Lab 10//Description: this program will
slamgirl [31]

Answer:

countLetterGrades:

void countLetterGrades(double grades[], const int SIZE, int &numberOfAs,int &numberOfBs,int &numberOfCs,int &numberOfDs,int &numberOfFs) {

for(int i = 0; i < SIZE; i++){

if(grades[i]>85){numberOfAs++;}

else if(grades[i]>75){numberOfBs++;}

else if(grades[i]>65){numberOfCs++;}

else if(grades[i]>55){numberOfDs++;}

else{ numberOfFs++;}

}

}

printData:

void printData(double average, int numberOfAs,int numberOfBs,int numberOfCs,int numberOfDs,int numberOfFs)

{

cout<<"Average: "<<average<<endl;

cout<<"Number of A's: "<<numberOfAs<<endl;

cout<<"Number of B's: "<<numberOfBs<<endl;

cout<<"Number of C's: "<<numberOfCs<<endl;

cout<<"Number of D's: "<<numberOfDs<<endl;

cout<<"Number of F's: "<<numberOfFs<<endl;  

}

Explanation:

<em>Your question is poorly formatted. (See attachment for proper presentation of question)</em>

------------------------------------------------------------------------------------------------------------

The first step is to go to the main function and replace

//TODO: Add function calls

with the following 4 lines of code:

<em>getGrades(grades,SIZE); </em>

<em>average = getAverage(grades,SIZE); </em>

<em>countLetterGrades(grades, SIZE, numberOfAs,numberOfBs,numberOfCs,numberOfDs,numberOfFs); </em>

<em>printData(average, numberOfAs,numberOfBs,numberOfCs,numberOfDs,numberOfFs); </em>

------------------------------------------------------------------------------------------------------------

1. getGrades(grades,SIZE);

This calls the getGrade functions; The getGrade function is where the user inputs 5 grades for a student

2. average = getAverage(grades,SIZE);

Next, is to get the average of the input grades. This is done using the above and the average is stored in variable average

3. countLetterGrades(grades, SIZE, numberOfAs,numberOfBs,numberOfCs,numberOfDs,numberOfFs);

Next, is to get letter grade of each number grade. This is done using countLetterGrades function.

4. printData(average, numberOfAs,numberOfBs,numberOfCs,numberOfDs,numberOfFs);

The above 3 functions populate data for average, numberofAs to numberofFs; This values are passed to printData function to to display program output.

------------------------------------------------------------------------------------------------------------

Next complete countLetterGrades and printData functions as seen in the answer section.

<em>For clarity, see the attached cpp file for line by line explanation of the complete code </em>

7 0
3 years ago
Other questions:
  • Write in general about ergonomic injuries and also mention the symptoms that computer users exhibit when they experience these s
    11·2 answers
  • What is the only true way to wipe out every possibility of the virus?
    11·1 answer
  • What is the purpose of look up tables in spreadsheet software apex
    13·1 answer
  • Codio Challenge Question (Python)
    6·1 answer
  • 897,100 rounded to the nearest hundred thousand is
    8·1 answer
  • A tablet computer is a low-cost, centrally managed computer with no internal or external attached drives for data storage.
    10·1 answer
  • Your job as a researcher for a college is going well. You have gained confidence and skill at pulling data and you are not makin
    13·1 answer
  • Resumen sobres el correo electrónico​
    6·1 answer
  • Pixar is a company that creates a huge amount of images, audio recordings, and videos, and they need to decide what compression
    11·1 answer
  • Write code which takes two inputs from the user, a number of sides followed by a side length, then creates a regular polygon wit
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!