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 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...

  • 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....

  • 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...

  • 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...

  • 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 =...

  • Write a java program: Create a method fillRandom() that accepts an array of int as input...

    Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...

  • Convert the following pseudocode to Java. Use the same variable names as those in the pseudocode....

    Convert the following pseudocode to Java. Use the same variable names as those in the pseudocode. You may assume that the incoming array contains int values and that a swap method exists elsewhere. The variables low and high represent indices in the array. In a comment before the sort method, list which sorting algorithm is used here and what its runtime complexity is in Big-O notation. This is the only comment required for this code. SUBROUTINE sort(ARRAY a[0..n], low, high)...

  • The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered...

    The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered list. The algorithm (in pseudocode) is as follows: highIndex - the maximum index of the part of the list being searched lowIndex - the minimum index of the part of the list being searched target -- the item being searched for //look in the middle middleIndex = (highIndex + lowIndex) / 2 if the list element at the middleIndex is the target return the...

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
ADVERTISEMENT