CS141 Course Sample Questions in Computer Science, Study notes of Computer Science

A set of sample questions for a computer science course, covering topics such as big o notation, recurrence equations, data structures, expression trees, stacks, sorting algorithms, and recurrence equation analysis.

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-7xm-1
koofers-user-7xm-1 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS141 Sample Questions
1. Show that (2n + 1)5 is O (n5).
2. Consider the following recurrence equations;
3 if n = 1
T(n) =
T (n-1) + n otherwise,
Show, by induction, that T(n) = n(n + 1) / 2.
3. Describe, using pseudo code, implementations of the methods insertBefore (p, e),
insertFirst (e), and insertLast (e) of the list ADT, assuming the list is implemented
using a doubly linked list.
4. Draw an expression tree that has four external nodes, storing the numbers 1, 5, 6,
and 7 (with each number stored one per external node but not necessarily in this
order), and has three internal nodes, each storing an operation from the set {+, -,
x, /} of binary arithmetic operators, so that the value of the root is 21. The
operators are assumed to return rational numbers (not integers), and an operator
may be used more than once (but we only store one operator per internal node).
5. Describe how to implement the stack ADT using two queues. What is the running
time of the push () and pop () methods in this case?
6. Give a pseudo-code description of a variation of the merge-sort algorithm that
operates on an array instead of a general sequence. (Hint: Use an auxiliary array
as a buffer.)
7. Show that the running time of the merge-sort algorithm on an n-element sequence
is O (n log n), even when n is not a power of 2.
8. Characterize each of the following recurrence equations using the Master Method.
(You can find the rules for Master Method in the book or slides)
a) T(n) = 4T(n / 2) + n
b) T(n) = 16T(n / 2) + log n
c) T(n) = 7T(n / 3) + n2
d) T(n) = 9T(n / 3) + n3log n
9. What is the best way to multiply a chain of matrices with dimensions that are 10 x
5, 5 x 2, 2 x 20, and 20 x 10? Show your work.

Partial preview of the text

Download CS141 Course Sample Questions in Computer Science and more Study notes Computer Science in PDF only on Docsity!

CS141 Sample Questions

  1. Show that (2n + 1)^5 is O (n^5 ).
  2. Consider the following recurrence equations; 3 if n = 1 T(n) = T (n-1) + n otherwise, Show, by induction, that T(n) = n(n + 1) / 2.
  3. Describe, using pseudo code, implementations of the methods insertBefore (p, e), insertFirst (e), and insertLast (e) of the list ADT, assuming the list is implemented using a doubly linked list.
  4. Draw an expression tree that has four external nodes, storing the numbers 1, 5, 6, and 7 (with each number stored one per external node but not necessarily in this order), and has three internal nodes, each storing an operation from the set {+, -, x, /} of binary arithmetic operators, so that the value of the root is 21. The operators are assumed to return rational numbers (not integers), and an operator may be used more than once (but we only store one operator per internal node).
  5. Describe how to implement the stack ADT using two queues. What is the running time of the push () and pop () methods in this case?
  6. Give a pseudo-code description of a variation of the merge-sort algorithm that operates on an array instead of a general sequence. ( Hint: Use an auxiliary array as a buffer.)
  7. Show that the running time of the merge-sort algorithm on an n-element sequence is O (n log n), even when n is not a power of 2.
  8. Characterize each of the following recurrence equations using the Master Method. (You can find the rules for Master Method in the book or slides) a) T(n) = 4T(n / 2) + n b) T(n) = 16T(n / 2) + log n c) T(n) = 7T(n / 3) + n^2 d) T(n) = 9T(n / 3) + n^3 log n
  9. What is the best way to multiply a chain of matrices with dimensions that are 10 x 5, 5 x 2, 2 x 20, and 20 x 10? Show your work.