Upcoming SlideShare
×

# Q

2,588 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
2,588
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
79
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Q

1. 1. Questions and exercises for Review Note. Questions/Exercises in green numbers apply to the midterm 1. What steps should one take when solving a problem using a computer? A: first to construct an exact model in terms of which we can express allowed solutions. Once we have a suitable mathematical model, we can specify a solution in terms of that model 2. Explain some issues when dealing with the representation of real world objects in a computer program. A: how real world objects are modeled as mathematical entities, the set of operations that we define over these mathematical entities, how these entities are stored in a computer's memory (e.g. how they are aggregated as fields in records and how these records are arranged in memory, perhaps as arrays or as linked structures), and the algorithms that are used to perform these operations. 3. Explain the notions: model of computation; computational problem; problem instance; algorithm; and program A: Model of Computation: An abstract sequential computer, called a Random Access Machine or RAM. Uniform cost model.  Computational Problem: A specification in general terms of inputs and outputs and the desired input/output relationship.  Problem Instance: A particular collection of inputs for a given problem.  Algorithm: A method of solving a problem which can be implemented on a computer. Usually there are many algorithms for a given problem.  Program: Particular implementation of some algorithm. 4. Show the algorithm design algorithm A: 5. What might be the resources considered in algorithm analysis? A: • running time • memory usage (space) • number of accesses to secondary storage • number of basic arithmetic operations • network traffic 6. Explain the big-oh class of growth.
2. 2. A: O(g) is the set of functions that grow no faster than g. g(n) describes the worst case behavior of an algorithm that is O(g)  Examples: n lg n + n = O(n2);;;;; lgk n = O(n) for all k ∈ N 7. Explain the big-omega class of growth. A: Ω (g(n)): class of functions f(n) that grow at least as fast as g(n)  g(n) describes the best case behavior of an algorithm that is Ω(g)  Example: a n2 + b n + c = Ω(n) provided a > 0 8. Explain the big-theta class of growth. A: Θ (g(n)): class of functions f(n) that grow at same rate as g(n) Example:n2 / 2 - 3 n = Θ(n2) We have to determine c1 > 0,c2 > 0, n0 ∈ N such that:c2 n2 ≤ n2 / 2 - 3 n ≤ c1 n2 for any n > n0. Dividing by n2 yields:c2 ≤ 1 / 2 – 3 / n ≤ c1 This is satisfied for c2 = 1 / 14, c1 = 1 / 2, n0 = 7. 9. What are the steps in mathematical analysis of nonrecursive algorithms? A: • Decide on parameter n indicating input size • Identify algorithm’s basic operation • Determine worst, average, and best case for input of size n • Set up summation for C(n) reflecting algorithm’s loop structure • Simplify summation using standard formulas 10.What are the steps in mathematical analysis of recursive algorithms? A: Decide on parameter n indicating input size • Identify algorithm’s basic operation • Determine worst, average, and best case for input of size n • Set up a recurrence relation and initial condition(s) for C(n) − the number of times the basic operation will be executed for an input of size n (alternatively count recursive calls). • Solve the recurrence to obtain a closed form or estimate the order of magnitude of the solution 11.From lowest to highest, what is the correct order of the complexities O(n2 ), O(3n), O(2n), O(n2 lg n), O(1), O(n lg n), O(n3 ), O(n!), O(lg n), O(n)? A: O(1),O(logn),O(n),O(2n),O(3n),O(nlogn),O(n*n lgn ),O(n*n),O(n*n*n),O(n!) 12.What are the complexities of T1(n) = 3n lg n + lg n; T2(n) = 2n + n3 + 25; and T3(n, k) = k + n, where k less-than or equal to n? From lowest to highest, what is the correct order of the resulting complexities? A: O(t1)=nlogn;;;;;O(t2)=2la put n;;;;;;O(t3)=n t3,t1,t2 13.Suppose we have written a procedure to add m square matrices of size n × n. If adding two square matrices requires O (n2 ) running time, what is the complexity of this procedure in terms of m and n? A: O((m-1)n 2 ) de fapt ii O(n*n),adica de n patrat 14.Suppose we have two algorithms to solve the same problem. One runs in time T1(n) = 400n, whereas the other runs in time T2(n) = n2 . What are the complexities of these two algorithms? For what values of n might we consider using the algorithm with the higher complexity?