Docsity

Questions on Algorithm and Systems Analysis - Final Exam | CSE 21, Exams of Computer Science

Toggle sidebar
bg1
0
Signature ___________________
Name ______________________
Student ID __________________
Final
CSE 21
Spring 2010
Page 1 ___________ (30 points)
Page 2 ___________ (18 points)
Page 3 ___________ (11 points)
Page 4 ___________ (12 points)
Page 5 ___________ (13 points)
Page 6 ___________ (34 points)
Page 7 ___________ (10 points)
Page 8 ___________ (11 points)
Page 9 ___________ (5 points)
SubTotal ___________ (144 points = 100%)
Page 10 ___________ (10 points) Extra Credit (7%)
Total ___________
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Questions on Algorithm and Systems Analysis - Final Exam | CSE 21 and more Exams Computer Science in PDF only on Docsity!

Signature ___________________ Name ______________________

Student ID __________________

Final CSE 21 Spring 2010

Page 1 ___________ (30 points)

Page 2 ___________ (18 points)

Page 3 ___________ (11 points)

Page 4 ___________ (12 points)

Page 5 ___________ (13 points)

Page 6 ___________ (34 points)

Page 7 ___________ (10 points)

Page 8 ___________ (11 points)

Page 9 ___________ (5 points)

SubTotal ___________ (144 points = 100%)

Page 10 ___________ (10 points) Extra Credit (7%)

Total ___________

Calculate the first 6 terms for the triangular numbers (n = 1, n = 2, n = 3, ... , n = 6). Then to the right calculate the sequence of differences between these terms. 1st^ triangular number is 1. n Sequences of differences 1 _______________________ = _____


2 _______________________ = _____ _____


3 _______________________ = _____ _____


4 _______________________ = _____ _____


5 _______________________ = _____ _____


6 _______________________ = _____

Write the recurrence relation for the triangular numbers T(n).

___________________________ if n ________ T(n) = ___________________________ if n ________

Based on the sequence of differences (above) what is a good guess for the closed-form solution to the recurrence relation above?

f(n) = ____________

Why?:

Verify this with a proof by induction. Prove T(n) = f(n) for all n ___________.

Proof (Induction on n):

_________________: If n = ____, the recurrence relation says T(__) = ____,

and the closed-form solution says f() = ______ = ____, so T() = f(__).

_________________: Suppose as inductive hypothesis that T(k-1) = ____________________ for some k > ___.

_________________: Using the recurrence relation, T(k) = ___________________________, by 2nd^ part of RR

= ___________________________, by IHOP

= ___________________________

= ___________________________

So, by induction, T(n) = ____________ for all n >= 1 (as ______________).

A) 4n – 2n B) n^3 – n C) n^4 – n^2 + 2 D) (n^2 + n)/2 E) 2n + n F) 2n^ + n

etc.

n = 1 n = 2 n = 3 n = 4

How many distinct memory locations (binary addresses) can be addressed with an address register of length n?


How many different strings of length 10 can be formed from a set of 26 refrigerator magnets A-Z?


How many strings of length 7 can be formed from a 10-symbol alphabet where no 2 adjacent symbols are the same?


How many 5-digit zip codes are possible? Zip codes can contain all zeros.


How many 5-digit zip codes contain only even digits? 0 is an even number.


How many 5-digit zip codes have at least one odd digit?


How many 5-digit zip codes have all different digits (no duplicates)?


How many 5-digit zip codes start with an even digit and end with an even digit?


How many 5-digit zip codes can be formed with at least one duplicate digit (for example, 00489, 58868, and 33997)?


How many (nonempty) strings of at most length 3 can be formed from a 26-symbol alphabet?


How many different strings can be made from the letters in SENSELESSNESS, using all the letters?

_________________________________________

What is the value of P(7,2)? Your answer should be an actual number for this one.


What is the value of C(8,3)? Your answer should be an actual number for this one.


How many ways are there to arrange the letters in the word CRAFTSMEN?


Which of the following evaluate to the same value? List the letters of the expressions that are the same. For example, (A & B) and (C & D & E). List all combinations that are equal. There may be more than one.

A) C(n,n) C) C(n,0) E) C(n,1) B) C(n,n-1) D) C(n,k) F) C(n,n-k)


An urn contains 8 balls numbered 0-7. Four balls are drawn from the urn in sequence, and the numbers on the balls are recorded. How many ways are there to do this, if

each ball is replaced before the next one is drawn? ___________________________________

when each ball is drawn it is not replaced? ___________________________________

all four balls are drawn at once (one handful of four balls) instead of in sequence? ________________________

How many solutions (using only non-negative integers) are there to the following equation?

x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 = 20 _____________________________________________

How many different ways are there to distribute 14 identical bones among 4 different dogs? (No dog can get a negative number of bones.)

_____________________________________________

How many different ways are there to rearrange the 10-bit binary string (bit pattern) 1001110000?

_____________________________________________

