given an array of lets say 30 items, make a function that prints the highest n values, in this case 10. Do this without sorting, and do it with the fastest algorithm. int topn = 10; int array_size = 30; int a[] = {2, 3, 5, 6, 1, 2, 3, 5, 7, 4, 23, 123, 54, 64, 123, 21, 54, 34, 76, 45, 87, 98, 34, 234, 12, 43, 54, 23, 12, 43}; // function top_n(a, array_size , topn);
Q: Let S be an unsorted array of n integers. Write an algorithm to find the pairs (x, y.) where x,, y;…
A: Algorithm: /* First sort the given array elements */ Read the unsorted array of n integers begin…
Q: Let B be an array of size n >= 6 containing integers from 1 to n – 5, inclusive, with exactly five…
A: The, answer has given below:
Q: Output: The inversion count is 5
A: The number of steps it will take to sort an array, or how far away it is from being sorted, is the…
Q: Consider the following algorithm to find all the prime numbers less than a given positive number N…
A: #include <stdio.h>#include <stdlib.h> int main(){ int n; printf("Enter the…
Q: Let F be the set of the first 1000 Fibnacci numbers and let P be the set of the first 1000 primes.…
A: TERMS: Fibonacci numbers: Let the fibonacci series starts with elements 1, 1 and hence the resultant…
Q: Consider an integer array a of length n with indexing starting at 0, where n is a positive integer.…
A: As per the company guidelines answer will be provided to the only one question. Please ask another…
Q: Given an array of size n, find how many times the elements in the array should be shifted left in…
A: <code in java Script> function sortedarray(arr, low, high){ // This condition is needed…
Q: Let B be an array of size n ≥ 6 containing integers from 1 to n−5 inclusive, five of which are…
A: Below is the complete solution and explanation about the given program in detail. Also contains the…
Q: Given an array with n objects colored red, white or blue, sort them so that objects of the same…
A: class Sort { //required function public void sortColors(int[] nums) { int…
Q: Write a program to find the value in an integer array all of length N that occurs at least (N/2 + 1)…
A: #include<stdio.h> #define MAX_SIZE 5000 int main(void) { int N; //Declare an array…
Q: p Consider an 8 x 8 array for a board game: int board[8][8]; Using loops, initialize the board so…
A: int i, j; for(i = 0; i < 8; i++) for(j = 0; j < 8; j++) { if((i+j) % 2 == 0)…
Q: Consider an array of N integers. Describe an algorithm with an 0(N) runtime that processes the array…
A: Please refer below for your reference: Below is a O(n) approach: I have counted the number of null…
Q: Let's call an array Nums[0.. 2n] plateau-valley if Nums[0] < Nums[1] 2 Nums[2] s Nums[3] 2...s…
A: Plateau-valley array is representing an array in the form of a wave. The first element in the array…
Q: Given an array of integers $arr, return the sum of all the integers that have an even index,…
A: Algorithm - Create a method evenLast with one array as argument. Now use the below logic $out =…
Q: What is the time complexity of the given algorithm below? An algorithm, M, for sorting a given…
A: n is the number of elements in the array A We are always comparing marking the first element but the…
Q: Let n be a positive integer and suppose we identify a collection of n people with numbers ranging…
A: The above question is solved in step 2 :-
Q: Given an array of integers of even length, your task is to split it into two arrays of equal length…
A: Program Explanation:- Using the header file. Count the number of occurrences of the elements in ar.…
Q: Implement the following method to sort the columns in a twodimensional array. A new array is…
A: A Java program is as follows, “Sample.java” import java. util. Scanner; public class Sample {…
Q: Given an array of integers, return a new array such that each element at index i of the new array is…
A: Given:
Q: The solution must be submitted in the Coral programming language. A program that reads a list of 10…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: Write a program (in mars ) maxarray that computes the double of maximum of values of any given array…
A: Step 1 Introduction: Start Take the array of elements Find the sum of the all elements Store the…
Q: Let F be the set of the first 1000 Fibnacci numbers and let P be the set of the first 1000 primes.…
A: In this question, our goal is to find the number of elements that are lower than the pivot. First we…
Q: Consider first ten letters of your name and for each letter encode with an integer number. For…
A: Note: Since we only answer up to 3 sub-parts, we’ll answer the first 3. Please resubmit the question…
Q: [For students whose last digit of Registration No is even] Write a C program that receives a…
A: CODE : #include<stdio.h> int main(){ int Size, i, arr[10]; int e_count = 0, o_count = 0;…
Q: Implement a Cfunction that return1 if a two-dimensional array of characters has your first four…
A: As mentioned I will not use string.h library. I am solving the problem in 2 parts First I will…
Q: h that at most k elements of A are less than or equal to x, or nil if no such element exists. A…
A: Code: #include<iostream> using namespace std; int size=15;int…
Q: Consider the following algorithm, which may be called on an array that is not necessarily sorted.…
A: T(n) = 3T(⅔n) + 1; T(0)=0, T(1)=0, T(2) = 1
Q: Consider the following algorithm to find all the prime numbers less than a given positive number N…
A: The required C code: #include<stdio.h># define MAX_SIZE 200 /* assign maximum size 200 */int…
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: Given an array of integers $arr, return the sum of all the integers that have an even index,…
A: Algorithm - Create a method evenLast with one array as argument. Now use the below logic $out =…
Q: You are given an array A[1, ., n] in which the elements A[2] to A[n] are already sorted, i.e., A[2,…
A: Algorithm with proper pseudocode
Q: Given an array of integers, find the first missing positive integer in linear time and constant…
A: According to the question below the Solution: Output:
Q: Write a version of the bubble sort algorithm that sorts a list of integers in descending order.…
A: In order to change this bubble sort to descending order we need to change just one condition if…
Q: Rewrite the linearSearch algorithm given below to output all positions of the element x in the array…
A: Here is the modified linearSearch algorithm to output all the positions of element X in array L.…
Q: in java , Consider the array of integers A={ 49, 26, 93, 17, 77, 31, 44, 55, 23}. Now, Perform the…
A: 1)Using Insertion Sort
Q: Write a program to set zero in the lower triangular of a given matrix a(4,4). For example array…
A: Coding problems.
Q: Implement MaxHeap sort algorithms on your computer. Run timings for each algorithm on arrays of size…
A: public class deletionHeap { static void heapify(int arr[], int n, int i) { int…
Q: Given an array of even size N, task is to find minimum value that can be added to an element so that…
A: CODE:
Q: Array A contains positive numbers that can be smaller than 1, larger than 1, or equal to 1. Find the…
A: #include <bits/stdc++.h>using namespace std; int maxSubarrayProduct(int arr[], int n){ int…
Q: Write a program that has a function that returns the index of the smallest element in an array of…
A: In this question, we are asked to write a C++ program which return the minimum element in the array…
Q: Let B be an array that is of size n >= 6 containing integers from 1 to n-5, inclusive, with exactly…
A: The algorithm to find repeated values for the above problem can be done in order of n time. The…
Q: Write a program that randomly fills in 0s and 1sinto an n-by-n matrix, prints the matrix, and finds…
A: Program: //import statement import java.util.ArrayList; import java.util.Scanner; //class…
Q: Write a program that finds the average of all positive, non-zero values found in a given array of…
A: Lets see the solution.
Q: Given an integer n and an array a of length n, your task is to apply the following mutation to a:…
A: We need to write a program to mutate an array as per the given condition. * Language used is C
Q: Write a program that sorts an array of random or sorted numbers using Radix sort algorithms, fill…
A: #include <stdio.h> int findMax(int a[], int n) { int maxx = a[0],i; for(i = 1;…
Q: Write an algorithm that takes the input 2 multi-dımensional array and produce and calculate the sum…
A: Algorithm : step by step procedure to solve a problem
given an array of lets say 30 items, make a function that prints the highest n values, in this case 10. Do this without sorting, and do it with the fastest
int topn = 10;
int array_size = 30;
int a[] = {2, 3, 5, 6, 1, 2, 3, 5, 7, 4, 23, 123, 54, 64, 123, 21, 54, 34, 76, 45, 87, 98, 34, 234, 12, 43, 54, 23, 12, 43};
// function top_n(a, array_size , topn);
Step by step
Solved in 3 steps with 1 images
- Write a program that prompts the user to enter an integerm and find the smallest integer n such that m * n is a perfect square. (Hint:Store all smallest factors of m into an array list. n is the product of the factors thatappear an odd number of times in the array list. For example, consider m = 90,store the factors 2, 3, 3, and 5 in an array list. 2 and 5 appear an odd number oftimes in the array list. Thus, n is 10.) Here are some sample run: Enter an integer m: 1500 ↵EnterThe smallest number n for m * n to be a perfect square is 15m * n is 22500Write a program to take input of 100 integers in a dynamically allocated array using malloc() function, then find the average of numbers that are in between 20 and 80. For example if an array contains [10, 40, 15, 20, 30, 90] then the average will be (40+20+30) / 3 = 30.Write a program that randomly fills in 0s and 1sinto an n-by-n matrix, prints the matrix, and finds the rows and columns with themost 1s. Here is a sample run of the program: Enter the array size n: 4 ↵EnterThe random array is0011001111011010The largest row index: 2The largest column index: 2, 3
- Write a function that gets an array of ints of length n, and a number k, and returns the longest subsequence of consecutive k’s in the array. For example - On input ([1, 1, 3, 3, 3, 1, 5, 1], 1), the function returns 3 - On input ([1, 3, 3, 2, 3, 3, 3, 3], 3), the function returns 4 - On input ([3, 5, 2, 5, 2, 5, 5], 3), the function returns 2 - On input ([1, 2, 3, 3, 3, 3], 5), the function returns 0 // returns the length of the longest subsequence // of consecutive k’s in the array int longest_seq(const int* ar, int n, int k); test for the function: void test_q1() { inta1[] = {1, 1, 3, 3, 3, 1, 5, 1}; if (longest_seq(a1, 8, 1) == 2) printf("Q1-1 ok\n"); else printf("Q1-1 ERROR\n"); inta2[] = {1,3,3,2,3,3,3,3}; if (longest_seq(a2, 8, 3) == 4) printf("Q1-2 ok\n"); else printf("Q1-2 ERROR\n"); }a. Write a version of the sequential search algorithm that can be used to search a sorted list. (1, 2) b. Consider the following list: 2, 20, 38, 41, 49, 56, 62, 70, 88, 95, 100, 135, 145 Using a sequential search on ordered lists, that you designed in (a), how many comparisons are required to determine whether the following items are in the list? (Recall that comparisons mean item comparisons, not index comparisons.) (1, 2) 2 57 88 70 135 Write a program to test the function you designed. Note: Have the function,seqOrdSearch, return -1 if the item is not found in the list. (return the index of the item if found).Write a program that fills an integer array of size 1000 with random positive integers between 1 and 10.Assume that each element represents a different city and the integers stored in the array represent thenumber of golds in those cities. The program traverses over the array and collects the golds at each city,starting from a random position. When the program visits a certain city, all of the golds are collected,and the visited element of the array becomes 0 (no gold is left at that city.) The journey continues withthe rule given below. If the position at the nth step is denoted by pn, and the number of golds at the citypn is denoted by gn,??+1 = {| ((??−1 + ?? + ??) ???1000|, ????? 2 = 0| ((??−1 + ?? − ??) ???1000|, ????? 2 = 1.The program continues visiting cities until the last three visited city has no gold.The program, at each visit, should print out the following information:• The current city index (pn).• The previous city index (pn-1).• The number of golds at the current city…
- The Sieve of Eratosthenes is an algorithm that finds all prime numbers up to a given limit, n. It works by creating an array of Booleans, flag, of size n+1, initializing the array to true (assuming every number is a prime number in the beginning), and iteratively traversing the numbers from 2 to n, setting the values of indices that are multiples of other numbers to false. Write a program using the algorithm above, and display all the prime numbers up to 50.Write a program that reads an integer array a[] from the console and writes out the subsequence of the array that sums to the largest value. If there are more than one such subsequence, then the program should write out the subsequence that starts at the smallest position in the array and, if there are more than one subsequence of largest sum starting at the same smallest position, it should write out the shortest such subsequence.in java , Consider the array of integers A={ 49, 26, 93, 17, 77, 31, 44, 55, 23}. Now, Perform the following sorting operations on ‘A’: Using Insertion sort, show how array would look like after each step. Using quick sort, show how array will be partitioned (first partition only) choose 23 the pivot element.
- Write a program to input a list of numbers in an array and then rearrange this array in such a waythat all the odd numbers appear in the beginning of the array and all the even numbers appear in theend of the array. E.g., if the input list is 1,4,2,7,6,5,9, then after rearrangement the list should be:1,7,5,9,4,2,6.Write a program that reads a list of 10 integers, and outputs those integers in reverse. For coding simplicity, follow each output integer by a space, including the last one. Then, output a newline. Ex: If the input is 2 4 6 8 10 12 14 16 18 20, the output is: 20 18 16 14 12 10 8 6 4 2 To achieve the above, first read the integers into an array. Then output the array in reverse. IN CORAL Please!Write a version of the bubble sort algorithm that sorts a list of integers in descending order. Namely, change the bubble sort method to sort the parameter array in descending order. Hint: Bubble sort: void bubbleSort(int array(1) { int size = array.length; boolean isChanged = false; for (int i = 0; i < size - 1; i++) isChanged = false; for (int j = 0; j < size . 1 . 1; j++) if (array(s) > array() + 1]) { int temp = array(s); array[3] . arrays + 1); array() + 1] = temp; is Changed = true; } if (isChanged) break;