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
astraxan [27]
3 years ago
9

Write a Java class to perform the following: 1. Write a method to search the following array using a linear search, ( target ele

ments: 11, 55, 17.). (count the number of comparisons needed). {06, 02, 04, 07, 11, 09, 50, 62, 43, 32, 13, 75, 01, 46, 88, 17} 2. Write a method to sort the array using Selection Sort. (count the number of comparisons needed) 3, Write a method to sort the array using Bubble Sort. (count the number of comparisons needed) 4, Search he sorted array using a binary search (recursive) for the same set of target elements. (count the number of comparisons needed)

Computers and Technology
1 answer:
Alina [70]3 years ago
7 0

Answer:

Check the explanation

Explanation:

Linear search in JAVA:-

import java.util.Scanner;

class linearsearch

{

  public static void main(String args[])

  {

     int count, number, item, arr[];

     

     Scanner console = new Scanner(System.in);

     System.out.println("Enter numbers:");

     number = console.nextInt();

   

     arr = new int[number];

     System.out.println("Enter " + number + " ");

     

     for (count = 0; count < number; count++)

       arr[count] = console.nextInt();

     System.out.println("Enter search value:");

     item = console.nextInt();

     for (count = 0; count < number; count++)

     {

        if (arr[count] == item)

        {

          System.out.println(item+" present at "+(count+1));

         

          break;

        }

     }

     if (count == number)

       System.out.println(item + " doesn't found in array.");

  }

}

Kindly check the first attached image below for the code output.

Selection Sort in JAVA:-

public class selectionsort {

   public static void selectionsort(int[] array){

       for (int i = 0; i < array.length - 1; i++)

       {

           int ind = i;

           for (int j = i + 1; j < array.length; j++){

               if (array[j] < array[ind]){

                   ind = j;

               }

           }

           int smaller_number = array[ind];  

           array[ind] = array[i];

           array[i] = smaller_number;

       }

   }

     

   public static void main(String a[]){

       int[] arr = {9,94,4,2,43,18,32,12};

       System.out.println("Before Selection Sort");

       for(int i:arr){

           System.out.print(i+" ");

       }

       System.out.println();

         

       selectionsort(arr);

       

       System.out.println("After Selection Sort");

       for(int i:arr){

           System.out.print(i+" ");

       }

   }

}  

Kindly check the second attached image below for the code output.

Bubble Sort in JAVA:-

public class bubblesort {

   static void bubblesort(int[] array) {

       int num = array.length;

       int temp = 0;

        for(int i=0; i < num; i++){

                for(int j=1; j < (num-i); j++){

                         if(array[j-1] > array[j]){

                           

                                temp = array[j-1];

                                array[j-1] = array[j];

                                array[j] = temp;

                        }

                         

                }

        }

   }

   public static void main(String[] args) {

               int arr1[] ={3333,60,25,32,55,620,85};

               

               System.out.println("Before Bubble Sort");

               for(int i=0; i < arr1.length; i++){

                       System.out.print(arr1[i] + " ");

               }

               System.out.println();

                 

               bubblesort(arr1);

               

               System.out.println("After Bubble Sort");

               for(int i=0; i < arr1.length; i++){

                       System.out.print(arr1[i] + " ");

               }

 

       }

}  

Kindly check the third attached image below for the code output.

Binary search in JAVA:-

public class binarysearch {

  public int binarySearch(int[] array, int x) {

     return binarySearch(array, x, 0, array.length - 1);

  }

  private int binarySearch(int[ ] arr, int x,

        int lw, int hg) {

     if (lw > hg) return -1;

     int middle = (lw + hg)/2;

     if (arr[middle] == x) return middle;

     else if (arr[middle] < x)

        return binarySearch(arr, x, middle+1, hg);

     else

        return binarySearch(arr, x, lw, middle-1);

  }

  public static void main(String[] args) {

     binarysearch obj = new binarysearch();

     int[] ar =

       { 22, 18,12,14,36,59,74,98,41,23,

        34,50,45,49,31,53,74,56,57,80,

        61,68,37,12,58,79,904,56,99};

     for (int i = 0; i < ar.length; i++)

        System.out.print(obj.binarySearch(ar,

           ar[i]) + " ");

     System.out.println();

     System.out.print(obj.binarySearch(ar,19) +" ");

     System.out.print(obj.binarySearch(ar,25)+" ");

     System.out.print(obj.binarySearch(ar,82)+" ");

     System.out.print(obj.binarySearch(ar,19)+" ");

     System.out.println();

  }

}

