



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
The third exam for csci 270, focusing on recursion, algorithm efficiency, and trees. It includes multiple-choice questions about recursion, binary search, and tree concepts, as well as a recursive algorithm to calculate the sum of integers from 1 to n. Additionally, there are exercises to trace recursive function calls, calculate the total number of operations executed, and determine the complexity of algorithms.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




CSCI 270 Exam 3 Recurse, Alg Eff, Trees (2 Aug) Name _________________________ Summer 2005 60 points total
a) True False Recursion refers to the act of defining an object in terms of itself. b) True False A recursive definition must include a base (or anchor) case c) True False A recursive function can have more than one base or terminating case. d) True False Binary search has logarithmic complexity. e) True False Linear search is more efficient than binary search. f) True False Some exponential algorithms would take centuries to execute even with the fastest possible processor. g) True False In a tree, nodes with no outgoing arcs are called leaves. h) True False A binary search tree has no special ordering of the nodes in the tree. i) True False A binary search tree can degenerate to a list for some sequences of insertions into the tree. j) True False A node in a general tree can have only two children at most.
int F(char ch1, char ch2)
{
if (ch1 > ch2)
return 0;
if (ch1 + 1 == ch2)
return 1;
return F(ch1 + 1, ch2 – 1) + 2;
}
a) (1 Point) What is the final value returned by the initial call to F _____ 6 ______
b) (1 Point) How many base cases does the recursive function F have ____ 2 ______
For Sum(n): base case: Sum(n) returns ______ 1 (or 0) _______ for n = _____ 1 (or 0) _______
general case: Sum(n) returns ____ n + Sum(n-1) _____ for n > ___ 1 (or 0) ________
c. yes no The function call Func (12); results in infinite recursion.
a. O ( __ 2 n __ ) 2 n^ + 10n^2 + 15
b. O ( __ n ___ ) (5284n - 245) / 35
c. O ( __ n ___ ) 14log 2 n + 2n
d. O ( __ n^4 ___ ) 63n + 25n^2 + 2n^3 + n^4 + 91
n^2 , log n, 2n, n log n, n^3 , n
least efficient 2 n^ n^3 n^2 n log n n log n most efficient
b) Perform inorder, preorder and postorder traversals of the tree that resulted from the insertion of the letters in a). Show the sequence of letters that results in each case:
inorder (L,V,R) : E H O S U
preorder (V, L, R) : H E O U S
postorder (L, R, V) : E S U O H