# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

1 Page

### 2c03-review - 00066

Course: CAS 2c03, Spring 2003
School: McMaster
Rating:

Word Count: 165

#### Document Preview

Factorial(int int n){ int f=1; for(int i=1;i&lt;=n;i++) f*=i; return f; } //DnC implements solution to 10(a). it uses divide and conquer method int DnC(int n,int m){ if(m==0 || n==m) return 1; else return DnC(n-1,m)+DnC(n-1,m-1); } //DP implements solution to 10(c). it uses dynamic programing technique method int DP(int n,int m){ //allocating the table int **L; L=new int*[n+1]; for(int i=0;i!=n+1;i++) L[i]=new...

Register Now

#### Unformatted Document Excerpt

Coursehero >> Canada >> McMaster >> CAS 2c03

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Factorial(int int n){ int f=1; for(int i=1;i<=n;i++) f*=i; return f; } //DnC implements solution to 10(a). it uses divide and conquer method int DnC(int n,int m){ if(m==0 || n==m) return 1; else return DnC(n-1,m)+DnC(n-1,m-1); } //DP implements solution to 10(c). it uses dynamic programing technique method int DP(int n,int m){ //allocating the table int **L; L=new int*[n+1]; for(int i=0;i!=n+1;i++) L[i]=new int[m+1]; //initializing the table i=0;i!=n+1;i++) for(int L[i][0]=1; for(int i=0;i!=m+1;i++) L[i][i]=1; //filling the table for(int i=1;i!=n+1;i++) for(int j=1;j!=m+1&&j<i;j++) L[i][j]=L[i-1][j]+L[i-1][j-1]; //result is in L[n][m] int r=L[n][m]; for(int i=0;i!=n+1;i++) delete[] L[i]; delete[] L; return r; } void main(){ cout<<"DnC(14,10):\t"<<DnC(14,10)<<endl; cout<<"DP(14,10):\t"<<DP(14,10)<<endl; 9
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

