


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Discrete Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2006;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Find a recursive expression for the nth triangular number. What is the value of the 10th triangular number?
b. The first four pentagonal numbers are 1, 5, 12, and 22. (3 points)
Find a recursive expression for the nth pentagonal number. What is the value of the 7th pentagonal number?
nonzero real number and n is a nonnegative integer. Format 1:
Format 2:
Choose one of these formats to write pseudocode for the following questions.
b. Devise a recursive algorithm to evaluate the nth term of the following sequence S:
procedure power(a: nonzero real number, n: nonnegative integer)
algorithm power(nonzero real number a; nonnegative integer n) if n = 0 then
else
end if end algorithm power
matrix. Assume that the value of A[i, j] can be accessed in constant time. What does the following algorithm do? Give a tight upper bound for the running time of this algorithm. (3 points)
d. (Bonus points for this one!! Your total homework score will not be hurt if you skip this problem.) S is an array of integers {1, 2, 3, โฆ, n} (each number appears in S exactly once). Subroutine swap(S[a], S[b]) exchanges array items indexed by a and b. Each swap takes constant time. What does the following algorithm do? What is the worst case time complexity? Why? (4 points)
algorithm X(array S, nonnegative integer n) for i = 1 to n -1 do
swap(S[i], S[S[i]]) end while end for end algorithm X
algorithm MatrixSum(matrix A) sum := 0 for k = 1 to n do for j = k to n do sum := sum + A[j, k] end for end for return sum end algorithm MatrixSum