Final CSE 21 Spring 2010

Signature ___________________ Name ______________________ Student ID __________________ Final CSE 21 Spring 2010 Page 1 ___________ (30 points) Pa...
Author: Guest
7 downloads 0 Views 169KB Size
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

___________

0

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=1 * n Sequences of differences n=2 ** 1 _______________________ = _____ *** n=3 _____ **** n=4 2 _______________________ = _____ _____ _____ etc. 3 _______________________ = _____ _____ _____ 4 _______________________ = _____ _____ _____ 5 _______________________ = _____ _____ _____ 6 _______________________ = _____

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

T(n) =

{

___________________________

if 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? A) 4n – 2n B) n3 – n C) n4 – n2 + 2 2 f(n) = ____________ D) (n + n)/2 E) 2n + n F) 2n + 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 ______________). 1

What are the four general decompositions of recursive algorithms discussed in class? _______________________________

_______________________________

_______________________________

_______________________________

Which of the above general recursive decompositions are most appropriate for the following algorithms: Factorial

____________________________

Binary Search _______________________________

Palindrome Check

____________________________

Fractal graphic _______________________________ output (for example, Koch snowflake or tree fractal)

List/String reversal ________________________ moving last element to front, recurse on rest (sa)R → a(s)R

List/String reversal ____________________________ exchanging first and last elements, recurse on rest

Which is true about proof by induction on k (IHOP on k and IS on k+1) vs proof by induction on k-1 (IHOP on k-1 and IS on k)? _____ A) Both the same B) first (on k) uses weak induction and second (on k-1) uses strong induction C) Different proofs (not same) D) first (on k) uses strong induction and second (on k-1) uses weak induction

Which of the following would require the use of strong induction and which would require the use of weak induction in a proof? A) weak induction B) strong induction _____ T(n) = T(n-1) + T(n-3)

_____ T(n) = T(n-1) + T(n-2)

_____ T(n) = T(n-1) + 2n * n

You may want to draw Venn diagrams (on your scratch paper) to help you answer the following questions. Professor Sally Mander has 25 students in her Data Structures class, 17 students in her Discrete Math class, and 13 students in her Compilers class. Assuming that there are no students who are taking more than one class from her, how many students does Sally have? ______ Assuming there are 4 students who take both Data Structures and Discrete Math at the same time and 4 students who take both Discrete Math and Compilers at the same and 2 students who take both Data Structures and Compilers at the same time and no student takes all three classes at the same time, how many students does Sally have? ______ What if the above question was modified to include 2 students who take all three classes at the same time. How many students does Sally have? ______

Mike has 6 different bikes and 3 different cars. He plans to ride a bike to and from work, and then take one of his cars to go out at night. How many different ways can he do this? ______ 2

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?

_________________________________________ 3

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) B) C(n,n-1)

C) C(n,0) D) C(n,k)

E) C(n,1) 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?

x1 + x2 + x3 + x4 + x5 + x6 + x7 = 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?

_____________________________________________ 4

In a class of 36, there will always be a group of how many who were born on the same day of the week? ______________________________________________

A small college offers 250 different classes. No two classes can meet at the same time in the same room. There are twelve different time slots at which classes can occur. What is the minimum number of classrooms needed to accommodate all the classes? ______________________________________________

What is the probability of rolling a 7 (sum of two fair 6-sided dice will be 7)? ______________________________________________ What is the probability of rolling a 4 or more (sum of two fair 6-sided dice will be 4 or more)? ______________________________________________

Consider the following algorithm: char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for ( int i = 0; i < m; ++i ) { for ( int j = 0; j < n; ++j ) { cout 0 ______________________________________ ______________________________________ ______________________________________ ______________________________________ }

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)? ______ 7

According to the Lower Bound Theorem, the best (most efficient) worst case complexity for comparison-based sort is _______________. According to the Lower Bound Theorem, the best (most efficient) worst case complexity for comparison-based search is _______________. In a collection of 25 coins, 1 coin is counterfeit and weighs more than the genuine coins. Find a good lower bound on the number of balance scale weighings needed to identify the fake coin. _______________________ Instead of a balance scale in the above question, you had a device that only tells whether or not two quantities weigh the same. In other words, the device has only two positions: "same" or "different." Find a good lower bound on the number of time you need to use this device to identify the fake coin out of 25 coins. _______________________

_____ is the collection of all problems that can be solved with an algorithm whose complexity is, at most, polynomial. _____ is the collection of all problems whose solutions can be checked (but not necessarily solved) in polynomial time.

Given the initial order of ints in an array as: 8, 6, 7, 9, 3, 0, 5 what is the order of the elements after 3 iterations of the selection sort algorithm covered in class and one of the HW exercises? ____ ____ ____ ____ ____ ____ ____

Which is more powerful: a finite state automaton/regular expression or a context-free grammar? __________________________________ S is the start symbol. a and b are a terminal symbols. 1)

S → Sab S → ab

3)

S → aSb S → ab

5)

S → abS S → ba

2)

S → aSa | bSb S → a|b| ε

4)

S → aSbS S → a|b

6)

S → aS S→b

Which context-free grammar correctly recognizes words of the language (ab)n for n ≥ 1? _____ Which context-free grammar correctly recognizes palindromes? _____ Which context-free grammar correctly recognizes words of the language anbn for n ≥ 1? _____

8

v0 is the start node. w is a terminal node. A node labeled with both v0 and w is both a start and terminal node. b b A)

B)

a

a v0

v0

w

w b

a C)

D)

b

a

a v0 w

w

v0

b

a E)

F) a

a

b

v0

b

a

v0

w

w

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) a*b*

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)? ___________________________________________

9

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.

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

_____ 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.

10

Scratch Paper

11

Scratch Paper

12