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]
3 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]3 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
An understanding of basic psychology can help design and marketing teams ensure they meet their intended audience.
Kamila [148]

Answer:

um true i think cause to understand something or someone you have to help it to find it place in the world by make design for them and have a team to help you so they can that there audience if that help you plz mark me brainliest if not then you don't have to

Explanation:

5 0
3 years ago
Read 2 more answers
What is the primary purpose of endnotes?
mihalych1998 [28]

Answer:

They acknowledge the source of a quotation, paraphrase, or summary; and (2) They provide explanatory comments that would interrupt the flow of the main text.so its B

5 0
2 years ago
Read 2 more answers
The first computer program was used to help the analytical engine calculate numbers. Who invented that program?
nikdorinn [45]

Answer:

Charles Babbage

Explanation:

Analytical engines were presumed to be the first general-purpose computer which was designed sometime in the 19th century by Charles Babbage -  a British mathematician and inventor. A series of punch cards was used by Charles Babbage in his design of the engine. These punch cards were used for various operations such as arithmetical operations, numerical constants and other operations such as load and store.

<em>Hope this works!</em>

8 0
3 years ago
Constructive criticism is intended as a possible solution.
wlad13 [49]

Answer:

True

Explanation:

Constructive criticism is a comment that cuts down on someone, but in an influencing way.

Example: Let's ask him to be more careful the next time he buys fish.

7 0
2 years ago
What is the other name of iterative staatement ​
Mademuasel [1]

Answer:

An loop statement

Explanation:

An iteration statement, loop, repeatedly executes a statement, know as a loop body,until the controlling expression is false

8 0
3 years ago
Other questions:
  • Given an array declared to hold 100 values, the smallest index that can be used with the array is
    7·1 answer
  • . Reorder the following efficiencies from smallest to largest:
    9·1 answer
  • Once you select select a crop boundary, you can no
    15·1 answer
  • The Cursor is blinking in a white area on the Screen. This area where text will appear in the ____.
    10·2 answers
  • How do i do a class in java??
    5·1 answer
  • When Russ opened a website on his browser, he saw an error that the site was not compatible with the browser version he was runn
    9·1 answer
  • What is the primary way to access applications in window 10
    7·1 answer
  • GIVING BRAINLIST TO WHOEVER ANSWERS
    9·1 answer
  • What is computer code?<br> A. Java Script<br> B. XML<br> C. HTML<br> D. Any programming language
    6·1 answer
  • State any three reasons why users attach speakers to your computer​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!