2. Write a function that multiplies a polynomial by a constant (or scalar). scale :: (Num a, Eq a) => a -> Poly a -> Poly a For example: > scale 2 (P [-1,0,1]) P [-2,e,2] > scale e (P [0,0,2]) P []
Q: Consider the list l= [3,2,1]. We can use this list to construct a polynomial p by taking the…
A: Answer: Python Source Code: def poly_builder(l): x = 3 l.reverse() n = len(l) res = l[0]…
Q: Python Programming Problem: You are given a sequence of integers A1, A2, ..., AN and an integer M.…
A: Required:We have to change the value of Apos to val(in our code it is taken as a and v) and find the…
Q: Identify the base case(s) of the function Puzzle. 2. Identify the general case of the function…
A: Given :- Consider the following recursive function:int Puzzle(int base, int limit){if (base >…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: Python Programming Problem: You are given a sequence of integers A1, A2, ..., AN and an integer M.…
A: We are required to create a python code to process the given process the given Q queries. Algorithm:…
Q: What is the time complexity of the following C language function, which assumes that matrix[][] is…
A: The time complexity for the following c language function will be :
Q: A function chicken_and_egg() has been analyzed to run with 0(2") complexity to process a list of…
A: Ans:) Given, complexity = O(2n) time taken = 3 mins, list size = 10
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Array Output - string based on the condition logic - for(let i=1;i<=n;i++){…
Q: A function dog_and_fox() has been analyzed to run with O(n²) complexity to process a list of size n.…
A: Time Complexity = O(n2) for size n 5 days to process a list of size 1000 for list of size 2000 would…
Q: The code of a sequential search function is shown on textbook page 60. In fact, if the list is…
A: code snippet:
Q: A matrix M with i rows, j columns can be transposed into a matrix N having j rows and i columns by…
A: //a.) Code : //Include necessary header files#include <stdio.h>// Defining a Function that…
Q: Python Programming Problem: You are given a sequence of integers A1, A2, ..., AN and an integer M.…
A: Required:We have to change the value of Apos to val(in our code it is taken as a and v) and find the…
Q: K-1 roblem 2. Write a function loss(x, q) to return E ita max(0, x¡ – xa + 1), where x is a 1darray…
A: import numpy as np #importing numpy as np def loss(x,q):k = len(x) #finding the lenght of the…
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Integer Output - string based on condition logic - for(let i=1;i<=n;i++){…
Q: Please answer it in Python Write a function show_winner that takes as an argument a dictionary of…
A: def Show_winner(dictonary): #First find smallest score smallest = 99999 for i in…
Q: Define a function named get_sorted_in_parallel(tuples1, tuples2) which takes two tuples of integers…
A: Solution - Programming Language - Python All necessary comments are included in program code.…
Q: IMPORTANT: For part 3, implement an iterative dynamic programming solution. You are driving from…
A: The required code in Python3 for the given problem: #function to find minimum toll def…
Q: You are give a matrix (a list of lists) of DISTINCT integers and a target number. Each row in the…
A: Program: public class Main { public static int[] searchMatrix(int[][] matrix,int target){…
Q: a. Evaluate the expression mystery [2, -3, 4, -5]. b. Define the above function directly and…
A: Haskell function Is a functional programming language. Doesn't contain its own functional…
Q: Data Abstraction and Problem Solving with C++ Consider the following C++ function f, which calls the…
A: Answer : In order to understand and find the number of comparisons performed by the function f,
Q: PYTHON DATASET given x = np.array([i*np.pi/180 for i in range(60,300,4)]) np.random.seed(10)…
A: Answer: I have done code and also I have attached code.
Q: Given a matrix of characters A of sizen x m and a string s, write a C function that counts how many…
A: #include<stdio.h> #include<string.h> #define MAXM 100 //function count int count(char…
Q: An algorithm to fill any linear structure with all prime numbers between an upper bounding boundary…
A: We will write an algorithm to fill a linear data structure with prime numbers between two bounds and…
Q: A function owl_and_cat () has been analyzed to run with O(n) complexity to process a list of size n.…
A: Given Data : Time complexity of owl_and_cat() is O(n) where n = size of list. The Time taken by…
Q: 2. (a) Write a function, called myListFn, which takes a single argument n and implements the…
A: Below find the solution !! (a) myListFn <- function(n) { xVec <- rnorm(n) xBar <-…
Q: Write a program in C++ that initializes a 4 x 4 Matrix as given below and then finds and displays…
A: Start Initialize an array i from 0 to 3 j from 0 to 3 print element at index ji Stop
Q: Write a function f1 that takes the root of a binary tree as a parameter and returns the sum of the…
A: /* Program to check children sum property */ #include <bits/stdc++.h> using namespace std;…
Q: (a) Write a function named getShortestPath (graph, from, to) that takes a graph as an input and…
A: Actually, python is a easiest programming language. It is a dynamically typed language.
Q: In a programing language using OCaml do the following: Use the built-in higher order functions2…
A: Higher-order functionsThere is no restriction on functions, which may thus be passed as arguments…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: A[i] = p*A[i-1] + q where p and q are coefficients of the relation.
Q: Write a O(n) time complexity C-function void maxmin(int data[], int n, int *min, int *max); finds…
A: Below is the implementation of the function: - Explanation of the function: - Defining the function…
Q: 5K-1 Problem 2. Write a function loss(x, q) to return Eita max(0, x¡ – x, + 1), where x is a 1darray…
A: ALGORITHM:- 1. Initialise the array. 2. Call the loss function with the corresponding array. 3.…
Q: Define a function named get_sorted_in_parallel (tuples1, tuples2) which takes two tuples of integers…
A: The python code for the above-given question is given below:
Q: P01: FN → FN–HEAD FN–BODY P02: FN–HEAD → TYPE id ( PARAM–LIST ) P03: TYPE → char P04: TYPE…
A: Pushdown Automata is a finite stack of additional memory that allows Pushdown Automata to understand…
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Integer Output - returns "Strong" if it is a strong prime, "Weak" if it is a weak prime,…
Q: (a) Write a recursive function to compute n! for n > 1. (b) Write a recurrence relation for the work…
A: As per our company guidelines we are supposed to answer only three subparts. Please repost other…
Q: 31. The given diagram shows the flow-chart for a recurtive function A(n). Assume that all statements…
A: Given:
Q: Write a C function, void sum_rows( int a*,int sum*,int n) to compute the sum of row elements in a…
A: void sum_rows(int a*, int sum*, int n) //Function for row sum { for(int i = 0; i < n;…
Q: Write a function that takes one input, a matrix X. Your function should modify X and return the…
A: NOTE - Here I have used the Python programming language. Here I have created the function named…
Q: Python Programming Problem: You are given a sequence of integers A1, A2, ..., AN and an integer M.…
A: Required:We have to change the value of Apos to val(in our code it is taken as a and v) and find the…
Q: Is the following statement TRUE or FALSE? If it is TRUE, prove it, and if it is FALSE, provide a…
A: The function is the relationship from the elements of one set S to the elements of the other set T.…
Q: 1. A function polyEval x p that evaluates the polynomial (represented by list) p at x; for ex-…
A: Note: Answering the question in python as no language is mentioned. Input : Value of x Value of…
Q: Write a C function insert(), to insert an integer x into a sorted array A[] (sorted in ascending…
A: Hi there, Please find your solution below, I hope you would find my solution useful and helpful.…
Q: 1 Write a Racket function (is-sorted x) where x is a list of numbers. Function returns true (#t) if…
A:
Q: Write a MATLAB function linearSearch.m. Your MATLAB function should take as parameters an unsorted…
A: Actually, program is an executable software that runs on a computer.
Q: Python Programming Problem: You are given a sequence of integers A1, A2, ..., AN and an integer M.…
A: We are required to create a python code to process the given process the given Q queries. Algorithm:…
Q: 1. def f(x): """ Evaluates function `f(x) = x^2 - 15 \sin(x * \pi/3)` Parameters ---------- x :…
A: Task : In the given question , we have given the partial code in python. Task is to find implement…
Q: Suppose, you are given two matrices (A and B) as input, you have to perform the following tasks: I.…
A: According to Bartleby policy, we will answer only the first 3 questions Attaching the code and…
Q: Compute time complexity of the given program. The complexity computation should be for the complete…
A: time complexity of Bubble Sort is O(n2). The space complexity for Bubble Sort is O(1), because only…
Q: Exercise 4. DYNAMIC PROGRAMMING: COUNTING CERTAIN DNA SEQUENCES. DNA strings use the alphabet A, C,…
A: Program to print DNA sequence Given the value of n i.e, the number of lobes. Print the double-helix…
Step by step
Solved in 3 steps with 1 images
- Write a function in c++ is ordered that takes an integer array and its size as parameters and returns true if the array elements are ordered in nondecreasing order and returns false if not. For example, integers in {10,0,1,1,5,1009} are ordered in nondecreasing order. On the other hand, integers in {1, 2, 3, 8, 4, 19} are not since 8 > 4Interesting, intersecting def squares_intersect(s1, s2): A square on the two-dimensional plane can be defined as a tuple (x, y, r) where (x, y) are the coordinates of its bottom left corner and r is the length of the side of the square. Given two squares as tuples (x1, y1, r1) and (x2, y2, r2), this function should determine whether these two squares intersect, that is, their areas have at least one point in common, even if that one point is merely the shared corner point when these two squares are placed kitty corner. This function should not contain any loops or list comprehensions of any kind, but should compute the result using only integer comparisons and conditional statements. This problem showcases an idea that comes up with some problems of this nature; it is actually far easier to determine that the two squares do not intersect, and negate that answer. Two squares do not intersect if one of them ends in the horizontal direction before the other one begins, or if the same…Write a function called number_matrix(r,c) that takes two parameters r and c and PRINTS ON THE SCREEN a matrix of numbers as follows: 1 2 3 4 5 .... 2 3 4 5 6 .... 3 4 5 6 7 .... ... In this pattern, each row contains c numbers and there are r rows. For example, number_matrix(4,3) results in: 1 2 3 2 3 4 3 4 5 4 5 6
- Write the following three functions: a) The function gets an array A of length n of ints, and a boolean predicate pred. It returns the smallest index i such that pred(A[i])==true.If no such element is not found, the function returns -1.int find(int* A, int n, bool (*pred)(int)); b) The function gets an array A of length n of ints, and a function f. It applies f to each element of A.void map(int* A, int n, int (*f)(int)); c) The function gets an array A of length n of ints, and a function f. The function f gets 2 ints and works as follows: Start with accumulator = A[0] For i=1...length-1 compute accumulator=f(accumulator, A[i]) Return accumulator For example, if f computes the sum of the two inputs, then reduce() will compute the sum of the entire array.int reduce(int* A, int n, int (*f)(int,int));Write the following three functions in c programming language: a) The function gets an array A of length n of ints, and a boolean predicate pred. It returns the smallest index i such that pred(A[i])==true.If no such element is not found, the function returns -1.int find(int* A, int n, bool (*pred)(int)); b) The function gets an array A of length n of ints, and a function f. It applies f to each element of A.void map(int* A, int n, int (*f)(int)); c) The function gets an array A of length n of ints, and a function f. The function f gets 2 ints and works as follows: Start with accumulator = A[0] For i=1...length-1 compute accumulator=f(accumulator, A[i]) Return accumulator For example, if f computes the sum of the two inputs, then reduce() will compute the sum of the entire array.int reduce(int* A, int n, int (*f)(int,int));Write a function f which takes three pointers to int variables (a, b, c). Then it should:-Set the first variable to the sum of values of the variables (a + b + c).-Set the second variable to difference between maximum and minimum of values ( max(a,b,c) - min(a,b,c) )-Set the third variable to median of a, b, c.For example:if a = 5, b = 10, c = 2Then f(&a, &b, &c) should:Set a to 17 (that is the sum)Set b to 8 (that is max - min = 10 - 2)Set c to 5 (that is the median of 5, 10 and 2) NOTE: You are already provided a test main which checks your code for evaluation. DO NOT MODIFY IT or your answer will NOT be accepted. #include<stdio.h> // Write your code here... //////////////////////////////////////////// THIS IS THE TEST MAIN FOR YOUR PROGRAM// DO NOT MODIFY IT!!int main() {int a = 1;int b = 2;int c = 3;for (int i = 0; i < 2; i++) {f(&a, &b, &c);printf("%d\n", a);printf("%d\n", b);printf("%d\n", c);}return 0;}//////////////////////////////////////////…
- Write a function in c programming language that gets an array of points ( function is defined as : typedef struct{ int x; Int y; } point; ) and sorts the array using qsort().Given two points a=(ax,ay) and b=(bx,by) we compare them as follows: 1) if (ax)2+(ay)2 < (bx)2+(by)2, then a should come before b in the sorted array. 2) if (ax)2+(ay)2 = (bx)2+(by)2, then we compare the points by the x coordinate. Remark: For a point a=(ax,ay) the quantity ((ax)2+(ay)2)1⁄2 is the distance of a from the (0,0). That is, we sort the points according to their distance to (0,0), and if for points at the same distance, then we sort them according to the first coordinate. You will need to implement the comparison function, and apply qsort() on the array with this comparison function. For example: - Input: [(3,2), (7,1), (1,1), (3,4), (5,0), (7,1)] - Expected output: [(1,1), (3,2), (3,4), (5,0), (7,1), (7,1) ] Explanation:(1,1) is first because 12+12=2 is the smallest(3,2)…Programming Language: C Write the following three functions: a) The function gets an array A of length n of ints, and a boolean predicate pred. It returns the smallest index i such that pred(A[i])==true. If no such element is not found, the function returns -1. int find(int* A, int n, bool (*pred)(int)); b) The function gets an array A of length n of ints, and a function f. It applies f to each element of A. void map(int* A, int n, int (*f)(int)); c) The function gets an array A of length n of ints, and a function f. The function f gets 2 ints and works as follows: 1. Start with accumulator = A[0] 2. For i=1...length-1 compute accumulator=f(accumulator, A[i]) 3. Return accumulator For example, if f computes the sum of the two inputs, then reduce() will compute the sum of the entire array. int reduce(int* A, int n, int (*f)(int,int)); Test for the functions: // used for test Q3-find bool is_even(int x) { return x%2 == 0; } bool is_positive(int x) { return x>0; } void…Write a C++ function, bool ok(int q[]), which takes an array q and returns true if the array represents a valid configuration of the eight queens and returns false otherwise.
- In C programming Mathematically, given a function f, we recursively define fk(n) as follows: if k = 1, f1(n) = f(n). Otherwise, for k > 1, fk(n) = f(fk-1(n)). Assume that there is an existing function f, which takes in a single integer and returns an integer. Write a recursive function fcomp, which takes in both n and k (k > 0), and returns fk(n). int f(int n);int fcomp(int n, int k){Language: C Write the function convolve that will calculate the confolution of two functions f, g on [0, t] interval. The convolution is defined as (f ∗ g)(t) = Z t 0 f(τ )g(t − τ ) dτ for f, g : [0, ∞) → R. The argument function f and g should be passed by pointers. The integral should be approximated by the Riemman sum, i.e., Z b a f(x) dx = Xn i=1 f(xi) ∆x, where ∆x = b−a n and xi = a + i ∆x. Define the functions func1, func2 and func3, that return sin(x), cos(x) and x 3 respectively. Use these functions to calculate the convolution of f = sin(x), g = sin(x) f = sin(x), g = cos(x) f = sin(x), g = x 3 for t = 2π and n = 1000.Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6}, the function would return 6, since the subsequence {1, 4, 6} is the longest that is strictly increasing. Develop a function that takes a string and a single character, then returns a list of the indexes in the string where the character occurs. For example, given the string “bookkeeper” and ‘e’, the function would return {5, 6, 8} since ‘e’ occurs at those positions. Return an empty list if the character does not appear in the string even once. Develop a function that takes two lists of integers and returns a list containing any value that appears in both parameter lists.