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
kykrilka [37]
4 years ago
12

I have six nuts and six bolts. Exactly one nut goes with each bolt. The nuts are all different sizes, but it’s hard to compare t

hem to each other. (Same for the bolts.) But if I try a nut and a bolt together, it’s easy to see if the nut is smaller than, the same size as, or larger than the bolt. Find a way to use quicksort to match up the nuts and bolts.
Computers and Technology
1 answer:
juin [17]4 years ago
7 0

Answer:

Explanation:

In order to arrange the corresponding nuts and bolts in order using quicksort algorithm, we need to first create two arrays , one for nuts and another for bolts namely nutsArr[6] and boltsArr[6]. Now, using one of the bolts as pivot, we can rearrange the nuts in the nuts array such that the nuts on left side of the element chosen (i.e, the ith element indexed as nutArr[i]) are smaller than the nut at ith position and nuts to the right side of nutsArr[i] are larger than the nut at position "I". We implement this strategy recursively to sort the nuts array. The reason that we need to use bolts for sorting nuts is that nuts are not comparable among themselves and bolts are not comparable among themselves(as mentioned in the question)

The pseudocode for the given problem goes as follows:

// method to quick sort the elements in the two arrays

quickSort(nutsArr[start...end], boltsArr[start...end]): if start < end: // choose a nut from nutsArr at random randElement = nutsArr[random(start, end+1)] // partition the boltsArr using the randElement random pivot pivot = partition(boltsArr[start...end], randElement) // partition nutsArr around the bolt at the pivot position partition(nutsArr[start...end], boltsArr[pivot]) // call quickSort by passing first partition quickSort(nutsArr[start...pivot-1], boltsArr[start...pivot-1]) // call quickSort by passing second partition quickSort(nutsArr[pivot+1...end], boltsArr[pivot+1...end])

// method to partition the array passed as parameter, it also takes pivot as parameter

partition(character array, integer start, integer end, character pivot)

{

       integer i = start;

loop from j = start to j < end

       {

check if array[j] < pivot

{

swap (array[i],array[j])

               increase i by 1;

           }

 else check if array[j] = pivot

{

               swap (array[end],array[j])

               decrease i by 1;

           }

       }

swap (array[i] , array[end])

       return partition index i;

}

You might be interested in
Suppose you are a merchant and you decide to use a biometric fingerprint device to authenticate people who make credit card purc
luda_lava [24]

Answer:

i dont know the answer

Explanation:

3 0
3 years ago
Dominick has been hired to design a network for Pirate Press. In a paragraph of no less than 125 words, discuss what he needs to
Luda [366]
If Dominic is to design a network for Pirate Press he would have to consider and know of the following:
a. Growing capital - he needs to know if the company's sales is growing or is in debt so that he would know what course of action he could take in case he pursues projects for the company. 
b. People/Team - the people/team working are the heart and soul of any company and knowing their specific needs and how they work is key to knowing how the company works as one unit 
c. Marketing of the product - he needs to know how the product sells in order for him to decide what other strategies he can incorporate to make the product more marketable to people.

3 0
3 years ago
Read 2 more answers
Write a method that draws a circle and a square that is centered in a DrawingPanel. The method will take in the width and height
Katarina [22]

Answer:

public static void drawGraphics (Graphics g, int width, int height) {

   int r = Math.round(width/2);

   int x = 45;

   int y = 30;

     g.setColor(Color.RED);

   g.fillRect(x, y, width, height);

   g.setColor(Color.BLUE);

   g.fillOval(Math.round(x/2), Math.round(y/2), r, r);

}

Explanation:

The Java method "drawGraphics" of the Graphics class accepts draws a square with the "fillRect()" method of the Graphics class object and at its center, a circular path is drawn as well.

3 0
3 years ago
What would you NOT use a router for?
Lena [83]
To run applications on your computer

-Apps will run independently from a router.
8 0
3 years ago
In which part of a professional email should you try to be brief, but highly descriptive
aev [14]
The correct answer is the Subject line

The subject line is usually just a very short sentence that presents the problem briefly and straight to the point.
4 0
4 years ago
Other questions:
  • What risks and safeguards are associated with wireless communication? what is “war driving” or “war flying”? are you comfortable
    14·1 answer
  • Differences between iphone 6 and 6s
    6·1 answer
  • Which question best helps a reader understand a plot’s exposition? What will life be like after the character takes action? How
    14·2 answers
  • What is Napoleon's friend's full name? From the Napoleon Dynamite movie.
    9·2 answers
  • The problem with the media giving equal air time to those who are __________ about the effects of media violence on violent beha
    9·1 answer
  • Which spreadsheet toolbar displays options such as Cut and Paste?
    11·2 answers
  • When max() function is used on lists of words, what does max() find? For example:
    13·1 answer
  • What is artificial Intelligence ?
    11·2 answers
  • Who is considered as the father of computer science?​
    11·1 answer
  • What's the difference between an exe file and an msi file?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!