{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exercise#3 - nz = NNZ(S is the number of nonzero elements...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
MIE335 Exercise #3 1 Algorithm analysis Look at the following pseudo code. procedure doSomething( A : list of items ) do swapped = false for i = 1 to length(A) - 1 if A[i] > A[i+1] then swap( A[i], A[i+1] ) swapped = true end if end for while (swapped == true) end procedure What does this algorithm do? What is the worst running time (Big-O)? Use this algorithm for the following input: A = { 5,3,7,1 } . Show all steps. Hint: you may wish to label your iterations! How many iterations will the above example take? 2 Set Cover Look at the following Matlab code. % A is a m*n binary (0,1) matrix % where each row is an element and each column a set % Thus x will be a n*1 binary vector
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % % nz = NNZ(S) is the number of nonzero elements in S. % I = FIND(X) returns the linear indices corresponding to % the nonzero entries of the array X. X may be a logical expression. Ap = A; x = zeros(size(A,2),1); while (nnz(Ap) > 0) cov = sum(Ap,1); ind = find(max(cov) == cov); x(ind) = 1; 1 eInd = find(Ap(:,ind)==1); Ap(eInd,:) = 0; end What does the above code do? What is its bound to the optimum? What is the stopping criteria? 3 MST What is a minimum spanning tree? What type of algorithm is Kruskal’s algorithm? Why? Write out pseudo code for Kruskal’s algorithm. 2...
View Full Document

{[ snackBarMessage ]}