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
goblinko [34]
4 years ago
5

Write pseudocode to solve the following problem: You are given an array A[1 . . . n] whose each element is a point of the plane

(x, y). You need to sort the array so that points with lower x-coordinate come earlier, but among points with the same x-coordinate, the ones with larger y-coordinate come earlier. So, for example if the array contains, (1, 2),(1, 4),(7, 10),(11, 3),(14, 1),(7, 2) The output in this case should be: (1, 4),(1, 2),(7, 10),(7, 2),(11, 3),(14, 1). Analyze the running time of your algorithm as a function of n.
Computers and Technology
1 answer:
bixtya [17]4 years ago
5 0

Answer:

Answer explained below

Explanation:

void bubbleSort(int X[], int Y[], int n)

{

   int i, j;

   for (i = 0; i < n-1; i++)      

     

   // Last i elements are already in place

   for (j = 0; j < n-i-1; j++)

       if (X[j] > X[j+1])

{

swap(X[j],X[j+1])

swap(Y[j],Y[j+1]);

}

       if (X[j] == X[j+1]&&Y[j]<Y[j+1])

{

swap(X[j],X[j+1])

swap(Y[j],Y[j+1]);

}

}

Since the above algorithm contains 2 nested loops over n.

So, it is O(n^2)

You might be interested in
Matlab In this assignment you will write a function that will calculate parallel resistance for up to 10 parallel resistors. Cal
Ket [755]

Answer:

The complete Matlab code along with step by step explanation is provided below.

Matlab Code:

function Req=ParallelR(Number)

Number=input('Please enter the number of resistors: ');

if Number>10 | Number<=0

   disp('Invalid input')

return

end

R=0;

for i=1:Number

r=input('Please enter the value of resistor: ');

R=R+1/r;

end

Req=1/R;

end

Explanation:

Parallel resistance is given by

\frac{1}{Req} = \frac{1}{R_{1}} + \frac{1}{R_{2}} + \frac{1}{R_{3}}...+\frac{1}{R_{N}}

First we get the input from the user for how many parallel resistors he want to calculate the resistance.

Then we check whether the user has entered correct number of resistors or not that is from 1 to 10 inclusive.

Then we run a for loop to get the resistance values of individual resistors.

Then we calculated the parallel resistance and keep on adding the resistance for N number of resistors.

Output:

Test 1:

Please enter the number of resistors: 3

Please enter the value of resistor: 10

Please enter the value of resistor: 20

Please enter the value of resistor: 30

ans =       60/11

Test 2:

Please enter the number of resistors: 11

Invalid input

Test 3:

Please enter the number of resistors: 0

Invalid input

8 0
3 years ago
Anyone got E-aqa login?​
pashok25 [27]

Answer:no

Explanation:

3 0
3 years ago
Powerpoint provides only three picture effects. true or false.
scZoUnD [109]
False, there is a variety
4 0
3 years ago
Technology, by itself is neither good nor bad.<br> A) true<br> B) false
sukhopar [10]

Answer:

true

Explanation:

I'm pretty sure it's true. I took coding class and something similar came up, but not 100% sure tho

8 0
3 years ago
Read 2 more answers
When you first log into linux, what is the current working directory?
mina [271]
This will depend on what the user has set the default working directory to. In order to check for yourself what your default working directory is inside linux, simply log in, click the start button>Click System Tools>LXTerminal. Once in the terminal, you can check your current working directory by typing in "pwd" without the quotation marks. Then, hit enter on your keyboard and the terminal will print your current working directory. I hope this has helped you.
6 0
4 years ago
Other questions:
  • An organization’s IRP prioritizes containment over eradication. An incident has been discovered where an attacker outside of the
    5·1 answer
  • All ofthe following are correct EXCEPT one option when it comes towriting disappointing news letters. Identify theexception.
    6·1 answer
  • A ________ allows users to add, remove, or edit its content.
    10·2 answers
  • Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle’s
    9·1 answer
  • ______ is a disadvantage of EDI.
    8·1 answer
  • Learning how to use software takes time. So, after customers have learned to use a particular software package, it is easier to
    11·1 answer
  • 71 81 77 15 63 96 36 51 77 18 17
    14·1 answer
  • A keyboard would be considered _____. Select 2 options.
    13·2 answers
  • 2. "The only requirement for a person to use a computer is that you should be able to read and
    7·1 answer
  • When passing a list of parameters to a stored procedure by name, you can omit optional parameters by:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!