Public class BUbbleSort { void bubbleSort (int arr []) { int n = arr.length; int i,j; for ( i = 0; i < n-1; i++) for (j = 0; j < n-i-1; j++) %3D if (arr [j] > arr [j+1]) { int temp = arr [j]; arr [j] =arr[j+1]; arr [j+1] = temp; %3D System.out.print.ln( "NUmber of passes using unoptimized=" + (i+j));| }
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: Since the programming language is not mentioned, I have done the code using JavaScript.
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: Algorithm - Take input from user. Now use the below logic - nums.map(function(el){…
Q: Write a program that creates an array of size 6 and input values to it through user input. It turns…
A: Explanation: So we have an array in which values are biased Let understand it by example Let take an…
Q: Write a function called modifyDistinct that takes an array of positive integers in random order and…
A: "Since you have not mention any programming language, so we will write our program in C language." C…
Q: Write a function that will combine two arrays of different lengths into another array. Express the…
A: In this program, we have to write a program for merging two array into a one array. so, for this…
Q: Write in Java. Given an array of integers A, find the Majority Element. Majority Element in an…
A: Code: import java.util.Scanner;class DriverMain {public static void main(String args[]) {//main…
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: Algorithm - Design a method with one argument as a string. Now use the below logic to solve the…
Q: Write down a function 'foo' that returns the number of times that in an array, the sum of three…
A: C programming refers to the object oriented programming languages that are used to create…
Q: You are given two int variables j and k, an int array zipcodeList that has been declared and…
A: Question :-
Q: Write a function numberOfOccurences() which takes an integer reference array of size 10 and a search…
A: Code #include<bits/stdc++.h>using namespace std;int countOccurrences(int arr[],int x){ int…
Q: inputAndPrintReverse: Inputs integers from the user until the user enters 0, then prints the…
A: Answer: Algorithms: 1.We have create a inputAndPrintReverse to pass the input as arguments 2.if…
Q: Given the following class definition: class ptrMemberVarType public: void print () const; void…
A: The program is implemented in C++ with object oriented approach. All the functions have already been…
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: Coded using JavaScript.
Q: This was the problem. You are given an array (which will have a length of at least 3 but could be…
A: public class LongestLine{ staticintfind(int[] integers){ intnumerOfOdds = 0; intnumberOfEvens = 0;…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: Algorithm - Take input from user. Now use the below logic - nums.map(function(el){…
Q: develop a class productsales with static array 'sales' of size 12 where 0th index stores january.1st…
A: Code: import java.util.*;public class ProductSales{ //declaring static array of size 12 static…
Q: Solution In JAVA Create a function that takes two numbers as arguments (num, length) and returns an…
A: According to the Question below the Solution: Output:
Q: Q- write a program to give initial values of integer using random() in the range of [0,100]for the…
A: Java Program for above : import java.util.Random; class Prog{ public static void main…
Q: Write a program to overload the function call operator ( ) so as to allow the more common form of…
A: Actually, program is executable software that runs on a computer.
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: Algorithm - Design a method with one argument as a string. Now use the below logic to solve the…
Q: Test your Baby class by writing a client program which uses an array to store information about 4…
A: Programming instructions: Define class. Declare the required variables. Create a default and…
Q: 2. Implement a function called findMinGap that will return the smallest gap betweenadjacent entries…
A: The C++ program and approach are given below:Approach:Declaring the essential headers and the…
Q: Write in Java. Given an array of integers A, find the Majority Element. Majority Element in an…
A: import java.util.*;import java.lang.*;import java.io.*; class Codechef{ public static int…
Q: Write a recursive function maxArrayList (ArrayList Write a recursive function searchArrayList…
A: Here is the java program of above problem. See below step for code.
Q: Write a function called agesToMinutes that, * accepts an array of object as parameter and * return…
A: function agesToMinutes(arr) { return arr.map(function(ele) { return { name:…
Q: Write a function is ordered that takes an integer array and its size as parameters and returns true…
A: Please refer below for your reference: Language used is JavaScript: function is_ordered(arr,n){…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: function palindromeSieve(nums) { return nums.filter(x => { var nArry = [...(x+'')]; const a =…
Q: Write a function numberOfOccurences() which takes an integer reference array of size 10 and a search…
A: Program approach:- Using the necessary header file. Using the standard namespace I/O. A print array…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: In this problem, we need to design the code in the JS programming language. Input - Array Output…
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: Step-1: Start Step-2: function isSpecialArray(array) Step-2.1: Declare a variable isSpecial and…
Q: Declare a 1D array of n elements. Then input values in array in such a way that user only allowed to…
A: The program is implemented in C++ with structured approach. The main functions only takes the value…
Q: Now, write another function that prints the values of any array in reverse order. (The function…
A: In this question, we have to write a function which will print the value of given array in reverse…
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: In this problem, we need to design the javascript programming language. Input - one array Output…
Q: Write a Program for insertion and deletion from an array without replacement of element from the…
A: Program Approach: Complete the function of insertion by inserting the element at the given…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: In this problem, we need to design the code in the JS programming language. Input - Array Output…
Q: Given your array declared above, and assuming your program has already read in a certain number of…
A: Below is the required program in C++ language. NOTE: As the array declaration is not given by you.…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: Algorithm - Take input from user. Now use the below logic - nums.map(function(el){…
Q: Write a function that takes in an array of integers and returns the integers that are either…
A: The above question is solved in step 2 :-
Q: Test your Baby class by writing a client program which uses an array to store information about 4…
A: Basically, a class named Baby is implemented which has name and age as its member, along with few…
Q: Write a function template that gets an array of generic type T as well as the number of items within…
A: please see the next step for solution.
Q: Write a program that uses two classes. The first class is called “dAta” and holds x and y…
A:
Q: In the following code both myList and yourList are dynamic arrays of the same size. The code…
A: PROGRAM: //Header file #include <iostream> //Using namespace using namespace std; //Defining…
Q: An array is special if every even index contains an even number and every odd index contains an odd…
A: In this problem, we need to design the javascript programming language. Input - one array Output…
Q: You should decide the appropriate declaration and implementation. Write a test class create array of…
A: To Do: Write a Java program that solves each part.
Q: Consider the following function. void printArray(int cards[], int size) { for (int i=0; i<size;…
A: const keyword: The const is the keyword to set a variable value as a constant that will not allow…
Q: Write a static function called "normalize" that takes a two-dimensional (2D) array of integer…
A: public class Main{ public static double[][] normalize(int arr[][]) { int r =…
Q: Write a function that takes an array of ints, and the size of the array – another int. It also…
A: Here, we are going to find the average of an integer array. As programming language is not mentioned…
Q: Given an array arr of type int, along with two int variables i and j, write some code that swaps the…
A: You have not specified any particular programming language to write a program for the given…
This is the unoptimized version of class BubbleSort.
This function also prints the number of passes (number of times the outer loop runs) made through the input array.
One way to optimize bubblesort is to stop when the inner loop does not swap any elements.
And another function to this class called bubblesortoptimized which stops when the inner loop does not swap any elements.
This function should also print the number of passes (number of times the outer loop runs) made through the input array.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- Beginner Java import java.util.Arrays;import java.util.Scanner; Arrays and scanner required. Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 65 pizza 100 45.75 70 5.8 5 Also suppose that you have two integers n and m that are both positive. For example: n = 5 and m = 10 Write a static method: public static double partialSum(Scanner s, int n, int m) that takes a Scanner and two integers n and m as arguments and returns the sum of the integers read by the Scanner that are divisible by n and not divisible by m. In the above example, the integers divisible by 5 and not divisible by 10 are 65 and 5, so the result would be 70. If the Scanner is empty, or no tokens are valid integers, the result should be 0. You can assume the Scanner is not null. It is probably easiest to test your method by creating a Scanner with a String instead of System.in. The starter code for an example of how to do this is…Complete the private combinations method. Modify the code so that it is possible to compute combinations(“ABCD”,2) with fewer than 20 calls and combinations(“ABCDE”,3) with fewer than 30 calls. import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; /** * Recursive computation of all combinations of k characters from a string s. * */public class Combinations { private static int recusiveCalls = 0; /** * Generate all combinations of the characters in the string s with length * k. * * @param s * a string. * @param k * the length of the combinations * @return a list of all of the combinations of the strings in s. */ public static ArrayList<String> combinations(String s, int k) { return combinations("", s, k); } /** * Recursive Problem Transformation: * * Generate all combinations of length k of the characters in rest prefixed * with the characters in…Create a Java class RecursiveMethods.java and create the following methods inside: ALL THE METHODS NEED TO BE COMPLETED RECURSIVLY. NO LOOPS ALLOWED. - oddEvenMatchRec: the method takes an integer array as a parameter and returns a boolean. The method returns true if every odd index contains an odd integer AND every even index contains an even integer(0 is even). Otherwise it returns false. - sumNRec: The method takes an integer array A and returns the sum of all integers in the parameter array. - nDownToOne: Takes an integer n and prints out the numbers from n down to 1, each number on its own line. - inputAndPrintReverse: Inputs integers from the user until the user enters 0, then prints the integers in reverse order. For this method, you may NOT use an array or any type of array structure, in other words, you may not use any structure to store the user input.
- public class Soru2 { static void sort(char a[]) { for(int i = 0; i < a.length; i++) { for(int j = i + 1; j < a.length; j++) { if(a[j] == 'X' && a[i] == 'O') { char temp = a[j]; a[j]=a[i]; a[i]=temp; } } } for(int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } public static void main(String[] args) { char a[] = {'X','O','X','O','X','O','X','O','X','O'}; sort(a); } } Calculate the time complexity and number of steps of the algorithm?public class ReplaceEvenWithZero { public static void main(String[] args) { int[]a = new int[]{14, 2, 19, 3, 15, 22, 18, 7, 44, 39, 51, 78} ; // Print array a for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); // Replace the even elements. replaceEven(a); // Print array a again to see new elements. for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } /** Replace the even elements in the given array with 0 @param arr the array to use for the replacements */ public static void replaceEven(int[] arr) { //-----------Start below here. To do: approximate lines of code = 2 // Write a for loop to go through each element, determine if it is even //If so, replace with 0. Hint: use the modulus operator % to determine if an…import java.util.*;class Arraylist{public static void main(String args[]){ArrayList obj = new ArrayList();obj.add("A");obj.add("B");obj.add("C");obj.add(1, "D");System.out.println(obj);}} What will the given code prints on the output screen.
- For any element in keysList with a value greater than 40, print the corresponding value in itemsList, followed by a semicolon (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20;30; import java.util.Scanner; public class Compare { public static void main(String args[]) {final int SIZE_LIST = 4;int[] keysList = new int[SIZE_LIST];int[] itemsList = new int[SIZE_LIST];int i;Scanner input = new Scanner(System.in); keysList[0] = input.nextInt();keysList[1] = input.nextInt();keysList[2] = input.nextInt();keysList[3] = input.nextInt(); itemsList[0] = input.nextInt();itemsList[1] = input.nextInt();itemsList[2] = input.nextInt();itemsList[3] = input.nextInt(); /* Your code goes here */ System.out.println();} }Write a client program that loops around getting two fractions from the user,output their sum, and state whether or not they are equal. Keep looping until the first fraction entered is a zero fraction. import java.util.ArrayList;import java.util.Scanner; //Define the class Fractionclass Fraction{private int n, d;public Fraction(){//Initialize the valuesthis.n = this.d = 0;}public Fraction(int n, int d){//Initialize the variablesthis.n = n;this.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}//Define the getter function getDen() that returns the denominatorpublic int getDen(){//Returns denominatorreturn d;}//Define the boolean function isZero() that returns 0 if numerator is 0 and denominator is not equals to zeropublic boolean isZero(){return(getNum() == 0 && getDen() != 0);}public boolean isequals(Object c){Fraction f = (Fraction) c;return(Integer.compare(n,f.n))==0 &&…public class ArrayMerge { static void arrayMerge(int a[], int b[]){ int c[] = new int[50]; int k = 0; for(int i = 0; i < a.length; i++) { c[k++] = a[i]; } for(int i = 0; i < b.length; i++) { c[k++] = b[i]; } for(int i = 0; i < k; i++) { System.out.println(c[i]); } } public static void main(String[] args) { int a[] = { 18, 36, 41, 78, 56 }; int b[] = { 10, 37, 44 }; arrayMerge(a,b); } } Calculate the algorithm step number and algorithm time complexity of the above program?
- java getDup accepts an array and returns an int. If there is any element is duplicated, the method counts how many of those present in the array. Example : getDup(["1","2","aa"',"1"]) returns:2 ("1" is duplicated and there are two "1"s so return is 2) class Main { public static int getDup(String[] r) { } public static void main(String[] args) { Scanner in = new Scanner(System.in); String [] strs = new String[in.nextInt()]; for(int i=0; i < strs.length; i++) { strs[i] = in.next(); } System.out.println(getDup(strs)); } } hint: you will need a nested array the will run on the array we get from the method argument. inside the nested loop you will need to check if the main array element is equal to the currentimport java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int n = scnr.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scnr.nextInt(); } for (int i = n - 1; i >= 0; i--) { System.out.print(arr[i]); if (i > 0) { System.out.print(","); } } }}JAVA In order to compute a power of two, you can take the next-lower power and double it. For example, if you want to compute 2^11 and you know that 2^10=1024, then 2^11=2×1024=2048. Write a recursive method public static int pow2(int n) where n is the exponent, that is based on this observation. If the exponent is negative, return -1. import java.util.Scanner; public class PowerTwo{ public static int pow2(int n) { /* code goes here */ } public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int exponent = in.nextInt(); System.out.println(pow2(exponent)); } }}