Quiz2Version2key

Quiz2Version2key - Analysis of Algorithms: Intro to...

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

View Full Document Right Arrow Icon
Analysis of Algorithms: CSE 5211 Fall 2010 Quiz 1 Points 40 Intro to Analysis of Algorithms: CSE 4081 Fall 2010 Quiz 1 Points 40 Time: 45 min Q1. The following recursive algorithm finds all possible permutations of an input list of characters. Input: a list L[1. .n] of characters, and the initial size of the list n . Output: each possible permutation of L . Algorithm Permute (list L, int n, int level, array A) (1) if (level = = n+1) then print A; else (2) for each element e of L do (3) A[level] = e; (4) L = L – e; // shrink the list by eliminating e (4) Permute (L, n, level+1, A); end for; end if; End algorithm Driver call : Permute(L, sizeof(L), level=1, empty A[ , , ]) ( 1a) (grad/ug: 2 ) How many lists are printed for n =4? 4! = 4.3.2.1 = 24 ( 1b) (g: 3, ug: 8 ) Draw the recursion tree for L=[x y z]. Also, indicate the post-order numbering of the tree. ( 1c) (Grad only : 5 ) Modify Permute to make sure A[i] <=A[i+1] according to the alphabet ordering (e.g., x<y<z), for each i=1. .(n-1), in the output, i.e., re-write the algorithm to prun appropriate branches of the recursion tree. You may check before printing (no pruning really), or check between (2) and (3) if e is
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/10/2012 for the course CSE 5211 taught by Professor Dmitra during the Spring '12 term at FIT.

Page1 / 3

Quiz2Version2key - Analysis of Algorithms: Intro to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online