Kindly check the fourth attached image below for the code output

You might be interested in
The _____ is the area in Microsoft Excel where you can perform file commands such as Save, Open, and Print
Arlecino [84]
The BACKSTAGE VIEW is the area in Microsoft where one can perform file commands such as save, open and print.
The backstage view can be found under the file tab in the excel window. It has many options available and they include the following:info, new, open, save, save as, print, share, export and close. These options give the user the opportunity to perform desired functions on their workbook.
8 0
3 years ago
What is the purpose of a career portfolio?
morpeh [17]

Answer:

To provide relevant information in a job interview

Explanation:

4 0
3 years ago
When reading words using a Scanner object's next method, _________. a. any characters at the beginning of the input that are con
zavuch27 [327]

Answer:

The answer is "Option d"

Explanation:

The scanner method is the full token of the process, that finds and returns. It is token, which is followed by both the inputs meeting and the guideline template. This method can block, even though the former instance of hasNext() is true while waiting for input, and wrong choices can be described as follows:

  • In option a, It is incorrect because the character at the beginning can't be considered.
  • In option b, It is wrong because the characters are known as the word in which blank space not a part of the word.
  • In option c, It is wrong because in this input before the call is not the method.
3 0
3 years ago
What is the significance of the Abstract section of a research paper? A. It contains important information such as the author, c
Bond [772]

Answer: A

Explanation:

7 0
3 years ago
Now let's create a memo. The memo should include all parts of a memo, and these parts should appear in the correct order. In you
netineya [11]

Answer:

MEMORANDUM

TO: Stacy Shoe, Allen Sock, and Emma Johnson.

FROM: Department of Information

DATE: 20th of December, 2019

SUBJECT: Computer Operations

The following is an illustration of how to start a computer and how to open an existing word processing document. For clarity and ease of understanding, this will be divided into two subheadings. All questions should be directed to the department of information.

START A COMPUTER

Step 1: Press the start button on the CPU tower.

Step 2: Wait while the computer boots. When the computer has finished booting, it will show a dialogue box that will ask for a user name and password.

Step 3: Enter your user name and password, then click

"OK."

Step 4: Your computer is now ready to use.

OPENING A WORD PROCESSING DOCUMENT

To open any word processing documents, you can use any of the options below.

1. Double-click file

In some cases, you can double-click a file to open it in Microsoft Word. However, the file will only open in Microsoft Word if that file type is associated with Microsoft Word. Word documents, like .doc and .docx files, are associated with Microsoft Word by default. However, web page files, text, and rich text format files are often not associated with Word by default, so double-clicking on these files may open in another program.

2. Right-click file and select program

For any file, you can choose the program to open a file with, including Microsoft Word.

Step 1: Right-click the file you want to open.

Step 2: In the pop-up menu, select the Open with option.

Step 3: If available, choose the Microsoft Word program option in the Open with menu. If Microsoft Word is not listed, select the Choose other app or Choose default program option, depending on the

Step 4: In the window that opens, find Microsoft Word in the program list and select that option. Microsoft Word should open and the file opened within Word.

3. Open within Microsoft Word

Follow the steps below to open a file from within Microsoft Word.

Step 1: Open the Microsoft Word program.

Step 2: Click the File tab on the Ribbon and click the Open option.

Step 3: If the Open window does not appear, click the Browse option to open that window.

Step 4: In the Open window, find and select the file you want to open in Microsoft Word. You may need to click the drop-down list next to the File name text field to change the file type to that of the file you want to select and open.

Step 5: Click the Open button at the bottom right of the Open window.

As stated above, all questions are to be directed to the department of information.

Thanks.

Explanation:

5 0
3 years ago
Other questions:
  • ----------HELP WITH 3 QUESTIONS FOR 30 POINTS!!!---------
    6·1 answer
  • ____ languages create source code using words and structures similar to spoken language.​
    15·1 answer
  • Write a method reverse( ) for OurLinkedList class. The method should return a new OurLinkedList object that is the reverse of th
    8·1 answer
  • You need to install an operating system on a computer that will be sharing files for the company employees. You estimate there w
    9·1 answer
  • Which of the following is the code of acceptable behaviors users should follow while on the Internet; that is, it is the conduct
    15·1 answer
  • How does a author develop a character in a story?
    14·2 answers
  • Scenario
    7·1 answer
  • Why should running your unit test suites not take a long time?A. Unit tests aren't that important, so less time should be spent
    5·1 answer
  • Multi-part question:
    13·1 answer
  • Windows is a GUI Operating System, what is the other type?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!