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]
3 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]3 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
Write a program that accepts a positive integer N as command-line argument, and outputs True if N is the square of some integer,
Ann [662]

Answer:

In Python:

N = int(input("Positive integer: "))

if N > 0:

   flag = False

   for i in range(1,N+1):

       if i * i == N:

           flag = True

           break

   print(str(flag))

else:

   print("Positive integer only")

   

Explanation:

N = int(input("Positive integer: "))

If the number is positive

if N > 0:

This initializes a boolean variable to false

   flag = False

This iterates from 1 to the input integer

   for i in range(1,N+1):

This checks if th number is a square of some integer

       if i * i == N:

If yes, flag is set to true

           flag = True

The loop is exited

           break

This prints either true or false, depending on the result of the loop

   print(str(flag))

If otherwise, that the number is not positive

<em>else:</em>

<em>    print("Positive integer only")</em>

3 0
3 years ago
What is the default setting Excel shows when Insert is clicked?
NikAS [45]

Answer: entire column

7 1
4 years ago
Read 2 more answers
1. Ce este o baza de date? (1p)
lesya [120]

Answer:

would you mind telling me what this says im still learning my spanish

Explanation:

6 0
2 years ago
Read 2 more answers
This script should:
denis23 [38]

Answer:

the answer is d

Explanation:

5 0
3 years ago
Get the user to enter some text and print it out in reverse order.
svetlana [45]

Answer:

strrev in c/c++

Explanation:

3 0
2 years ago
Other questions:
  • A network administrator is implementing dhcpv6 for the company. the administrator configures a router to send ra messages with m
    6·1 answer
  • The support group at Universal Containers wants agents to capture different information for product support and inquiry cases. I
    14·1 answer
  • what properties are associated with all Microsoft Office files and include author, title, and subject
    5·1 answer
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • Select the correct answer.
    6·2 answers
  • Should the use of hacktivists by a country against enemy organizations be considered an act of war? Why or why not? How about th
    8·1 answer
  • The image below shows an encoding for a black and white pixel image. The first two
    13·1 answer
  • Create a public class Dog that stores a single double age set by the constructor. (Reject negative ages using assert.) Dog shoul
    13·1 answer
  • How you use ict today and how will you use it tomorrow
    14·1 answer
  • What’s cloud-based LinkedIn automation?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!