Question 1: The following algorithm takes an unsorted array of integer numbers as input and sorts it in descending order, by repeatedly doing the following: first, it searches in the whole array for the greatest element. it then puts this element to the beginning of the array. • then, it searches the whole array excluding the first element for the greatest value and puts it to the second position. Implement the algorithm according to two different strategies: A By using the method shiftRight(int] A, int i, int ): if the maximum element is found in position j and needs to be put into position i, then (1) shift A to the right, starting from position i, while remembering the element in position į that will be overridden; (i) copy the remembered element to position i B. By using the method swap(int] A, int i, int j): if the maximum element is found in position i and needs to be put into position j, then use swap to exchange the element in position i with the element in position j.
Q: Recall the Find problem from Assignment # 1. You were asked to implement the following static…
A: Here is the solution of the above problem:
Q: write a Java method merge that takes as parameter a non-empty double array representing employees’…
A: here i written java code for given problem MergeSalary. public class MergeSalary { }
Q: Implement one of the following sorts of your choosing to reorder values from least-to-greatest (i.e.…
A: The answer is given in below step
Q: 4. Consider the array intArr below, which has been filled with rando numbers. Fill in the code to…
A: There are two ways you can sort an array in ascending order: 1. Using for loop to sort the array,…
Q: Given an array of ints, return the number of times that two 6's are next to each other in the array.…
A: Given: Given an array of integers. int n[] = {2, 6, 71, 6, 6, 6, 34, 6, 6, 89}; Requirement: Write a…
Q: OR JAVA // Question is the first one, try to solve it by using the second question. Repeat the…
A: Required: FOR JAVA // Question is the first one, try to solve it by using the second question.…
Q: A prime integer is any integer that is evenly divisible only byitself and 1. The Sieve of…
A: Program: #include <iostream> #include<iomanip> using namespace std; int main() {…
Q: Write a code in C++ / cpp to solve the following problem Sasha has an array that contains each…
A: Increasing order 3 time pic the value in the array and for that code is below step.
Q: Implement one of the following sorts of your choosing to reorder values from least-to-greatest (i.e.…
A: The following shows the implementation of bubbleSort, selectionSort and insertionSort using Java…
Q: Write a program to shift all the zero present in the array in the alternative order, For example
A: Note: Programming Language not specified using c++ //include the necessary headers#include…
Q: Write class name Student Management having array of students and count of students as attribute.…
A: import java.io.*;class Student{int rollno;String name;int number_of_subjects;int mark[]; Student(int…
Q: Above method deletes range of elements from an array. Consider array A[] globally declared and…
A: Here, the function is accepting two int parameters, from and to The main use of this algorithm is…
Q: Have an array with integers in it. This array contains all non-overlapping elements. Split it into…
A: Start. Find the split point. Traverse array element and compute the sum of the whole array Again…
Q: Write a java program to perform Sequential Search. 1. Create an array of String.] 2. Your answer…
A: In Sequential Search, we go on comparing each and every element in array till match is found String…
Q: Heapsort has heapified an array to: 95 78 92 15 37 35 91 and is about to start the second for loop.…
A: The solution for the above-given question is given below:
Q: Consider following method: bool replaceOne(int n1, int n2) { int i = 0; while(NumAry[i] != n1){ i =…
A: I have added the functionality in this code to search all the elements of match and then ask the…
Q: Simulate binary search Use array {1, 2, 3, 4, 5, 6, 7} to simulate binary search of 3. For each…
A: Index 0 1 2 3 4 5 6 Value 1 2 3 4 5 6 7
Q: Write java methods to do these tasks: a. Move even elements to the front, if not then preserving…
A: The code is as follows:-
Q: Problem #2: We need to develop a game that allows two players to throw a dice ten times and the…
A: An array is a data structure that contains the elements of the same type. It helps to store…
Q: Consider the following code segment that includes a method called multiply. The multiply method is a…
A: Given: To find value of a5[1][1].
Q: B) Write an algorithm that takes the input 2 multi-dimensional array and produce and calculate the…
A: Given: Creation of two 2D array. SUM of Consecutive Adjacent rows
Q: 9. Implement an array with values 1, 5, 14, 23, 45, 52, 58, 81, 82 91. a) Create a getindex(…
A: Solving the given problem by using C++, as no programming language is specified. The below given…
Q: Write a Java program to implement the following by using class Arrays: Read 5 student marks and…
A: Given: Write a Java program to implement the following by using class Arrays: Read 5 student marks…
Q: int primes={21,23,25,37,11,13,17.19,23,29,31,37,41,43,47,53,59,61,67,73,79,83,89,97} consider the…
A: Program Approach: Include the necessary header files for the standard I/O. Declare a function…
Q: In this lab, you will implement the bubble sort algorithm. The bubble sort is so called because it…
A: Code:- public class BubbleSorter{ static void bubbleSort(int[] arr) { int n =…
Q: Write a program that takes numbers from the user and places them into an array. After each new…
A: Dear Student, Please mention programming language in the question , as no language is mentioned I am…
Q: Consider the following equation for the sum of a finite arithmetic series: Sm where n is the number…
A: Solved using JAVA
Q: Write a program to ask the user for the number of arrays he wants to maintain and then populate each…
A: Actually, array is a collection of elements.
Q: What will be the problem with the following algorithm for finding an item in an unsorted array? How…
A: We need to find the problems in the given algorithm to find the item in an unsorted array. The given…
Q: Write a Java class to perform the following: 1. Write a method to search the following array using…
A: Method to search an element using linear search: return type- int (if element is found, its index is…
Q: This method takes two numbers as input first one is to find and the other is to replace that number…
A: The given function named replaceOne will be updated in C++ (as programming language is not…
Q: Write method findZero, as started below. findZero should return the index of the first element of…
A: Solution:
Q: Given two arrays that are full of integers, recursively merge these two arrays into one large array.…
A: We need to complete the given function for desired functionality.
Q: Write a program that first reads an integer for the array size, then reads numbers into the array,…
A: In this question we have to write a C program as we have to use the pointer to access the array for…
Q: Consider the following equation for the sum of a finite arithmetic series: Sm where n is the number…
A: As no programming language is mentioned, it is solved using JAVA
Q: Consider the following code segment that includes a method called multiply. The multiply method is a…
A: Given: To find the value of a6[0][0].
Q: First, write a Java method merge that takes as parameter a non-empty double array representing…
A: Here I have created 3 functions. Function merge(), takes an array as input and returns the merged…
Q: If x is an array of interger, then the value of &x[i] is same as A. &x[i-1] + sizeof (int) B. x…
A: We are given an array x which contain integers and we are asked which option will give the value of…
Q: For this exercise, you need to shift all the elements in the array one space to the right (increase…
A: I have given an answer in step 2.
Q: Implement one of the following sorts of your choosing to reorder values from least-to-greatest (i.e.…
A: Start. Take the array and pass it to the bubble sort function. In this function, the array will be…
Q: swift WAP foran array of integer is given print all entries, then add one more entry in it .now…
A: Question :- WAP for an array of integer is given print all entries, then add one more entry in it…
Q: Complete the method int getMaxRow(int a) to m is the sum of all the elements in a particular row.)…
A: Using the method int getMaxRow
Q: • Method section_6 Given two arrays (a and b) with equal length and that have at least one element,…
A: Program to add the corresponding elements of two arrays of same length.
Q: public static int[] mergeArr ( int nums1[], int m, int nums2[], int n) { int i - 0,j int arr[] 0,k -…
A: Worst Case: The size of array1 is 'm' and the size of array2 is 'n'. We are comparing elements of…
Q: Complete the method int getMaxRow(int[] a) to return the index of the "row" in the two-dimensional…
A: The JAVA code is given below with an output screenshot Happy Coding?
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: First, write a Java method merge that takes as parameter a non-empty double array representing…
A: import java.util.Scanner;//to read inputpublic class Main{ private static Scanner input = new…
Q: Consider following method: bool replaceOne(int n1, int n2) { int i = 0; while(NumAry[i] != n1){ i =…
A: In this program i have completed the replaceOne function and also used main method to demonstrate…
Q: Problem (class MergeSalary) First, write a Java method merge that takes as parameter a non-empty…
A: Answer :
the qusetion on the picture
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- A prime integer is any integer that is evenly divisible only byitself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It operates as follows:a) Create an array with all elements initialized to 1 (true). Array elements with prime subscriptswill remain 1. All other array elements will eventually be set to zero. You’ll ignoreelements 0 and 1 in this exercise.b) Starting with array subscript 2, every time an array element is found whose value is 1,loop through the remainder of the array and set to zero every element whose subscriptis a multiple of the subscript for the element with value 1. For array subscript 2, all elementsbeyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6,8, 10, etc.); for array subscript 3, all elements beyond 3 in the array that are multiplesof 3 will be set to zero (subscripts 6, 9, 12, 15, etc.); and so on.When this process is complete, the array elements that are still set to one indicate that the subscriptis a…A prime number is any integer that is evenly divisible only by itself and 1. The Sieve ofEratosthenes is a method of finding prime numbers. The algorithm is described below.• Create an array with all elements initialized to 1 (true). Array elements with primesubscripts will remain 1. All other array elements will eventually be set to zero.• Starting with array subscript 2, every time an array element i is found whose value is 1,loop through the remainder of the array and set to zero every element whose subscript is amultiple of i. For array subscript 2, all element beyond 2 in the array that are multiples of2 will be set to zero (subscripts 4, 6, 8, 10, etc.); for array subscripts 3, all elements beyond3 in the array that are multiples of 3 will be set to zero (subscripts 6, 9, 12, 15, etc.); and soon.When this process is complete, the array elements that are still set to one indicate that the subscriptis a prime number. These subscripts can then be printed. Write a program that uses…Calculating the Minimum Sum Path in a Triangle (LeetCode Problem)Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move toan adjacent number of the row below. More formally, if you are on index i on the current row, you maymove to either index i or index i + 1 on the next row. public static int minSumPathMemo(int[][] triangle)This method will calculate the minimum sum path in the triangle using the top down strategy. Note thismethod MUST BE recursive and you will need to create a recursive helper method. public static int minSumPathBottomUp(int[][] triangle)This method will calculate the minimum sum path in the triangle using the bottom up strategy. Note thismethod CANNOT be recursive and you should not create any additional helper functions. Extra Challenge: Could you do this using only O(n) extra space where n is the total number of rows in thetriangle? This is method signature class below: package dynamic; public class MinSumPath {…
- The rotateLeft method takes an array of integers, and an integer number of places, and returns a new copy of the array that contains a "rotated" version of the input array. Rotation means that elements have been shifted leftwards by that number of places, moving elements off one end of the array and onto the other end. For example, [11, 12, 13, 14, 15] rotated left by 2 places results in [13, 14, 15, 11, 12].Create an array of size one million (1,000,019). Fill it in reverse sequentially with values (e.g. array[0] should equal 1,000,018, array[1] should equal 1,000,017, etc). Then the computer should select a random target number between 0 and array size – 1. You should then search the array for this value twice – once with a linear search algorithm, and then with a binary search algorithm. Start searching from the end of the array, rather than the beginning. Keep track of how long each one took, using the following criteria: Linear Search: Number of loop iterations before the target number was found Binary Search: Number of midpoints chosen (a.k.a “guesses”) taken before the target number was found Once both algorithms have been run, display the results and print which algorithm found the number first (or if there was a tie). Once both algorithms have been run, display the results and print which algorithm found the number first (or if there was a tie). In the rest of this assignment,…A prime integer is any integer greater than 1 that can be divided evenly only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It works as follows:a) Create an array with all elements initialized to 1 (true). Array elements with prime subscripts will remain 1. All other array elements will eventually be set to zero.b) Starting with array subscript 2 (subscript 1 is not prime), every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. For array subscript 2, all elements beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, and so on.). For array subscript 3, all elements beyond 3 in the array that are multiples of 3 will be set to zero (subscripts 6, 9, 12, 15, and so on)When this process is complete, the array elements that are still set to 1 indicate that the subscript is a…
- Correct answer will be upvoted else Multiple Downvoted. Computer science. you can choose two indices x and y (x≠y) and set ax=⌈axay⌉ (ceiling function). Your goal is to make array a consist of n−1 ones and 1 two in no more than n+5 steps. Note that you don't have to minimize the number of steps. Input The first line contains a single integer t (1≤t≤1000) — the number of test cases. The first and only line of each test case contains the single integer n (3≤n≤2⋅105) — the length of array a. It's guaranteed that the sum of n over test cases doesn't exceed 2⋅105. Output For each test case, print the sequence of operations that will make a as n−1 ones and 1 two in the following format: firstly, print one integer m (m≤n+5) — the number of operations; next print m pairs of integers x and y (1≤x,y≤n; x≠y) (x may be greater or less than y) — the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence…Devise an algorithm that detects whether a given array is sorted into ascending order. Write a Java method thatimplements your algorithm. You can use your method to test whether a sort method has executed correctly. Ensure that your program has a test classImplement the following method to sort the columns in a twodimensional array. A new array is returned and the original array is intact.public static double[ ][ ] sortColumns(double[ ][ ] m) Write a test program that prompts the user to enter a 4 X 4 matrix of doublevalues and displays a new column-sorted matrix. Here is a sample run: Enter a 4−by−4 matrix row by row:0.15 0.875 0.375 0.225 ↵Enter0.55 0.005 0.225 0.015↵Enter0.30 0.12 0.4 0.008 ↵Enter0.07 0.021 0.14 0.2 ↵EnterThe column−sorted array is0.07 0.005 0.14 0.0080.15 0.021 0.225 0.0150.30 0.12 0.375 0.20.55 0.875 0.4 0.225
- Given n distinct integers on an array and a positive integer K. step1. choose any two integers x and y in the array which differ by at most K, i.e. |x − y| ≤ K. step2. remove the smaller of the two chosen integers. one move is consisting of the two steps above. task is to make moves in this way until no longer able to do so. in some cases, may be unable to make even a single move. Design an algorithm which runs in O(n log n) time and finds the longest sequence of moves. Do not write the code, give steps and methods. Explain the steps of algorithm, and the logic behind these steps in plain English In some initial states, has no valid moves. For example, if n = 5, K = 1 and the numbers are 1, 3, 5, 7, 9, then cannot make any moves and the longest sequence of moves is simply the empty sequence. Use the greedy method.Given an integer array of 12 elements. We would like to write an algorithm that fills the array with multiples of 5 starting from zero (0, 5, 10, 15...). Then we wish to displays/prints the array contents; and then print the summation of all elements of this array. In the following, the first few steps (lines) of this algorithm are listed below) but is not complete. You need to complete this algorithm and write down the remaining steps clearly and correctly: Algorithm: fill and output an integer array of length 12 with contents are multiples of 5 starting from 0 as follows: 0,5, 10, 15,.... And then output the total summation of all these elements. Input: no user input needed. Output: the contents of the array and the total sum of all array elements. Procedure:...........write down here in simple English how to do this program... in two to three lines only.. 1) Define an array called ar1 of length 12 elements and of type integer. 2) Set i = 0; // it will be used as array index 3) Set…A basic iterator offers all the following operations except Group of answer choices 1. Except nothing, it can do all of the listed operations. 2. Get the item at the current iteration 3. Return an array of all items 4. Determine if there are more items 5. Go to the next item