Write the pseudocode that uses two arrays

Assignment Help JAVA Programming
Reference no: EM132430569

Scenario

Selection sort is best understood by imagining that you have two lists, Aand B. Initially, we have list A, containing all the unsorted elements, and list B is empty. The idea is to use B to store the sorted elements. The algorithm would work by finding the smallest element from A and moving it to the end of B. We keep on doing this until A is empty and B is full. Instead of using two separate lists, we can use the same input array, keeping a pointer to divide the array in two.

In real life, this can be explained by picturing how you would sort a deck of cards. Using a shuffled deck, you can go through the cards one by one until you find the lowest card. You set this aside as a new, second pile. You then look for the next-lowest card and once found, you put it at the bottom of the second pile. You repeat this until the first pile is empty. 

One way to arrive at the solution is to first write the pseudocode that uses two arrays (A and B, in the preceding description). Then, adopt the pseudocode to store the sorted list (array B) in the same input array by using the swap method. 

Aim

Implement selection sort in Java.

Prerequisites

  • The sort() method should accept an integer array and sort it. 

Steps for Completion

  1. Split the input array in two by using an array index pointer. 
  2. The sort method should accept an integer array and sort it. 
  3. Iterate over the unsorted portion of the array to find the minimum.
  4. The minimum item is then swapped so that it can be added to the end of the sorted portion.

 

public class SelectionSort {

 

  // Write your code here

 

  public static void main(String[] args) {

    /*  

    * This main method is a stub.

    * It does nothing.

    * Feel free to write your own code to test your implementation.

    * In this case, we have nothing actionable in here, just this comment block, so the JVM should rapidly lose interest and move on to the rest of your code.

    */

  }

 

}

Reference no: EM132430569

Questions Cloud

How do the four components of culture : What does your chosen theorist say about the role of culture in shaping human behavior?How do the four components of culture?
Program that tracks goldfish stored in fish tanks : Implement a program that tracks goldfish stored in fish tanks. The FishTank class includes:
Design an application for the sublime sandwich shop : Design an application for the Sublime Sandwich Shop. The user makes sandwich order choices from list boxes, and the application displays the price.
Form field validation and error messages : You have created a basic form and added interactivity to images using JavaScript. Now it is time to validate information entered into your form fields
Write the pseudocode that uses two arrays : Selection sort is best understood by imagining that you have two lists, Aand B. Initially, we have list A, containing all the unsorted elements
Explain ways addiction impacts physical well being of client : explain how gender might influence the physical, emotional, and spiritual well being of clients with problems.Explain ways addiction impacts physical well being
Improve the performance of program : In a Java program that used a sequential file, how or why would would using either a random access or index sequential file improve the performance
Provide a standard three-parameter constructor : Provide a standard three-parameter constructor for a class named CellPhone. The class contains three instance variables-manufacturer, model, and price
Generate an application named studentsstanding : Generate an application named StudentsStanding.java that allows you to enter student data that consists of an ID number

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program to handle applications

Write a Java program to handle applications for universities admission providing a much better user interface than in the program discussed in the lecture

  Write a recursive program to compute the number of ways in

write a recursive program to compute the number of ways in which an integer k can be written as sum each of whose

  Write a javascript program that perform a simple calculation

Write a javascript program that will read a form and perform a simple calculation. The output will then be written to the page, and you will embed your script.

  What value would be returned from call to its size() method

If a collection stores 5 objects, what value would be returned from a call to its size() method?

  Flexirent rental property management program

COSC1295 Advanced Programming - develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1

  Java data structures

Project is to create a German-English, English-German, French-English, English-French dictionary. You will be responsible for entering a total of twenty-five words in German, the part of speech each word represents and its English meaning. Please use..

  Enterprise java beans (ejb) in software development

Enterprise Java Beans (EJB) in software development, EJB technology, EJB application, Stateless Session Beans (SLSB), Stateful Session Beans (SFSB), Message Driven Bean (MDB), Entity Bean

  Write a generic class pair which has 2 type parameters

Write a generic class Pair which has 2 type parameters, F and S, representing the type of the first and second elements of a pair respectively

  What output will be produced by the code

Consider the loop which is an inefficient (at best) attempt to increment count 200 times - What values are stored in firstNum

  The ai player will not be asking

The AI player will not be asking the user for any input. This means that placeShips() and fire() should not ask the user for locations. The AI player should choose locations of ships and automatically place them

  What vulnerabilities might these threats exploit

What special consequences do you foresee from information security breaches confined to online retail banking compared to online commercial banking?

  Write a java program which reads a text file

Write a Java program which reads a text file and writes the content into a new file. During the read-write process, convert all the upper case letters.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd