
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
A set of questions related to algorithms. It defines the stages of an algorithm, recurrence relation, and list of elements of a set. The questions include finding recursive and closed formulas for a sequence, writing algorithms to output the nth term of a sequence, counting the number of times a number appears in a list, and describing the relationship between input and output of an algorithm. suitable for students studying algorithms and data structures.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Work in groups or alone and use the time today to answer all of the questions below. You may use your books or notes from class, and do not turn in this assignment: it is yours to study for the exam next week. Recall that: Defn: An algorithm consists of three stages: input, procedure, and output. All arith- metic operations (+, −, ×, ÷) and comparisons (≤, <, =) must occur in the procedure stage. The complexity of the algorithm is the total number of arithmetic operations and/or comparisons used for the algorithm to run for an input in the worst case. Defn: A recurrence relation an = ran− 1 + san− 2 has solution
an =
c 1 xn 1 + c 2 xn 2 if x 1 6 = x 2 , c 1 xn 0 + c 2 nxn 0 if x 1 = x 2 = 0, where x 1 , x 2 are the roots of the characteristic polynomial x^2 − rx − s = (x − x 1 )(x − x 2 ) = 0, and c 1 , c 2 are unknown constants which are solved for using the initial conditions of the recursively defined sequence. Defn: A list of elements of a set A is an ordered n-tuple, or element of An^ = A︸ × A × · · · ×︷︷ A︸ n times