This BubbleSort algorithm takes as its input the list of words w), W2, ...,W.. Step 1: Let j=1. Step 2: If j=n then output
This BubbleSort algorithm takes as its input the list of "words" w), W2, ...,W.. Step 1:...
7. An alternate version of bubblesort sorts the list in ascending order by moving the smallest value to the first position on the first pass and so on. The pseudocode for this version is shown below. The procedure swap is used to interchange the values in its two arguments. In the box, rewrite the contents of the list 5, 2, 3, 4, 1 every time it changes, in this5, 2, 3, 4, 1 new version of bubblesort. Walk through each...
5 3 1 0 Problem 10 Let wi = ,W2 W3 Let W = Span{W1,W2, W3} C R6. 11 9 1 2 a) [6 pts] Use the Gram-Schmit algorithm to find an orthogonal basis for W. You should explicitly show each step of your calculation. 10 -7 11 b) [5 pts) Let v = Compute the projection prw(v) of v onto the subspace W using the 5 orthogonal basis in a). c) (4 pts] Use the computation in b) to...
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
ALGORITHM X(A[0..n - 1]) // Input: A contains n real numbers for it 0 to n - 2 do for jt i +1 to n - 1 do if Aj] > A[i] swap A[i] and A[j] 1. What does this algorithm compute? 2. What is the basic operation? 3. How many times is the basic operation executed? 4. What is the efficiency class of this algorithm?
9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...
17. Consider the following algorithm: procedure Algorithm(n: positive integer; di,d2.. ,dn: distinct integers) for 1 to n-1 for 1 to n-k if ddi+ then interchange di and di+ print(k, I, d,ddn-1, dn) (a) |3 points Assume that this algorithm receives as input the integer-6 and the corresponding input sequence 41 36 27 31 17 20 Fill out the table below ds (b) 1 point Assume that the algorithm receives the same input values as in part a). Once the algo-...
Data Structure and Algorithm (a) Given the following integer list: 10 23 12 34 a[0] a[1] a[2] a[3] a[4] Show a trace (step by step) for each execution of Bubble Sort based on the following algorithm. //passes llone pass l/one comparison for (pass = 1 ; pass<= n ; pass++) for (i = 0); i<=n-2; i++) if (a[i] > a[i+1]) { hold = a[i]; a[i] = a[i+1]; a[i+1] = hold; } l/one swap (6 marks)
Problem 1. 1. Draw the decision tree for the merge-sort algorithm for the input consisting of 3 numbers: a, b,c. 2. Draw the 4 top levels of the decision tree for the merge-sort algorithm for the input consisting of 4 numbers: a, b, c, d 3. How may leaves does this tree have? 4. How many levels does this tree have? 5. What is the number of comparisons needed to sort these 4 numbers by the merge-sort algorithm in the...
2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi, v2, ..., vn], the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W. Tt i=1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using an array with size...