Rank the different time complexity classes from smallest to largest according to how fast they grow as their input n grows large. Fill in the blanks with the appropriate letter.

_______ smallest/slowest growing (faster algorithms)






_______ fastest growing (slower algorithms)

Now match the time complexity class names in the box above with their big-Oh equivalent.

_______ O( n! ) _______ O( 2n^ )

_______ O( n ) _______ O( n^2 )

_______ O( 1 ) _______ O( log 2 n )

_______ O( n log 2 n )

Match the algorithms with their recurrence relations and their run time complexities. Use the letters and numbers from the boxes to the right.

Recurrence Time Algorithm Relation Complexity

Selection Sort ______ ______

Binary Tree Traversal ______ ______

Binary Search ______ ______

Sequential Search ______ ______

Fibonacci sequence ______ ______ (recursive) Merge Sort ______ ______

Towers of Hanoi ______ ______

Bubble Sort ______ ______

Recursive FindMax ______ ______

Array access ______ ______

A) polynomial B) linear C) exponential D) logarithmic E) factorial F) n log 2 n G) constant

A) T(n) = O(1) B) T(n) = T(n/2) + O(1) C) T(n) = T(n-1) + O(1) D) T(n) = 2 T(n/2) + O(1) E) T(n) = 2 T(n/2) + O(n) F) T(n) = T(n-1) + O(n) G) T(n) = 2 T(n-1) + O(1) H) T(n) = T(n-1) + T(n-2)

  1. O( n! )
  2. O( n )
  3. O( 1 )
  4. O( n log 2 n )
  5. O( 2n^ )
  6. O( n^2 )
  7. O( log 2 n )

Given the following recurrence relation, write the actual body of code for the function T(n). Just write the code for the base case and recursive case (do not worry about anything else).

1 if n = 1 T(n) = T(n – 1) + 2n – 1 if n > 1

Given the binary tree to the right

Specify the output for the following traversals

Preorder traversal: ____ ____ ____ ____ ____ ____ ____ ____ ____

Inorder traversal: ____ ____ ____ ____ ____ ____ ____ ____ ____

Postorder traversal: ____ ____ ____ ____ ____ ____ ____ ____ ____

Construct a minimum spanning tree from the following network. Use the grayed network on the right to construct your msp. Hint: 9 vertices so msp should have 8 edges.

What is the total weight of the minimum spanning tree? _______ Is there more than one minimum spanning tree in this graph (yes or no)? ______

long long int T( int n ) { // Assume n > 0





}

w

a

b

v 0 w

a v 0 w

b

a v 0

b

a

w

a v 0

b

a

a

v 0 w

b b

b

v 0 w

a a

v 0 is the start node. w is a terminal node. A node labeled with both v 0 and w is both a start and terminal node.

A) B)

C) D)

E) F)

Which finite state automaton correctly recognizes words of the language a(ba)n^ for n ≥ 0? _____

Which finite state automaton correctly recognizes words of the language (ab)n^ for n ≥ 0? _____

Which finite state automaton correctly recognizes words of the language abna for n ≥ 1? _____

Which of the following is another way of specifying

(ab)n^ for n ≥ 0 using regular expression metacharacters? _____

A) (ab)^ B) (ab)+^ C) (ab)?^ D) ab*^ E) a+b+^ F) [ab]{n} G) a?b?

On the last day of class I quickly demo'ed a simple context-free grammar that recognizes a language to draw circles in PostScript. What was the final graphic drawn (what did it look like)?


Extra Credit

Match the person to what the person is famous for. (1/2 point each)

_____ Known as the father of C.

_____ Known as the father of algorithms.

_____ Known as the father of Pascal.

_____ Computing's highest honor (Nobel Prize of computing) named after.

_____ Helped popularize the term "debugging."

_____ One of the letters in BNF.

_____ Shortest-Path algorithm.

_____ Co-developer of the Go programming language from Google.

_____ Influential in early regular expression work used in grep, awk, and most editors (not Brian Kernighan).

_____ Invented Merge sort algorithm.

_____ Co-authored Concrete Mathematics (a blend of CONtinuous and disCRETE math) with Donald Knuth.

_____ Invented Quicksort algorithm.

_____ Known as the father of Fortran.

_____ Has a well-known conference primarily for women in computing named after.

_____ The 'K' of AWK and the 'K' of K&R C.

_____ A theoretical device representing a computing machine to understand limits of computation named after.

_____ Developed Unix along with Kernighan and Thompson.

_____ Invented the semaphore concept.

_____ Known as the father of the modern computer.

_____ At one time his number was known as the largest number ever used in a serious mathematical proof.

A) Edsger Dijkstra B) Donald Knuth C) Alan Turing D) Grace Hopper E) John von Neumann F) Ken Thompson G) Ron Graham H) Dennis Ritchie I) Brian Kernighan J) Niklaus Wirth K) John Backus L) C.A.R. Hoare

Scratch Paper