McMaster - CAS - 2c03
12.[10] Suppose characters a, b, c, d, e, f, g, h, i, j have probabilities 0.02, 0.02, 0.03, , 0.04, 0.05, 0.10, 0.10, 0.13, 0.20, 0.31, respectively. Construct an optimal Huffman code and draw the Huffman tree. Use the following rules: a. Left: 0, right:
McMaster - CAS - 2c03
13.[20] Suppose T is a Huffman tree, and that the leaf for symbol a has greater depth than the leaf for symbol b. Prove that the probability of symbol b is no less than that of a. It can be proven in many ways by induction. The simplest seems to be the fo
McMaster - CAS - 2c03
Another possible solution, in the similar style is the following. For any Huffman tree, if we combine two leaves, and use another symbol to represent it. Assigning the sum of probability of two leaves to the new symbol, we get a new Huffman tree for a new
McMaster - CAS - 2c03
Now, we suppose prob(a) &gt; prob(b), which means a is not used before b is used in construction of Huffman tree. These imply that prob(a) &gt; prob(T), because prob(b) and prob(T) must be the smallest two ones. With the same reason, prob(c) &gt; prob(b), pro(T),
McMaster - CAS - 2c03
16.[20] Suppose we use the 2-3 trees to implement the WMERGE (i.e. a MERGE(A,B), but the set is totally ordered and all the elements of A are smaller than the elements of B) and SPLIT. a.[10] Show the result of splitting the tree of Question (1a) at 7. 25
McMaster - CAS - 2c03
Question 3 5 1 0 2 3 4 6 7 8 10 9 11 12 13 After deletions: 5 1 0 2 4 6 7 8 10 9 11 12Question 9 8 2 5 10 j f1 [j ] f2 [j ] l1 [j ] l2 [j ] 1 10 15 2 20 19 1 1 3 22 26 1 3 2 6 4 27 27 1 1 5 36 33 1 2 6 39 41 2 2 10 2 1 7 7 49 47 1 2 8 52 52 2 2 1 3 4 5 4
McMaster - CAS - 2c03
Question 14 (a) 519110 After deletions:234678101213519110 (b)2467810122690 After deletions:134578101112132690 (c)14578101112590 After deletions:1234678101112135901246781011122
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 4. Total of this assignment is 231 pts. 100%= 205. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, a
McMaster - CAS - 2c03
Using KMPabaAbabaababbababaaababaababb pass1 a b b pass2 aB pass3 Abb pass4 abb pass5 ab pass6 abb pass7 abbababaaabab # of comparisons 3 2 3 3 2 3 13 Total 293.[16] Abstract Data Type DIGRAPH involves the following 3 operations on directed graphs : FIR
McMaster - CAS - 2c03
b.[8] Linked adjacency lists Assume the ADT LIST is defined with proper functions implemented. function FIRST(v:integer): position begin return(FIRST_LIST(A[v]) end function NEXT(v:integer, i:position): position begin return(NEXT_LIST(A[v],i) end function
McMaster - CAS - 2c03
a.[5] a a b c d e f g h i b[5] a [b,5,nil] b [c,1] [d,3,nil] c [a,3] [d,2] [e,3] [h,2,nil] d [a,4] [b,4,nil] e [b,2] [d,3] [f,2] [i,4,nil] f [b,1] [d,2,nil] g [b,1] [c,3,nil] h [d,2] [g,3,nil] i [a,1,nil] 3 4 b c 1 4 2 1 1 d 3 2 3 2 3 2 1 3 e 3 2 f 5 g h
McMaster - CAS - 2c03
7.[20] A root of a directed acyclic graph (dag) is a vertex r such that every vertex of the dag can be reached by a directed path from r. Write a program to determine whether a dag is rooted. Assume that the dag is represented using adjacency lists. Make
McMaster - CAS - 2c03
10.[10]Use a depth-first search algorithm to identify all the articulation vertices and biconnected components in the graph from Question 9. Draw an appropriate depth-first graph and indicate all the low and dfnumber values.A solution at the end11.[15]
McMaster - CAS - 2c03
A possible solution M cfw_(A,I) cfw_(A,I),(B,G) cfw_(A,I),(B,G),(C,J) cfw_(A,I),(B,G),(C,J),(E,K) cfw_(A,I),(B,G),(C,J),(E,K),(M,N) cfw_(A,I),(B,H),(C,J),(D,G),(E,K),(M,N) cfw_(A,I),(B,H),(C,J),(D,G),(E,K),(F,J),(M,K) augmenting path relative to M A-I B-G
McMaster - CAS - 2c03
Question 5(a)a 1/18/1b 3/16/3g 12/13/9f 2/17/2c 4/15/4i 8/9/7e 7/10/6d 5/6/5h 11/14/8Tree edges are black, back edges are red, forward edges are green and cross edges are blue. The numbers in each vertex are (d[v ]/f [v ]/dfnumber[v ]). Question
McMaster - CAS - 2c03
Question 8 Assuming alphabetical ordering, the solution is:A 1/12 B 2/3 C 4/5O 28/29H 14/17I 15/16G 13/18 D 7/8 F 6/11 E 9/10 N 25/26J 19/30K 20/21L 22/27M 23/24Ordering by decreasing nishing times gives the topological sorting:JOLNMKGH
McMaster - CAS - 2c03
(c) Depth-rst spanning tree (costs ignored):a f51b2g c3 8i6e4d7h(d) Breadth-rst spanning tree (costs ignored):1a1 1 11b2g c2f i e2dhQuestion 10 We use the depth-rst spanning tree from question 9(c), and redraw it to highlight t
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 5. Total of this assignment is 75pts. 100% equals 65. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right
McMaster - CAS - 2c03
Question 1 Dijkstras algorithms works as follows if alphabetical ordering (as in the last assignment) is assumed. Edges are numbered in the order that they are added.3 a 0 1 f 5 2 e 10 d 7 7 c 7 6 i 14 9 h 9 8 b 6 4 g 12The array is as follows. [a] [b]
McMaster - CAS - 2c03
A3 =0 3 3 64 6 65 44 4 72 0 4 2 1 1 1 0 5 3 2 2 3 2 0 3 2 4 2 4 3 8 0 5 5 5 8 8 9 2 0 9 12 0 3 3 2 7 5 4 4 0 7 7 47 5 03 A4 =20 3 3 64 6 65 44 4 6 7 0 6 4 2 1 1 6 1 0 5 3 2 2 7 3 2 0 3 2 4 2 4 3 8 0 5 5 10 5 8 8 9 2 0 9 11 12 0 3 3 2
McMaster - CAS - 2c03
9v14 6 15 104v3817 4v54 8 96s5t152v212v43v69v14 6 12 104v3817 4v54 8 9 126s35 9 3t32v2v43v69v14 6 4 104v38 217 4v54 8 46s115 1 111 8 3t11v2v4v6No more augmenting paths exist, so we are done. Quest
McMaster - CAS - 2c03
CS2MD3. Sample solutions to the assignment 1. Total of this assignment is 132pts. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit
McMaster - CAS - 2c03
2.[11] Using only definition of O(f(n) proof that the following statements are true: 1.[2] 7000n2n/(n2 + 3) = O(2n) Let c=1, n0=7000. For all n 7000, 7000n2n/(n2 + 3) 7000n2n/(7000n + 3) 2n. 2.[3] 100n32n + 6n23n = O(4n) Let c=106, n0=16=24. First n3 = 23
McMaster - CAS - 2c03
For all n n0, n*log (3/2) log c, then (3/2)n c. Hence, 3n = (3/2)n * 2n c*2n. d.[2] log n + n1/2 = O(log n) For all c 0, take n0 = c4. For all n n0, log n + n1/2 log c + n1/4*n1/4 log c + c*n1/4 c*log n hold.4.[12] Consider lists of integers. The lexicog
McMaster - CAS - 2c03
p1 := FIRST(L1); p2 := FIRST(L2); while (p1 &lt;&gt; END(L1) and p2 &lt;&gt; END(L2) do begin x1 := RETRIEVE(p1, L1); x2 := RETRIEVE(p2, L2); if (x1 &lt; x2) then return(true) else if (x1 &gt; x2) then return(false) else begin p1 := NEXT(p1, L1); p1 := NEXT(p1, L1) end end
McMaster - CAS - 2c03
for j:=3005 to 2*n*n do begin C[i,j]:=0; for k:=n/5 to 3*n do C[i,j]:=C[i,j]*A[i,k]; for k:=n to n*n do C[i,j]:=C[i,j] + A[i,k]*B[k,j]; for k:=1 to n/2 do C[i,j]:=C[i,j]*A[i,k]; end end else begin C[i,j]:=A[i,j]; for k:=n*n/3 to n*n/2 do C[i,j]:=C[i,j]*A[
McMaster - CAS - 2c03
T1(n) = C + 2*T1 (n - 3) = (1+2)C +22T1 (n 3*2) = (1+2+22)C +23T1 (n - 3*3). = (1+2+22+2n/3-1)C +2n/3T1 (1) where m ~ logn/log3 = 2n/3*C + 2mC = O(2n/3) T2(n) = C + 2*T2 (n - 1) = (1+2)C +22T2 (n - 2) = (1+2+22)C +23T2 (n - 3). = (1+2+22+2(n-1)C +2nT1 (1)
McMaster - CAS - 2c03
while (p .next &lt;&gt; nil) do begin if (n mod 3 = 0) or (n mod 3 = 2) the begin p .next := p .next .next; n:= n+1;end p := p .next ; n:= n+1; end end The time complexity is O(n). b.[5] SHUFFLE(L1,L2). This procedure shuffles the list, the result has the appro
McMaster - CAS - 2c03
while (p .next &lt;&gt; nil) do begin tmp := p .next; p .next := p2 .next .next; tmp .next := L .next .next; L .next .next := tmp; p1 := p1 .next .next ; p2 .next := tmp2 ; end end The time complexity is O(n). d.[5] Assume that the list are doubly linked and re
McMaster - CAS - 2c03
begin L.last := (L.last - 1) div 3) + 1; for (n :=2 to L.last) do begin L.element[n] := L.element[3n-2] end end The time complexity is O(n). b.[5] SHUFFLE(L1,L2). This procedure shuffles the list, the result has the appropriate elements of the first list
McMaster - CAS - 2c03
L[p] := L[q]; L[q] := tmp; p := p + 1 ; q := q-1 end end The time complexity is O(n).8.[15] Using the operations given on pages 38-39 of Aho-Hopcroft-Ullman, write procedures to compute the functions from question 6. [5] procedure 3ONLY(var L: List;); va
McMaster - CAS - 2c03
var p,q: position; tmp: elementtype; begin if (FIRST(L)=END(L) or NEXT(FIRST(L),L)=END(L) or NEXT(NEXT(FIRST(L),L),L)=END(L) return; p := NEXT(FIRST(L),L); q := NEXT(p,L); while (q &lt;&gt; END(L) do begin INSERT(RETRIEVE(q,L), p, L); DELETE(NEXT(p,L),L); q :=
McMaster - CAS - 2c03
CS2MD3. Sample solutions to the assignment 2. Total of this assignment is 122pts. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit
McMaster - CAS - 2c03
Using find 2abbbabbaabbabaab a baabaabaababbabbbabba pass1 a b a pass2 a pass3 a pass4 aba pass5 a pass6 ab pass7 aba pass8 a pass9 abaab a a pass10 (a b a) a pass11 (a) b a a b a a b a b pass12 (a b a a b a) a b a b # 3 1 1 3 1 2 3 1 7 1 9 4 362[15]. A
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
U. Houston - PSYCH - 1300
Purdue - CNIT - 176
CIT 176 Exam 1 ReviewChapter 1: Your Need to Know Systems Development Life Cycle (SDLC)- process of creating or altering systems. The series of steps IS professionals follow when developing an IS. Unified Process- A modern SDLC. Under the SDLC, an IS is
Santa Barbara City - ECE - 210a
University of California, Santa BarbaraDepartment of Electrical &amp; Computer EngineeringECE 210a, Math 206a, CMPSC 211a, ME 210a, ChE 211a Matrix Analysis and Computation Fall 2009Homework 1.Problem 1. Find a basis for the following vector spaces: 1. Th
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213
New Mexico - ECE - 213