for ( i = 0; i < n; i++ ) msis[i] = A[i];
Q: A-1D-9 Given the code segment below, what will be the sum of ALL elements of dCData after running…
A: Please upvote. I am providing you the correct answer below. Please please please.
Q: A 2D array can be flipped horizontally, vertically as shown in the examples below. In this task you…
A: int swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp; } void FlipRow(int *row, int…
Q: 9. Consider the following function: int rec(int array[], int n) { int p; if (n < 0) if (array[n] <…
A: Output: 108050404090170180180 Recursive function call tree:
Q: Answer in C++ only Chef loves lucky numbers. Everyone knows that lucky numbers are positive integers…
A: Find Your Code Below
Q: Write a VB.NET program to input elements in an array from user, find maximum and minimum element in…
A: We need to write a progam in VB.NET programming language to take input elements in an array from…
Q: Write a program that will create a dynamically created 1D array of length n (given by the user) and…
A: Step1 : Start Step 2 : In the main function , Take input from the user for the Length of the array…
Q: in c++ You are given an array A of non-negative integers of size m. Your task is to sort the array…
A: The problem is based on finding the sorted array and printing the array indices corresponding to the…
Q: IN C++ You have given an array aa of length n and an integer x to a brand new robot. What the robot…
A: Don't exactly add 'X' elements, instead keep the count of how many elements we are adding to the…
Q: Use C Language Write a program that reads two matrices of integers. It then generates the sum and…
A: C language program that reads two matrices of integers and It then generates the sum and difference…
Q: (v) Write a JAVA program to the frequency of number n in the array given below. Read the number n as…
A: Please find the answer below :
Q: Question 3: a) Consider a recursive function to return the Number of Binary Digits in the Binary…
A: Abstract: Recursive functions are the functions which repeats itself recursively. We have to find…
Q: C++ Given a positive integer, N, the ’3N+1’ sequence starting from N is defined as follows: If…
A: #include <iostream>using namespace std;int sequence(int N){ int x,count = 1;…
Q: Write a program that reads two matrices of integers. It then generates the sum and difference of the…
A: For calculating the addition or subtraction of two matrices, we need to use two loops. One loop will…
Q: Compute the complexity of the following code snippet:
A: So as given in this code : Firstly there is a int statement it will execute once Similarly the other…
Q: Write C++ Program and Test the following function: void multiply (float a[ ], int n, float b[]); The…
A: Problem Analysis : First, we will input the size of both the arrays. Then we will input the value…
Q: 12. Consider the recursive function int gcd( int a, int b) int gcd( int a, int b){ if (b > a)…
A: Recursive function: It is a function that calls itself during execution. The number of invocations…
Q: Describe the execution of the following program segment. 1. int c[2] [3]; 2. int a[2] [3] ={ {5},…
A: Here the content of array a is 5 0 0 1 2 0 Content of array b is 2 4 6 8 0 0
Q: Pointers, modified) by Catherine Arellano We have a new game show that pits three people against…
A:
Q: Solve the following problem by writing a recursive function. Note: you must actively use recursion…
A: Even Numbered frog will have 2 toes Odd numbered frogs will have 1 toe
Q: Complete the following function definition to recursively print the index of a unique value in an…
A: we have to write all code in the blanks
Q: Question #1 Implement a recursive C++ function which takes an array of integers (arr) and the…
A: Array in c++ Syntax: <data-type> <array-name>[size] ; Example: int arr[10]; for size 10…
Q: a. Translate with a three-address statement, the following expression: n = f((x+2), y) – 5; b. If…
A: a. Given n = f((x+2), y) – 5; Three Address Code for the given expression is- (1) T1 = x+2 (2) T2 =…
Q: complete java program. (3 * 4 = 12 Marks) 1. Implement the following reverseArray() method on…
A: public static int[] reverseArray(int[] A) { int[] newArray = new int[A.length]; for (int i…
Q: 02: Detect the errors (at least 8) in the following C++ program: #include int i, j, array(5,5),…
A: Your answer is given below.
Q: int A[10] = { 3,2,1,0,4}; int *p = &A[3]; %3D
A: Required:
Q: Q6 In Python implement a recursive function named test() that accepts an integer parameter. If the…
A: Student :- 1. I will provide the code 2. I will provide the output
Q: •For the following algorithm, explain what it computes, state what the input size for analysis is,…
A: The given code is used for sorting an array The algorithm that is used here is called bubble sort,…
Q: Compilation Techniques a. Translate the three-address statement, the following expression: n =…
A: Solution: The Three- address code is a common intermediate representation by the front end of a…
Q: 12. Consider the recursive function (from class) int gcd( int a, int b) int gcd( int a, int b){ if…
A: Recursive function: A recursive function is a function that during its execution calls…
Q: (b) Write a function to compute f(n), that is defined recursively as: 1. ifn=0 f (1) ={1, Lf (n-1)+ƒ…
A: Answer(b) //Code is given below:#include <bits/stdc++.h>using namespace std;// recursive…
Q: Q5. Given an array of N elements. Get an integer K form user such that K<N. Now shift the elements…
A: C++ Program for above : #include <iostream> using namespace std; //it will rotate array…
Q: 1. Using C++, Implement the following using C++ arrays and Classes. find the Mean, Median, Mode,…
A: According to the information given:- We have to find mean , median, mode, standard deviation and…
Q: 5. Convert the following recursive functions into iterative functions. def max(k, n): if k == []:…
A: Here we have given 2 functions, max() and sum_odd(). The function max() returns the largest value…
Q: If A is an array of integers with width = 4, translate with three-address statement, the following…
A: 1. load the address of a 2. add i to address of a 3. get the content of address a 4. add 2 to it 5.…
Q: Given an array A, push all the zeros of the array to the front. The order of all other elements…
A: import java.util.Arrays;class Main{public static void pushZero(int[] A){int current = A.length -…
Q: Q#2 Write a recursive function zeroCount ( int a[ ], int s, int e) that receives an array of…
A: Given: Write a recursive function zeroCount ( int a[ ], int s, int e) that receives an array of…
Q: A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the…
A: Given: Write code for a procedure that given an array of n integers and a number, d, performs d left…
Q: Count consecutive summers def count_consecutive_summers(n): Like a majestic wild horse waiting for…
A: Coded using Python 3.
Q: 3. Describe the execution of the following program segment. 1. int c[2] [3]: 2. int a[2] [3] ={ (5}.…
A: - We need to fill the tables according to the code provided.
Q: (Python Code, polynomial interpolation)We implement a routine that evaluates a polynomial, given by…
A: Input to the Function : c: The vector for the coefficient of the polynomial x0: The data point…
Q: for this in C: Create an array of N items. Implement these using array initializers in the…
A: Here have to determine about c code for array sum and avarage.
Q: Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find…
A: So, to find out the missing element in the range of 1 to N can be done as below :
Q: 3. Describe the execution of the following program segment. C++ 1. int c[2] [3]; 2. int a[2] [3] ={…
A: int a[2][3]={{5},{1,2}}; Here we are creating array of size 2*3, but we but one element in first row…
Q: Implement a recursive C++ function which takes an integer array (A) and the starting (start) and…
A: Lets analyze what information we are given and what is expected out of it. Required : Recursive C++…
Q: 3. Write a pseudo code function m(i) to compute the following series using a recursive method m() =…
A: Pseudocode: float sumOfSeries(int i, int n, float s){ if (i > n ) return s;…
Q: Count consecutive summers def count_consecutive_summers(n): Like a majestic wild horse waiting for…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: Write in Java. Given an array A, push all the zeros of the array to the front. The order of all…
A: Actually, array is a collection of elements.
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…
(i) Consider the following code:
int myFunc(int A[], int n)
{
int i, j, max = 0;
int msis[n];
for ( i = 0; i < n; i++ )
msis[i] = A[i];
for ( i = 1; i < n; i++ )
for ( j = 0; j < i; j++ )
if (A[i] > A[j] &&
msis[i] < msis[j] + A[i])
msis[i] = msis[j] + A[i];
for ( i = 0; i < n; i++ )
if ( max < msis[i] )
max = msis[i];
return max;
}
- What is the time complexity of the
algorithm ?
Step by step
Solved in 2 steps
- iv) Write a JAVA program to merge two sorted arrays into a single sorted array. Take the sample arrays given below and print the result in the output. The time complexity of the program should be O(N+M) where N and M are the sizes of both the arrays. int []arr1 = {1, 6, 10, 14} int []arr2 = {2, 4, 5, 11, 16, 19} Print the merged array in the output.13. Implement function triangleArea(a,b,c) that takes as input the lengths of the 3 sides of a triangle and returns the area of the triangle. By Heron's formula, the area of atriangle with side lengths a, b, and c is √ s ( s−a )( s−b)( s−c ) , where s=(a+b+ c )/ 2 .>>> triangleArea(2,2,2)1.7320508075688772C++ Given a positive integer, N, the ’3N+1’ sequence starting from N is defined as follows: If N is an even number, then divide N by two to get a new value for N If N is an odd number, then multiply N by 3 and add 1 to get a new value for N. Continue to generate numbers in this way until N becomes equal to 1 For example, starting from N = 3 the complete ’3N+1’ sequence would be: 3, 10, 5, 16, 8, 4, 2, 1 Write code to ask the user to enter a positive integer (N) in the main() function. Write a function sequence() that receives the integer value N and display the ‘3N+1’ sequence starting from the integer value that was received (entered by the user). The function must also count and return the numbers that the sequenceconsists of. The returned value must be displayed from the main() function.
- Question 1 Work your way through the following code fragments. What would be printed? a) int i = -23; int * p = &i; printf("*p = %i\n", *p); b) int i; int * p = &i; printf("*p = %i\n", *p); c) int i = 48; int * p; printf("*p = %i\n", *p); d) int i = 10;int * p = &i;int j; j = ++*p; printf("j = %i\n", j);printf("i = %i\n", i); e) int i = 10, j = 20;int * p = &i;int * q = &j; *p = *q;printf("i = %i, j = %i\n", i, j);printf("*p = %i, *q = %i\n", *p, *q); i = 10; j = 20; p = q;printf("i = %i, j = %i\n", i, j);printf("*p = %i, *q = %i\n", *p, *q);in c++ You are given an array A of non-negative integers of size m. Your task is to sort the array in increasing order and print out the original indices of the new sorted array. Example: A= {12, 2, 6, 10, 9, 24,23, 33} After sorting the new array becomes A= {2,6,9,10,12,23,24,33}. The required output should be sorted array and original indexes "1 2 4 3 0 6 7", index of 2 in original array was 1 , index for 6 was 2 and so on.Answer the given question with a proper explanation and step-by-step solution. In Java, please. Consider the following problem. Input: an array of integers A[] Output: rearranges the array to have the following property: Suppose the first element in the original array A[], A[0] = x. In the rearranged array, suppose that x is at index i, that is A[i] = x. Then, we want the rearranged array to be such that A[j] <= x for all j < i and A[j] > x for all j > i. The rearranging should place all the values less than (or equal to) x to the "left" of x and all values larger than x to the right of x. Here's an example. Suppose the array has the elements in this initial order: 4 3 9 2 7 6 5 A[0] = 4. After rearranging elements, we get: 3 2 4 5 9 7 6 That is, A[0] = 4, is positioned in the resulting array so that all elements less than 4 (that is, 2, 3) are to its left (in no particular order), and all elements larger than 4 are to its right (again, in no particular order).
- 1.The following is the C code that you need to implement for this lab: uint8_ t f(uint8_tn) return(n<2)?(n):(f(n-1)+f(n-2)); The main function can be assumed as follows: int main() uint8_ t x; x=f(???); return 0; Obviously, " ? ? ? " is representing a value used to test the algorithm! Is "f"recursive? a.No answer text provided. b.Yes c.no d.depends on whether it is in for main 2.First, make the code in the previous question an actual C program so that it can be compiled and it runs. Play with it so that you feel comfortable with the logic of the code. Then implement the code in TTPASM. Note that you need to preserve the actual C code structure, this means you cannot it into a non-recursive subroutine. Furthermoreall conventions discussed in class regarding subroutines must be followed. The idea is that I should be able to substitute f with my own code, and main should work. Or, I can substitute main with my own, and f should work. Attach the source code of your assembly…In java: Develop a function that accepts an array of integers and returns their average. Develop a function that accepts an array of integers and a threshold value from the user. The function returns how many values in the array are strictly greater than the cutoff. Using the functions written for #1, #3, and #4, find the number of values above average in two randomly generated arrays. Develop two functions:a. a function that returns the index of the maximum value in an array of integers passed by a caller, the caller prints the returned index and the value at that indexb. a function that returns the index of the alphabetically first value in an array of strings, the caller prints the returned index and the value at that inde Develop two functions:a. a function that swaps the alphabetically first value in an array of Strings with the first value in the array. Call this function twice on two different arrays of Strings; in the caller, use the function written for #2b to display…Do not use static variables to implement recursive methods. USING JAVA USING: // P4 public static int min(int [] a, int begin, int end) { } Implement a recursive method min that accepts an array and returns the minimum element in the array. The recursive step should divide the array into two halves and find the minimum in each half. Demonstrate the output of min on the array int [] a = { 2, 3, 5, 7, 11, 13, 17, 19, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 23, 29, 31, 37, 41, 43 }
- c++ Implement a function that recursively calculates the nth number in the Fibonacci sequence of numbers. The Fibonacci sequence starts at 0 and 1. Each number thereafter is the sum of the two preceding numbers. This gives us the following first ten numbers: 0,1,1,3,5,8,13,21,34, .... Input Expected output0 01 17 139 34Compilation Techniques a. Translate the three-address statement, the following expression: n = f((x+2), y) – 5; b. If A is an array of integers with width = 4; Translate with a three-address statement, the following expression: x = a[i] + 2Answer in java code a) Given this: int [][] tda = new int [12][25];Write a loop to print the fourth row of this two-dimensional array tda {assume the array is filled with data..}b) Write Java code (only the loop) to find the maximum value in the array Ab of type integer (use enhancedfor-loop): c) Write the output of this code:int [][] tda = {{5,99,88,2},{22,76,12,87,77,66},{34,88,13,4},{9,76,77,11}};tda[1][4] = -22;for(int q=0; q<tda[3].length; q++) System.out.print(tda[2][q] + " ");