Question

Qi. Create a java project Question that includes: • A bubble sort method to sort your arrays. Implement the below recursive b

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  import java.io.*; class Question1 {   public static void bubble_sort(char[] a){ int size = a.length; for(int i=0;i<size-1;i++){ for(int j=i+1;j<size;j++){ if(a[i]>a[j]){ char temp; temp = a[i]; a[i] = a[j]; a[j] = temp; } } } } public static int bin_search(char[] a,char value,int left,int right){ if(left>right) return -1; int mid = (left+right)/2; if(a[mid] == value) return mid; else if(value > a[mid]) return bin_search(a,value,mid+1,right); else return bin_search(a,value,left,mid-1); } public static void main(String[] args){ char[] a = {'b','c','d','a','e'}; bubble_sort(a); char value = 'c'; for(char c:a) System.out.println(c); int x = bin_search(a,value,0,a.length-1); System.out.println("element found "+x); } } 

The question is answered as per the requirement given.

Feel free to ask query if found stuck at any moment.

Thank you :) .....

U can organize it as in the screen shot.

import java.io.*:| class GFG { public static void bubble_sort(char[] a){ int size = a.length; for(int i=0;i< size-1; i++) { fpublic static void main(String[] args) { char[] a = {b,c,d, a, e}; bubble_sort(a); char value = c; for(char c:a)

Add a comment
Know the answer?
Add Answer to:
Qi. Create a java project Question that includes: • A bubble sort method to sort your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java application that implements the recursive Binary Search alogrithm below: Write a Java application...

    Write a Java application that implements the recursive Binary Search alogrithm below: Write a Java application that implements the recursive Binary Search alogrithm below:/** * Performs the standard binary search using two comparisons * per level. This is a driver that calls the recursive method * @return index where item is found or NOT FOUND if not found */public static <AnyType extends Comparable<? super AnyType>> int binarySearch(AnyType [] a, AnyType x) {return binarySearch(a, x, 0, a.length -1);}/** * Hidden recursive...

  • JAVA Algorithms course need help completing this method using binary search thank you in advance. -------------------------------------------------------------------------------------------------...

    JAVA Algorithms course need help completing this method using binary search thank you in advance. ------------------------------------------------------------------------------------------------- /** A class for executing binary searches in an array. */ public class BinarySearcher { /** Finds a value in a range of a sorted array, using the binary search algorithm. @param a the array in which to search @param low the low index of the range @param high the high index of the range @param value the value to find @return the index...

  • Java The following questions ask about tracing a binary search. To trace the binary search, list...

    Java The following questions ask about tracing a binary search. To trace the binary search, list the value of first, last, and mid for each pass through the loop or method. Use one of these methods for your trace. public static int binarySearchIterative(int[] numbers, int target) { boolean found = false; int first = 0; int last = numbers.length - 1; while (first <= last && !found) { int mid = (first + last) / 2; if (numbers[mid] == target)...

  • use the same code. but the code needs some modifications. so use this same code and...

    use the same code. but the code needs some modifications. so use this same code and modify it and provide a output Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...

  • Create an Eclipse Java project that utilize "Bubble Sort" to sort an unsorted integer array of...

    Create an Eclipse Java project that utilize "Bubble Sort" to sort an unsorted integer array of size 10. The main method should display unsorted array and sorted array after Bubble Sort. NEED A WORKING JAVA PROJECT. NEED IT ASAP

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

  • Given the binary search function, answer following question: int binarySearch(int a[], int size, int target, int...

    Given the binary search function, answer following question: int binarySearch(int a[], int size, int target, int low, int high) { while (low <= high) { int mid = (low + high) / 2; if (a[mid] == target) return mid; else if (a[mid] < target) low = mid + 1; else high = mid 1: } return -1; } 1) If array a[] = {4, 5, 18, 25, 66, 70, 78}, size = 7, target = 71, low = 0, high...

  • Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch...

    Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...

  • USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list...

    USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list and use a Merge Sort to sort the object by age. Create a class called Person : name and age Create methods that add, and delete Person from the link list Create a method that sorts the persons' objects by age. package mergesort; public class MergeSortExample { private static Comparable[] aux; // auxiliary array for merges public static void sort(Comparable[] a) { aux =...

  • I'm trying to make a recursive binary search that checks whether or not the words in...

    I'm trying to make a recursive binary search that checks whether or not the words in a file are correct by comparing it to a dictionary file, but for some reason the method I'm using below is not working and is outputting all the words in the file I am checking as incorrect. (the dictionary is organized in alphabetical order however the file "oliver.txt" is not) my question is what do I have to do to make this work? public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT