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
Computer forensics is practiced _____. A. Only by specially trained government and law-enforcement personnel B. By many organiza
laiz [17]

Answer:

Option B is the correct answer.

<h3>Computer forensics is practiced by many organizations, including public- and private-sector organizations such as hospitals, law enforcement, and businesses. </h3><h3 />

Explanation:

Computer forensics can be defined as a branch of digital forensics that deals with the evidences and and proofs found on all digital storage media such as computers.

It is basically a step for enhancing security bases of communication. Therefore it is mainly used by law-enforcement personnel but it can also be practiced by other institutions for the purpose of self security.

<h3>I hope it will help you!</h3>
4 0
3 years ago
Compare physical storage and virtual storage. Give an example of each and explain why one type allows computers to access data a
Nuetrik [128]
Physical storage is like your Hard Drive, Virtual is what is called the Cloud. Hard drives are able to pull information directly from inside the computer while the cloud has to do over the internet.
8 0
4 years ago
17. Which of the following game development companies is credited with launching and perfecting the sports simulation genre?
allochka39001 [22]
I think it is D
Hope this help you؟
3 0
3 years ago
Write a program that accepts a whole number as input, multiplies that number by 12, and then outputs the product
kenny6666 [7]

The program accepts a whole number as input, multiplies that number by 12, and then outputs the product

Explanation:

This program asks user to enter two integer numbers and displays the product.

The scanner class is used as input functions.

The code is shown below :  

import java.util.Scanner;

public class Demo {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter number: ");

int num1 = scan.nextInt();

scan.close();

int product = num1*12;

System.out.println("Output: "+product);

   }

}

5 0
4 years ago
Read 2 more answers
_____ represents an entity in the real world that can be distinctly identified.
Margaret [11]

Answer:An object

Explanation: An objects play an important role as the  real world component/entity which display any element which are sourced through their behaviors and different states. Object are the entities that are required in the program for the making the program easier and simpler to understand .

Example- computer can be considered as the object which is related with the  real world.

4 0
3 years ago
Other questions:
  • You’ve received a tarball called data79.tar from a colleague, but you want to check the names of the files it contains before ex
    15·1 answer
  • Which is a challenge in photographing forests
    14·2 answers
  • A section-lined area is always completely bounded or outlined by an?
    11·1 answer
  • The strategy in which you periodically look away from the text and ask yourself about the material is called the
    8·2 answers
  • Animation includes special visual and sound effects applied to text or other content. true or false.
    14·1 answer
  • A) Suppose a computer has an instruction pipeline with 4 phases. How many cycles (if there are no delays) would it take to compl
    13·1 answer
  • Kenny needs to keep client information such as names and addresses. She should use a
    7·2 answers
  • It is believed that Taiwan is the original home of these early Oceania explorers. Maori Lapita Polynesians Aborigines
    13·2 answers
  • Which of the following statements represents a scientific bias?
    15·1 answer
  • What will happend when I got a BSOD in Windows?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!