A numeric array of length N is given. We need to design a function that finds all positive numbers in the array. a) Describe approaches for solving optimal worst case and optimal average case performance, respectively.
Q: PRINT-OPTIMAL-PARENS(s, i, j){ if (i=j) then print “A”i else{ print “(”…
A: B) Since the matrix chain, multiplication algorithm uses 3 nested loops each iterating linearly thus…
Q: Let X1 < x2 <... < xn are real numbers representing the coordinates of N villages located along a…
A: Let us take an example and understand the problem Let the coordinates of the village be represented…
Q: Find the path from S to G using A* algorithm. Is it optimal ?
A: Find the path from S to G using A* algorithm. Is it optimal ?Basically,A* algorithm is best…
Q: Write a recurrence that would be used in dynamic programming for the following problem: Given a rod…
A: #include<stdio.h>#include<limits.h> // this is mainly used for the finding of two…
Q: Lets say you need to arrange seating in a club. There is a finite amount of seating, that is close…
A: Introduction: We have to write an algorithm for this problem.
Q: a. In the best-case scenario, what is the fewest possible comparisons needed to find a number using…
A: Given an array of 1000 integers , Lets see the best and worst case of Linear search
Q: We have two input arrays, an array A with n elements, and an array B with m elements, where m 2 n.…
A: Brute force algorithm would require us to perform linear search. Best case algorithm would require…
Q: Estimate in terms of n, the worst case time complexity of each of the following pseudo-code…
A: An algorithm is an arrangement of unambiguous guidelines for settling a issue, i.e., for acquiring a…
Q: Let m be a randomly chosen non-negative integer having at most n decimal digits, i.e. an integer in…
A: Let m be randomly chosen non-negative integer having at most n digits, i.e.,an integer in the…
Q: Let f(n) and g(n) be asymptotically nonnegative increasing functions. Prove: (f(n) + g(n))/2 =…
A: Asymmetrically non-negative, i.e. f (n) is not negative whenever n is large enough. Positive action…
Q: unning time of constant function f(n) = 6993. To find the upper bound of f(n), we have to find c and…
A: Introduction: An element that is greater than or equal to the sum of all the elements in a given…
Q: Given a positive integer number n (i.e., n>0), we can use the following algorithm to find the nth…
A: According to the Question below the Solution:Output:
Q: (b) Prove that your algorithm from part (a) is optimal up to constant factors. In other words, if f…
A: Comparison Sort Comparison sort is basically demonstrated to study of various catalogs through which…
Q: An input number x is given. Present an optimal algorithm with time complexity O(log n) for EREW PRAM…
A: Paraller Random Access machine(PRAM) is a model, which is considered for most of the parallel…
Q: You are given an array of positive integers S[1, . . . , n]. You are initially positioned at the…
A: Naive approach: Start from the first element and recursively call for all the elements reachable…
Q: Let's say there are n villages, {X1, . . . , Xn} on the country-road and we aim to build K < n…
A: The algorithm for the given problem can be written as: 1. Repeat the following steps for 'n' number…
Q: We have N jobs and N workers to do these jobs. It is known and known (as a positive numerical value)…
A: If a number is added to or subtracted from all of the entries of any one row or column of a cost…
Q: In the Fractional Knapsack Problem, you are allowed to take f of each object, where f is some r…
A: Here first we need to find profit/weight or value/weight ratio of each item and then choose items.
Q: alculating the optimal cut of the text t of length n, where we have m cut points given in the field…
A: Write the formula for calculating the optimal cut of the text t of length n, where we have m cut…
Q: Q5. Suppose we want to minimize J(0) as a function of 0 by using one of the advanced optimization…
A: Suppose we want to minimize J(θ) as a function of θ by using one of the advanced optimization…
Q: This is a memoized version which uses a global array Q to store the results of computations.…
A: The algorithm given is:- for (i=0; i< length[Q]; i++){ Q[i] = -1; } int Q-Optimal(int n)…
Q: In this exercise we will develop a dynamic programming algorithm for finding the maximum sum of…
A: Actually, algorithm is a step by step process.
Q: Given an array of digits D[1, . . . , n], find the largest multiple of three that can be formed by…
A: When there are multiple questions, we must answer the first one.
Q: Design a backtracking procedure to reconstruct the optimal assignment of characters in the Sankoff…
A: Answer is given below-
Q: he heuristic path algorithm is a best-first search in which the objective function is f(n) = (4…
A: When the value of w is as follows: O≤w≤1, then the algorithm will be optimal. if w ≤ 1, then the…
Q: We are now also given an array of integers A = {a;}"-1, and some random integer k. 1. Develop an…
A: I am solving this in Python language . I am giving you the code as well the screenshot of code and…
Q: You are given a set of n (closed) intervals on a line: [a1, bi], [a2, b2], ., [an, bn]. Design an…
A: Answer is given below
Q: Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem…
A: The divide and conquer recurrence relation is used to find the running time T(n) of a…
Q: Assume we have a sorted list. Binary search algorithm takes time and grows the linear search…
A: Filled the given statement
Q: algorithm cutRod(p, N) input: array of prices p of length n+1; rod length n output: total money…
A: The complete solution for the above algorithm is shown below: algorithm cutRod(p, N) input: array…
Q: locations in A. The worst-case number of probes performed by an optimal algorithm is
A: Here, in this question as we can see each 0s are followed by 1s so, we can have sorted sequence and…
Q: How can you establish that an algorithm is optimal?
A: Answer An algorithm can be said to be optimal if the function that describes its time complexity in…
Q: Do
A:
Q: Given an array of intervals I[1, . . . , n] where I[i] = [si, fi], find the minimum number of…
A: Define subproblem: If the intersection of two intervals [a, b] and [c, d], where a=b and c=d, is not…
Q: Find the Worst case time Complexity of the following recursive functions T(n) = T(n-1)+n -1, T(1) =…
A: T(n) = T(n-1)+n-1, T(1) = 0
Q: Consider an n by n matrix, where each of the n² entries is a positive integer. If the entries in…
A: The statement is TRUE. With a matrix of size nxn, having integers in increasing order from left to…
Q: 38. Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a…
A: Check further steps for the answer :
Q: a. If an optimal solution can be created for a problem by constructing optimal solutions for its…
A: Question a. If an optimal solution can be created for a problem by constructing optimal solutions…
Q: Algorithm A and B have a worst case running time of 09 and O(log n), respectively. Therefore,…
A: Ans. False
Q: We have an array A[1 : n] consisting of n positive integers in {1,..., M}. Our goal is to check…
A: Given: An array A[1 : n] consisting of n positive integers in {1, . . ., M}. Asked: to find the…
Q: Consider the Coin Changing problem: Given n coin denominations 0 d, and find the values dd Describe…
A: coin change(d, n, k) M[n+1] M[0] = 0 for j in 1 to n minimum = INF for i in 1 to k…
Q: Consider a randomized algorithm SCRAMBLE-SEARCH that works by first randomly permuting the input…
A: Consider a SCRAMBLE-SCRATCH procedure in which at first randomly permute the array and then use…
Q: The monotone restriction (MR) on the heuristic function is defined as h (nj ) 2 h (ni ) – c (ni ,…
A: The Highlighted path is the best first path chosen uisng best first search algorithm. Blue circle…
Q: 1. /15 points] Consider the following function: Func1(A, n) * A is an array of integers 1 80; 2 for…
A: a)Worst case running time of Func1:The random number between 1 to “n” is assigned to “k” in the…
Q: The heuristic path algorithm is a best-first search in which the objective function is f(n)= (w+2) *…
A: f(n) = (w+2)g(n) + (2w-6)h(n), Here 1<=w<=16…
Step by step
Solved in 4 steps with 2 images
- The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stocks price for all n days. The span S; of the stocks price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day. For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}. Example 1: Input: N = 7, price[] Output: 1 1 1 2 1 4 6 = [100 80 60 70 60 75 85]We have N jobs and N workers to do these jobs. It is known at what cost each worker will do each job (as a positive numerical value). We want to assign jobs to workers in such a way that the total cost of completion of all jobs is minimal among other possible alternative assignments. For this problem, write the algorithm as pseudocode, whose input is a matrix representing worker/job costs, and the output is a list of tuples showing which work will be done by which worker, and that tries to reach the solution with GREEDY technique. Explain in what sense your algorithm exhibits greedy behavior. What is the time complexity of your algorithm? Interpret if your algorithm always produces the best (optimum) result for each instance of the problem.There are n students who studied at a late-night study for final exam. The time has come to order pizzas. Each student has his own list of required toppings (e.g. mushroom, pepperoni, onions, garlic, sausage, etc). Everyone wants to eat at least half a pizza, and the topping of that pizza must be in his reqired list. A pizza may have only one topping. How to compute the minimum number of pizzas to order to make everyone happy?
- Consider array A of n numbers. We want to design a dynamic programming algorithm to find the maximum sum of consecutive numbers with at least one number. Clearly, if all numbers are positive, the maximum will be the sum of all the numbers. On the other hand, if all of them are negative, the maximum will be the largest negative number. The complexity of your dynamic programming algorithm must be O(n2). However, the running time of the most efficient algorithm is O(n). Design the most efficient algorithm you can and answer the following questions based on it. To get the full points you should design the O(n) algorithm. However, if you cannot do that, still answer the following questions based on your algorithm and you will get partial credit. Write the recursion that computes the optimal solution recursively based on the solu- (a) tion(s) to subproblem(s). Briefly explain how it computes the solution. Do not forget the base case(s) of your recursion.A team sport game has m players in a team and a tournament can have n competing teams. TeamT1 ranks higher than team T2 if there is a way such that every member of T1 ranks higher than acorresponding member of T2 (note that the ranking is based on individual team members).(1) Design an efficient algorithm (pseudo code) to determine whether or not two teams T1and T2 can be ranked.(2) Given n teams {T1, T2, ... , Tn}, abstract the team ranking problem as a graph.(3) Design an efficient algorithm (pseudo code) to find the longest sequence <Ti1 , Ti2 ,..., Tik> of teams such that Tij ranks higher than Tij + 1 for j = 1,2,..., k − 1.(4) Analyze the time complexity of your algorithm in terms of m and n.Question 2) We have N jobs and N workers to do these jobs. It is known at what cost each worker will do each job (as a positive numerical value). We want to assign jobs to workers in such a way that the total cost of completion of all jobs is minimal among other possible alternative assignments. For this problem, write the algorithm as pseudocode, whose input is a matrix representing worker/job costs, and the output is a list of tuples showing which work will be done by which worker, and that tries to reach the solution with GREEDY technique. Explain in what sense your algorithm exhibits greedy behavior. What is the time complexity of your algorithm? Interpret if your algorithm always produces the best (optimum) result for each instance of the problem.
- Correct answer will be upvoted else downvoted. Computer science. Positive integer x is called divisor of positive integer y, in case y is distinguishable by x without remaining portion. For instance, 1 is a divisor of 7 and 3 isn't divisor of 8. We gave you an integer d and requested that you track down the littlest positive integer a, to such an extent that a has no less than 4 divisors; contrast between any two divisors of an is essentially d. Input The primary line contains a solitary integer t (1≤t≤3000) — the number of experiments. The primary line of each experiment contains a solitary integer d (1≤d≤10000). Output For each experiment print one integer a — the response for this experiment.Today is Max's birthday. He has ordered a rectangular fruit cake which is divided into N x M pieces. Each piece of the cake contains a different fruit numbered from 1 to N*M. He has invited K friends, each of whom have brought a list of their favorite fruit choices. A friend goes home happy if the piece he receives is of his favorite fruit. Note that each friend can receive only one piece of cake. Design a way for Max to find the maximum number of friends he can make happy. Input The first line of the input consists of an integer - numOfFriends, representing the number of friends(k). The next Klines consist of X+1 space-separated integers, where the first integer represents the count of choices of the th friend followed by X space-separated integers representing the fruits he likes. The next line of the input consists of an integer - numN, representing the number of rows. The next line of the input consists of an integer - numM, representing the number of columns. Output Print an…Given A = {1,2,3} and B={u,v}, determine. a. A X B b. B X B
- This problem is taken from the delightful book "Problems for Mathematicians, Young and Old" by Paul R. Halmos. Suppose that 931 tennis players want to play an elimination tournament. That means: they pair up, at random, for each round; if the number of players before the round begins is odd, one of them, chosen at random, sits out that round. The winners of each round, and the odd one who sat it out (if there was an odd one), play in the next round, till, finally, there is only one winner, the champion. What is the total number of matches to be played altogether, in all the rounds of the tournament? Your answer: Hint: This is much simpler than you think. When you see the answer you will say "of course".Single Point based Search: Fair share problem: Given a set of N positive integers S={x1, x2, x3,…, xk,… xN}, decide whether S can be partitioned into two sets S0 and S1 such that the sum of numbers in S0 equals to the sum of numbers in S1. This problem can be formulated as a minimisation problem using the objective function which takes the absolute value of the difference between the sum of elements in S0 and the sum of elements in S1. Assuming that such a partition is possible, then the minimum for a given problem instance would have an objective value of 0. A candidate solution can be represented using a binary array r=[b1, b2, b3,…, bk,… bN], where bk is a binary variable indicating which set the k-th number in S is partitioned into, that is, if bk =0, then the k-th number is partitioned in to S0, otherwise (which means bk =1) the k-th number is partitioned in to S1. For example, given the set with five integers S={4, 1, 2, 2, 1}, the solution [0,1,0,1,1] indicates that S is…Suppose a candidate solution p, where p is a phenotype consisting of 4 vertices. Suppose that minimum fitness occurs when no pair of vertices in p are connected, and maximum fitness occurs when all pairs of vertices in p are connected. Write a pseudocode on how to calculate the fitness F of p.