COT 3.1,3.2,3.3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Arrange the steps in order to show that 4x^5 + 16x^2 log x is O(x^5)

1.

Match the functions in the left column with the smallest big-O estimate in the right column. 1. log n! 2.n! 3.1 + 2 + ... + n 4.log n

1. O(n log n) 2. O(n^n) 3. O(n^2) 4. O(n)

Rank the following functions so that each function is big-O of the one above it, that is rank them in descending order.

1. n! 2. 2^n 3. n^2 4. n log n 5 n 6. log n

Which are the following problems are known to be tractable

Searching for an element in a list (it is in class P because linear search solves this problem, and a linear search is O(n). Sorting a list (It is in class P because inserting sort solves this problems and is O(n^2)

Which of these statements is true about the time complexity of a linear search?

The algorithm requires no more than O(n) comparisons for all input of size n elements -Certainly checking each element of the list is sufficient to determine whether the search element is present or not The algorithm may require Omega(n) comparisons for some input of size n -The search term could be the last element, in which case n comparisons are required.

Which are these are true?

The worst-case complexity of insertion sort is O(n^2) comparisons The most efficient comparison sorting algorithms can sort n items using O(n log n) comparisons. The worse-case complexity of bubble sort is O(n^2) comparisons.

Let f and g be functions from the set of real numbers to the set of real numbers, then f(x) is O(g(x)) if there are constants C and K such that

|f(x)| is less than or equal to C|g(x)| whenever x > k

Match the function with the best big-O estimate 1. (x^2 + 1)log(x^2 + 1) 2.(3x^2 + (log x)^3)(x + (log x)^2) 3.((log x)^2+1)(x log x+1) 4.(x + (log x)^4)(x + (log x)^3)

1. O(x^2 log x) 2. O(x^3) 3. O(x(log x)^3) 4. O(x^2)

An analysis of the number of operations required to solve a problem of a particular size involves the --- --- of the algorithm. An analysis of the computer memory required involves the --- --- of the algorithm.

1. time complexity 2. space complexity.

Find the number of additions and multiplications of integers, required to multiply two 3 x 3 matrices with integer entries

18 additions and 27 multiplications There are 9 entries in the product of the two matrices. To find each entry, requires a total of 3 multiplications and 2 additions, hence, a total of 27 multiplications and 18 additions.

Use bubble sort to sort 4, 3, 5, 2, 6, showing the list obtained at each step

After the first pass 3, 4, 2, 5, 6 After the second pass 3, 2, 4, 5, 6 After the third pass 2, 3, 4, 5, 6 After the fourth pass 2, 3, 4, 5, 6 -This is the way Algorithm 4 operates on the given input

Which pair of witnesses can be used to show that 10x is O(x^2)

C = 10 and k = 1 C = 1 and k = 10 C = 15 and k = 10

What steps need to be done to show that the algorithm for finding the maximum element in a finite sequence is correct?

We must show that when the algorithm terminates, the value of the variable max equals the maximum term of the sequence. (This is required for the correctness property)

Which of the following are correct statements?

f(n) is O(n^2) and f(n) = 2n^2 + 8 log n is O(n^2) -Because 0 < 8 log n less than or equal to 8n^2, it is easy to establish that f(n) is O(n^2) and Omega(n^2)

Which of these inequalities correctly completes this definition? If f and g are functions from the set of integers or the set of real numbers to the set of real numbers, then f(x) is Omega(g(x)) if there are positive constants C and K such that ---- whenever x > k

|f(x)| (greater or equal to) C|g(x)|

List these functions so that each function in the list is big-O of the function below it.

1. 1,000,00 2. (log x)^2 3. 107x + 108 4. x^3 + x^2 + 17 5. 2^x 6. 3^x

Examine the statements below 1. f(x) = 40x^3 is O(x^4) 2. f(x) = 1 is O(x) 3. f(x) = 17x^2 is O(16x^2)

1. 40x^3 (Less than or equal to) 40x^4 for x >1 2. 1 (less than or equal to) x for x > 1, so c = 1 and k = 1 are witnesses. 3. 17x^2 (less than or equal to) 2 * 16x^2 = 32x^2 for x > 1

Match the terminology on the left with the definition on the right. 1. Intractable 2. Tractable 3. Solvable 4. Unsolvable

1. A problem that cannot be solved using an algorithm with worst-case polynomial time 2. A problem that can be solved using an algorithm with worst-case polynomial time complexity 3. An algorithm exists for finding an answer to all instances of a problem 4. There is no algorithm for finding answers to all instances of the problem

Put the following steps in order to perform a worst-case analysis of bubble sort.

1. Bubble sort makes makes n - 1 passes through the list 2. On the ith pass through the list, it makes n - i comparisons 3. The total number of comparisons is (n-1) + (n-2) +...+ 2 + 1 = (n-1)n/2 4. Hence, the number of comparisons is (n-1)n/2, and bubble sort is O(n^2)

Put the following steps in order for determining the time complexity of the algorithm for finding the maximum element in a sequence of integers. Use the number of comparisons as a measure of time complexity

1. Each time the "for" loop is executed, one comparison is needed to determine whether i > n. This amounts to n - 1 comparisons. 2. Each time the "if" statement is executed, one comparison is needed to test whether man < ai. This amounts to n - 1 comparisons. 3. One more comparison is used to exit the loop when i = n + 1. 4. the total number of comparisons is 2(n-1) + 1 = 2n -1 5. Since f(n) = 2n - 1, the algorithm is O(n)

Match the algorithm with a big O estimate of its worst-case complexity 1. Locating an item in an unordered list by examining the items one by one 2. Locating an item in an ordered list by successively splitting the list in half and comparing the element to the middle element 3. Print out all the bit strings of length n 4. Print out all ordered pairs of a set with n elements

1. O(n) -This is a linear search; its complexity is studied in the example on the time complexity of the algorithm for finding the maximum element in a finite sequence. 2. O(log n) -This is a binary search; its complexity is studied in the example on the time complexity of the binary search algorithm. 3. O(2^n) -There are two possible values for each position. Since there are n positions, the number of bit strings is 2^n 4. O(n^2) -An ordered pair has two elements and there are n ways to pick each element. Hence, there are n*n = n^2 ordered pairs.

Match each sequence with the position of its first term that is out of increasing order. 1. 1 5 78 99 101 202 400 2. 5 2 7 90 85 80 72 3. 5 6 9 10 14 21 20 4. 3 7 10 9 8 14 17 5. 5 77 25 45 22 94 58 99

1. Sequence is in increasing order -Each term is greater than the one before it. 2. Second position -2 is less than 5. 3. Seventh position -The first six terms are increasing order, but the seventh is less than the sixth 4. Fourth position -The first three terms are in increasing order, but the fourth term is less than the third. 5. Third position -The first two are in increasing order, but the third term is less than the second.

Order the following steps of a trace of binary search algorithm used to search 13 in the list 10, 11, 12, 13, 14.

1. Set i to 1 and j to 5 2. Compare 1 to 5 and set m to 3 3. Compare 13 to 12 and set i to 4 4. Compare 4 to 5 and set m to 4 5. Compare 13 to 13 and set j to 4 6. Compare 4 to 4. Then compare 13 to 13, set location to 4, and report that 13 is at location 4

Match the algorithms described in pseudocode on the left with the description of what it does on the right. 1. Procedure A(a1, a2, ..., a(n): integers) x=a1 for i = 2 to n if x < a(i) then x = a(i) return x 2. Procedure B(a1, a2, ..., a(n): integers) x=a1 for i = 2 to n if x > a(i) then x = a(i) return x 3. Procedure C(a1, a2, ..., a(n): integers) x=a1 for i = 2 to n x = x + a(i) return x 4. Procedure D(a1, a2,... , a(n): integers) x=a1 for i = 2 to n if x = x + ai return x/n

1. The algorithm finds the maximum value in the input sequence. -Note that if x < a(i), then x is assigned the value a(i). Therefore, at the end of the loop, x contains the maximum value of those in the sequence. 2. This algorithm finds the minimum value in the input sequence. -Note that if x > a(i), then x is assigned the value a(i). Therefore, at the end of the loop, x contains the minimum value of those in the sequence. 3. This algorithm finds the sum of all of the integers in the input sequence. -Every integer in the sequence is added to the variable x. After the "for" loop has executed, x is returned. 4. This algorithm finds the average of the integers in the input sequence. -Every integer in the sequence is added to the variable x. After the "for" loop has executed, x/n is returned.

Arrange these steps in order to show that n^2 is O(n^3)

1. To show that n^2 is O(n^3), we must find constants C and k such that n^2 is less than or equal to Cn^3 whenever n > k 2. To find a C and k that will work, we note that for all n > 1, n^2 is less than or equal to n^3. 3. Hence, we can take C = 1 and k = 1. These are constants C and k such that n^2 is less than equal to Cn^3 whenever n > k. 4. Therefore, n^2 is O(n^3)

The number of character comparisons used by the naive string matcher to look for the pattern of in the text love is ---

4 -At shift 0, "I" is compared to o. At shift 1, o is compared to o and v is compared to f. At shift 2, v is compared to o.

The number of character comparisons used by the naive string matcher to look for the pattern of in the text love is 4

4 At shift 0, l is compared to o. At shift 1, o is compared to o and v is compared to f. At shift 2, v is compared to o.

A problem that is solvable using an algorithm with polynomial worst-case complexity is called ----. Problems that cannot be solved using an algorithm with worst-case polynomial time complexity are called ----. Problems for which it can be shown that no algorithm exists for solving them are called ----.

Tractable (A problem that is solvable using an algorithm with polynomial worst-case complexity is called tractable) intractable (problems that cannot be solved using algorithm with worst-case polynomial time complexity are called intractable) unsolvable (problems for which it can be shown that no algorithm exits for solving for solving them are called unsolvable

Which of these statements is true about worst-case complexity

Worst-case analysis estimates how many operations an algorithm needs to guarantee that it can find the solution -Worst-case analysis gives an upper bound.

What change is made by the cashier's algorithm for 40 cents using quarters, dimes, and pennies(but no nickels)?

1 quarter, 1 dime, and 5 pennies The algorithm adds 1 quarter, leaving 15 cents. Then it adds 1 dime, leaving 5 cents. Then it adds 5 pennies.

Arrange these steps of the linear search for finding location of an element x in a list a1, a2 ,... , a(n)

1. Compare x and a1 2. When = a1, the solution is 1 (the index of the term a). 3. Otherwise, when x does not = a1, and the sequence does not end with a 1, compare x with a2 4. If x = a2, the solution is the location of a2 5. when x does not = a2, and the sequence does not end, compare x with a3, continue comparing x successively with each term of the list until a match is found. 6. If the entire list has been searched without locating x, when the solution is 0.

Arrange the steps of the binary search algorithm, to search for the integer x in the list a1, a2, ..., a(n), where a1 < a2 < ... < a(n)

1. Compare x with the middle term a(m) of the list 2. If x > a(m), then the search for x is restricted to the second half of the list which is a(m+1) , a(m+2), ..., a(m) 3. Otherwise if x is not greater than a(m), then the search for x is restricted to the first half of the list, which is a1, a2, ..., a(m) 4. Using the same procedure, restrict the search to the first or second half of the remaining list. 5. The procedure is repeated until a list with one term is obtained. This term is compared with the search term.

Which of these considerations are important reasons for studying the computational complexity of algorithm?

1. We need to estimate the time required to solve a problem of a specific size. -The results of computational complexity can be used to estimate the amount of time required 2. We want to know which of several possible algorithms to use. -The results of computational complexity may tell us that particular algorithm will not work well for problems above a certain size. 3. We want to know how much memory will be required. -The results of computational complexity can be used to estimate the amount of memory required.

Match functions of the same order 1. x^2 + x^2 log x 2. 3^x(x^2+1) 3. (x^3 + x^2)(2^x +3)

1. x^2 log(x^3 + 1) 2. (2^x + 3^x)(8x^2 + x) 3. 2^x(x^3 + x(log x)^2)

Arrange these steps in order to show that n^3 is not O(n^2)

1.To show that n^3 is not O(n^2), we first assume that it is, that is that n^3 is O(n^2) 2.Then, there are constants C and k such that n^3 is less than or equal to Cn^2 whenever n > k. 3. But then, it follows that n is less than or equal to C for all n > k. 4.This is a contradiction as n grows without bound and C is a constant 5.Hence, there can be no pair of witnesses C and k such that n^3 is less than or equal to Cn^2 whenever n > k. 6. We conclude that n^3 is not O(n^2)

The number of character comparisons used by the naive string matcher to look for the pattern is in the text Mississippi is ---

13 -At shift 0, M is compared to i. At shift 1, i is compared to i and s is compared to s (a match). At shift 2, s is compared to i. At shift 3, s is compared to i. At shift 4, i is compared to i and s is compared to s (a match). At shift 5, s is compared to i. At shift 6, s is compared to i. At shift 7, i is compared to i and p is compared to s. At shift 8, p is compared to i. At shift 9, p is compared to i.

What is the list at the end of the first pass of the bubble sort algorithm when given the list 4, 2, 6, 7, 5 as input

2, 4, 6, 5, 7 -The first pass switches 2 and 4 and the 7 and 5.

Problems for which a solution can be checked in polynomial time are said to belong to the class ----. Problems for which a solution can be found with an algorithm with polynomial time worst-case complexity are said to belong to the class ----.

NP P

Using the greedy change-making algorithm, determine the coins required in making change for 46 cents, using quarters, dimes, nickels, and pennies.

One quarter, two dimes, and a penny

Which of the following shifts s are found by the naive string matcher in searching for the pattern is in the text Mississippi?

4 -The two characters starting with shift 4 in the text Mississippi are is. 1 -The two characters starting with shift 1 in the text Mississippi are is.

Order the following steps of a trace of a linear search algorithm used to search for 13 in the list 14, 13, 12.

1. Set i to 1. 2. Compare 1 with 3 and 13 to 14 3. Set i to 2. 4. Compare 2 with 3 and 13 to 13 5. Compare 2 with 3 and set location to 2 6. Report that 13 is at location 2.

Which of the following is the sequence at the end of the second pass when the insertion sort algorithm is used to sort the the list 4, 2, 6, 7, 5?

2, 4, 6, 7, 5 The first pass puts 2 and 4 into the correct order. As 6 is already in the correct order with respect to 2 and 4, the second pass does not change the order of any element

Which of these statements are true about the insertion sort algorithm as specified in the book

- Linear search is used to insert the next element on each pass *This is the way the algorithm works - After inserting the jth element, the first j elements are in order *This is the way the algorithm works - For all sequences of the same size, the algorithm always uses the same number of passes *This is true. The number of passes depends only on the size of the input sequence.

Which of the following are algorithmic paradigms?

Brute-force algorithms (An algorithmic paradigm is a general approach to constructing an algorithm. A brute-force algorithm is one based on a straightforward reading of the problem and the definitions involved.) Greedy algorithms (An algorithmic paradigm is a general approach to constructing an algorithm. A greedy algorithm is an optimization algorithm that aims to find a global optimum through repetitive local optimization)

Define Algorithm

Is a finite sequence of precise instructions for performing a computation or for solving a problem. The solution to a problem is divided into a simple and logical sequence of steps to obtain the desired results. Such a sequence of steps is called an algorithm

Which of these are true statements?

It may be the case that for a particular sequence bubble sort is more efficient than insertion sort. (If the list is already sorted, bubble sort does no interchanges, but insertion sort still inserts each element in its original position..) The worst-case complexity of insertion sort and bubble sort are the same (both are O(n^2))

Why do we measure time complexity in terms of the number of operations required instead of actual computer time?

-Computer processing speeds have been increasing as time passes. (The results of complexity analysis must not be affected by new developments in computing) -Different computers take different amounts of time to perform the same basic operations. (we need the results of complexity analysis to be independent of the machine on which the algorithm runs. -There are many reasons why the same instance of an algorithm on different occasions may take different amounts of time to execute. (For instance, a computer could be running different processes at different times.


संबंधित स्टडी सेट्स

American History From 1865 Midterm Exam

View Set

PULL, THROW. Read the sentences on the left and match the phrasal verbs with their correct number in the box next to each definition.

View Set