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
Randomly choose rock, paper, or scissors for the computer
Pepsi [2]

import random

computer_choice = random.choice(["rock", "paper", "scissors"])

user_choice = input("rock, paper, or scissors? ")

if computer_choice == user_choice:

   print("It's a draw!")

elif user_choice == "rock" and computer_choice == "scissors":

   print("You win!")

elif user_choice == "paper" and computer_choice == "rock":

   print("You win!")

elif user_choice == "scissors" and computer_choice == "paper":

   print("You win!")

else:

   print("The computer wins!")

I wrote my code in python 3.8. I hope this helps.

8 0
3 years ago
To keep you from inadvertently moving controls as you work in the IDE, click the form or control, then click the _________ optio
Delicious77 [7]

Answer:

Lock Control

Explanation:

Lock Control can used to keep you from inadvertently moving controls while working in the IDE.You can do that by  clicking on the form and then click Lock control in format menu.

In visual studio you have to go to properties and and select Locked property and select True.So that it can be locked and you can unlock them also from here.

5 0
3 years ago
A placeholder for information that will be placed in a document is a _____.A. wizard B. merge field C. merge or D.hyperlink. The
geniusboy [140]

Merge Fields

Merge fields are fields that contain placeholders where you can put email templates such as addresses and greetings. In addition to email templates, you can put mail merge templates and custom links. For instance, a user can place a merge field in an email template so that the salutation or the greeting includes the recipient's name rather than a simple "Hi" or "Hello".

ALT + CTRL + D

From time to time, you may find it important to insert endnotes in your Word document. By default, endnotes appear at the end of the document and a number on endnotes matches up with a reference mark. To insert an endnote, you can click the reference tab or hit the combination keys ALT + CTRL + D

Yes

There are many ready-to-use Microsoft Document Templates available online that can help you jump start your project. If you are searching for a particular layout or style template and you cannot find it, you do not have to create one from scratch. You can search for thousands of templates in the Microsoft Office Online site

4 0
3 years ago
Read 2 more answers
The goal for me is that I need to identify the objects needed for the UNO card game and the actions that those objects perform,
Alik [6]

Answer:

Explanation:

//Java program

class UnoCard{

  private String color;

  private int value;

 

  public UnoCard(String color , int val) {

      this.color = color;

      value = val;

  }

  public String getColor() {

      return color;

  }

  //set the color of the card

  public void setColor(String color ) {

      this.color = color;

  }

  //get the value of the card

  public int getValue() {

      return value;

  }

  //set the value of the card

  public void setValue(int val) {

      value = val;

  }

  //return true if card has same value or

  //same color as the card

  //return false otherwise

  public boolean isMatch(UnoCard card) {

      return (this.value==card.value)||(this.color==card.color);

  }

}

public class Card {

  public static void main(String args[]) {

      UnoCard card1 = new UnoCard("Red",10);

      UnoCard card2 = new UnoCard("Green",10);

      UnoCard card3 = new UnoCard("Blue",15);

     

      if(card1.isMatch(card2))System.out.println("Match");

      else System.out.println("No Match");

     

      if(card2.isMatch(card3))System.out.println("Match");

      else System.out.println("No Match");

  }

}

6 0
4 years ago
PLEASE ILL GIVE BRAINLIEST IMMEDIATELY
leva [86]

Answer:

AI

Explanation:

The answer is Artificial intelligence.

4 0
3 years ago
Other questions:
  • What is the name for an object that is what it appears to be?
    11·1 answer
  • Which of the following is the best definition of a workplace policy?
    13·2 answers
  • _______ is a process that insures that operations meet data validity standards. For instance, information systems that process c
    11·1 answer
  • An investigator responsible for tracking e-mail communication would begin by locating what
    8·1 answer
  • Janice usually works on a particular workbook that contains all business related data. She decides to keep a backup of all the d
    7·2 answers
  • Instagram
    9·1 answer
  • As an improvement of the ATX form factor over AT, shorter wires made it easier to shield them and made them capable of handling
    6·1 answer
  • What are some random fun facts about Technology?
    12·1 answer
  • Fern has set up a computer network for the entire building. Unfortunately, the signal strength diminishes as it reaches toward t
    8·1 answer
  • How do we ensure that future technologies are fair to society?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!