Kindly solve the below function in cpp Write a program / Algorithm to find intersection of two sets in O(n). void setA_Intersection_setB (int setA[], int counterA, int setB[], int counterB)
Q: 5x5 matrix with randomly generated integers from -100 to 100, print your matrix in a table form and…
A: Q: Generate random integers and print according to ID.
Q: Write a recursive function named merge_sort that sorts a given list using the recursive algorithm of…
A: Note: - We are allowed to answer one question at a time because you did not specify which question…
Q: Code in Python only You are given a sequence A1, A2,..., AN. Find the number of ways to split it…
A: It is defined as a interpreted, object-oriented, high-level programming language with dynamic…
Q: in c++ Write the code of the insertion-sort algorithm. Illustrate the execution of the algorithm on…
A: We are given an array A = 3, 13, 89, 34, 21, 44, 99, 56, 9 and we have to perform insertion sort on…
Q: Use C++ Programming language Write a function that merges two sorted array-based lists into one…
A: Code:- #include <iostream> //Set up the two arraysvoid mergeArrays(int a[],int b[],int n,int…
Q: provide algorithm, sample code in java, use for following i. Inorder Traversal
A: Question. Provide algorithm, sample code in java, use for following i. Inorder Traversal Answer i.…
Q: List the elements of set A = {x:x є N, 2<x<9} where N= {1, 2, 3, ...}
A: Here the set A will contain all elements which are greater than 2 and less than 9.
Q: Write a recursive version of this code. one in which n is divided by two. public static > void…
A: According to the information given above:- we have to create Merge Sorting with the help of…
Q: how would you write this function in recursion int findLargest() { int largest; if (!empty) {…
A: Please refer below code snippet to find the largest element in a linked list using recursion: I have…
Q: You, Alice and Bob are working on recursive search algorithms and have been studying a variant of…
A: Bob has heard that trinary search is no more efficient than binary search.
Q: 1. Initialize i = strlen(s1) 2. Initialize j = strlen(s2) 3. Initialize count =0; / * This segment…
A: Note: since programming language is not mentioned we are providing solution in c programming. please…
Q: Write a program which uses linear Search to search the elements 45,and 78 and delete it.…
A: We are given some numbers and we have to perform linear search and delete elements 45 and 78. We…
Q: please write the algorithm that solves the Closest-Pair problem using the divide-and-conquer…
A: Closest-pair problem: In closest pair problem we have to find the pair which have the minimum…
Q: Analyse the following three statements and identify the correct statement? i) Binary search can be…
A: ✓Binary Search is divide and conquer approach to search an element from the list of sorted element.…
Q: a) Explain in your own words why the stringSort function will return a string with the characters of…
A: For example String s="hello" Output must be: "ehllo"
Q: For the following sets, determine wheter 3 ia an element of the set. If it is choose true, else…
A: Answer :- False
Q: The aim of the following function is to create a vector containing all the divisors of an integer n.…
A: Here in this question, we need to build a vector with all the divisors of an integer.
Q: Suppose we want to modify the above code to compute the set intersection of the arrays a and b,…
A: Given:
Q: Given A = {a, b, c}, B = {0,1}, and C = {m, n}, write down the elements of B × C × A (note order of…
A: INTRODUCTION: A set is a collection of items in mathematics. The empty set is a set with no…
Q: two_sum is a Python function that takes in a list of integers (elements) and an integer number (num)…
A: Given: two_sum is a Python function that takes in a list of integers (elements) and an integer…
Q: This is Program 1. Program 1 outputs n copies of that list as a single list. Combine Program 1 with…
A: a) def bs(ar): n = len(ar) for i in range(n): s = False for j in range(0,…
Q: a. It was remarked in this chapter that the performance of bubble sort can be improved if we stop…
A: Programming language is missing in the question. So we will answer this program in C++ language. If…
Q: The cat function can be a useful :tool for building Arrays O Vectors O none of the above O
A: MATLAB as the name suggests, it is a language which is developed by the Math works, and can coined…
Q: Q} Code the given problem using python programming language Sereja has an array consisting of n…
A: python code is given below,
Q: In C++ Language: Write a function SummOdd that will find the sum of all elements of add order a1+…
A: As it is not clear in the question that sum of odd order for the arr[]={ 8,6,4,2,3,5} is 8 (3+5=8…
Q: Problem 6 - Use Bubble Sort...Go through the first pass only String x [ ] = {"cat", “cAt", “Cat",…
A: Swapping of the elements is done considering ascending sort. ASCII values are used for the…
Q: Use Figure 10.8 as an example to show how to apply the binary search approach to a search for key 10…
A: The binary search algorithm is mentioned below. STEP 1: In the first step, sort the list in…
Q: A c++ question: search.h: Compromise Search is a compromise between Binary Search and Linear Search:…
A: #include "binary_search_function.h" double binary_search_function( const…
Q: Python problem: Replace of the ten Xs in the simple sum shown below with a digit drawn…
A: Program: #call the method setOfSolution = set() #definition of "result" method def result(x1, x2,…
Q: 4. How many distinct subsets are of 3 elements in a set S = {1, 2, 3, 4, 5, .. , 99}? For these…
A: Total number of distinct subsets of size 3 from {1, ... , 99} is 99C3
Q: Consider the following problems for recursive definition/solution. Answer the following questions.…
A: The answer is attached below:-
Q: Code in Python: Question 2: Write a Python program in which you will invert the logic of…
A: Python program in which you will invert the logic of Selection-Sort (means select Max-value in…
Q: Task 2: Write a program to implement Binary search. Count numbers of comparison you have made to…
A: implement binary search . use one global variable count=0 with each return statement do count++…
Q: See the pseudo-code of the Binary Search using recursion below. Fill in the XXXX and YYYY in the…
A: An array refers to a simple data storage structure that is capable of holding some given elements of…
Q: You are given an array A[1..n], which stores the output of the pre-order traversal of a binary…
A: The current scenario here is to construct the binary tree with the pre-order traversal using…
Q: Python Programming Lab: You are given N sets of integers A1,A2,…,AN. For each valid i, let's denote…
A: Itertools module in Python can be used to find all combinations of a number of lists. Set() converts…
Q: • Let A, B are two set , then A – B= 1. AnB 2. ВПА 3. ВПА 4. ĀNB 4 O 3 2 0
A: Let A, B are two set, then A - B= 1. A∩B' 2. B∩A 3. B∩A 4. A'∩B ANSWER: The CORRECT OPTION will be…
Q: lgorithm to the given array " arr" following alphabetical order (a < b <c ... < z). Assume first…
A:
Q: T/F: Binary Search can correctly determine whether an element is in an array if it is unsorted.
A: Answer is given below .
Q: What does the ff. algorithm return? (Note: indentation is important) algorithm foo(f : function, a1,…
A: In the given algorithm we have the array hit keep track of which elements of the codomain B have…
Q: program / Algorithm to find intersection of two sets
A: Program: // C++ version 14#include<iostream>using namespace std;// function declarationvoid…
Q: Consider the following multiplication problem: Given an integer list (an array) of size n, we want…
A: a) An instance of a problem can be defined as a particular case of a generalized problem with a very…
Q: If set A has 4 elements and B has 3 elements then set n(A X B) is 14 12 24 7
A: If set A has 4 elements and B has 3 elements then set n(A X B) is 14 12 24 7
Q: Consider the following C++ code fragment for Selection Sort (the numbers on the left-hand are line…
A: Answer: We have discussed about selection sort in brief explanation
Q: 1- Consider the following function : f (n) = 10n + 2n -20 For which positive integer m can you say…
A: Solution:- As, f (n) = 10*n6 + 2*n4 - 20 Thus, for m=6, we can say f (n) is O(nm). Also m = 6 for…
Q: consisting of n integers a1 < a2 <... < an
A: python code is given below,
Q: Code in Python Q) Write a function to sort given array using Bubble sort algorithm and returns the…
A: Given: Code in Python Q) Write a function to sort given array using Bubble sort algorithm and…
Q: Write aJava function given an array of integers nums [passed by reference] and an integer target,…
A: - Working on the code. - We have to use java here.
Kindly solve the below function in cpp
Write a
void setA_Intersection_setB (int setA[], int counterA, int setB[], int counterB)
Step by step
Solved in 2 steps
- In main() for now: do these - one at a time, each in it's own loop (we will make functions out of them later –Declare an array RandArray with 20 integers –Assign each of the 20 values with a random value from 0 to 99 Hint: Use rand()%100 For mimir: Do not call srand at the top of main. // normally: Call srand(time(0)) at the top of main –(you need #include<cstdlib>) –Write another loop that prints the array, with index values Important: If the output values do not match mimir, please add srand(17); // inside your main function - at the top code format: #include <iostream>using namespace std; #include <cstdlib> // required for rand() int main(){ srand(17); // define a constant ARRAYSIZE that is 20 // declare randArray // set the 20 elements in randArray to be a random number between 0 and 99 // hint: use rand()%100 // print the 20 values return 0;}1. Rewrite the Bubble sort to use recursion. 2. Use the time(0) function to determine how many seconds it takes to sort a vector using the recursive method. 3. Use the time(0) function to determine how many seconds it takes to sort a vector using the non-recursive method described in the videos. Run the sort test on vectors containing random integers. You should sort vectors of the following sizes: 100 elements, 1000 elements, 5,000 elements, 10,000 elements and 50,000 elements. Was the recursive method able to work on vectors of each of those sizes? If not, explain why it errored. 4. Create a class that will store a vector of planets (See the Planet assignment). Your class will have functions to add a planet, delete a planet and sort the planets. The class must utilize the insertion sort.1. Rewrite the Bubble sort to use recursion. 2. Use the time(0) function to determine how many seconds it takes to sort a vector using the recursive method. 3. Use the time(0) function to determine how many seconds it takes to sort a vector using the non-recursive method described in the videos. Run the sort test on vectors containing random integers. You should sort vectors of the following sizes: 100 elements, 1000 elements, 5,000 elements, 10,000 elements and 50,000 elements. Was the recursive method able to work on vectors of each of those sizes? If not, explain why it errored.
- Two arrays list1 and list2 are strictly identical if they have the same length and list1[i] is equal to list2[i] for each i. Write a function that returns true if list1 and list2 are strictly identical using the following header: bool strictlyEqual(const int list1[], const int list2[], int size) Write a test program that prompts the user to enter two lists of integers and dis- plays whether the two are strictly identical. The sample runs follow. Note that the first number in the input indicates the number of the elements in the list. This number is not part of the list. Assume the list size is maximum 20./** numUnique returns the number of unique values in an array of doubles. * The array may be empty and it may contain duplicate values. * Unlike the previous questions, you can assume the array is sorted. * * Your solution should contain at most one loop. You may not use recursion. * Your solution must not call any other functions. * Here are some examples (using "==" informally): * * * * * Ⓒ == numUnique (new double[] { }) 1 == numUnique (new double[] {11}) 1 == numUnique (new double[] { 11, 11, 11, 11 }) 8 == numUnique (new double[] { 11, 11, 11, 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88, 88 }) 8 == numUnique (new double[] { 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88 }) * */ public static int numUnique (double[] list) { return StdRandom.uniform (100); //TODO: fix thisComplete the following function definition to recursively print the index of a unique value in an array or -1 if the value is not found:1 int getIndex(int *a, int s, int v) {2 if( ) { // if no values are found3 4 }5 if(a[s-1] == v) { // if a value is found6 7 }8 return getIndex( ); // recurse to check next value9 }Hint:Recurse through the array by counting down from size. 1. Complete the one line of code for line 2:2. Write one line of code for line 3:3. Write one line of code for line 6:4. Complete the one line of code for line 8: please send an atom code. not other software
- 3. Largest: a recursive function that computes the largest value for an integer array of positiveand negative values. For example, for the array below, the function largest should return 22,which is the largest value in the array. You can assume there are no more 20 integers in thearray. Think of how to formulate the recurrence relation in this problem yourself.JAVA Problem Create a function that determines whether elements in an array can be re-arranged to form a consecutive list of numbers where each number appears exactly once. Examples cons([5, 1, 4, 3, 2]) → true // Can be re-arranged to form [1, 2, 3, 4, 5] cons([5, 1, 4, 3, 2, 8]) → false cons([5, 6, 7, 8, 9, 9]) → false //9 appears twiceLanguage: JAVA Script Write a recursive function called 'shortestToLongest' which takes an array of lowercase strings and returns them sorted from shortest to longest. Strings of equal length should be sorted alphabetically. (Hint: stri <str2 will return true if str1 comes before str2 alphabetically) Your function should accept a default argument called 'sorted' which holds the currently sorted elements. Each recursive step should add the shortest string in the strings array to the end of 'sorted'. // Examples: // Sorts strings from shortest to longestlet strings1 = ["abc", "de", " ", "f", "ghijk", "Imno"] shortestToLongest (strings1);// [' ', 'f', 'de', 'abc', 'lmno', 'ghijk'] // Accepts a pre-sorted default parameter let strings2 = ["pomegranate", "persimmon", "peach"]; let sorted ["pea", "pear"];shortestToLongest (strings2, sorted); // ['pea", "pear', 'peach', 'persimmon', 'pomegranate'] // Sorts strings of the same length alphabetically let strings3 = ["dog", "cat",…
- Problem2: A square matrix can be represented by a two-dimensionalarray with N rows and N columns. You may assume a maximum size of 50 rows and 50 columns. 1. Write an algorithm MakeEmpty(n), which sets the first n rows and n columns to zero. 2. Write an algorithm Add(M1, M2, M3), which adds two matrices M1 and M2 together to produce matrix M3. 3. Write an algorithm Subtract(M1, M2, M3), which subtracts matrix M2 from matrix M1 to produce matrix M3. 4. Write an algorithm Copy(M1, M2), which copies matrix M1 into matrix M2.There is a recursive function called `longestToShortest` which takes an array of lowercase ot strings and returns them sorted from longest to shortest. Strings of equal length should be sorted alphabetically. Your function should accept a default argument called `sorted` which holds the currently sorted elements. Each recursive step should add the shortest string in the `strings` array to the end of `sorted`. // Examples: // Sorts strings from shortest to longest let strings1 = ["abc", "de", "", "f", "ghijk", "lmno"] shortestToLongest(strings1); // ['', 'f', 'de', 'abc', 'lmno', 'ghijk'] function longestToShortest(strings, sorted = []) { } Please explain all steps Line by line, Show all work inside the function to pass the example console.log test cases. Please do it in the recursive function only. Thank you!Do this using C++. Initialize an integer array with random number between 0 to 51 using rand() function. And search one random generated key element from this array. If match not found, an error must be print on screen "key not found" or "element not found in the list". Searching technique "linear search"