Preview

algorithm

Satisfactory Essays
Open Document
Open Document
1449 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
algorithm
Algorithms Homework – Fall 2000

8.1-1 Using Figure 8.1 as a model, illustrate the operation of PARTITION on the array A =

13 19 9 5 12 8 7 4 11 2 6 21 i j  j

6 19 9 5 12 8 7 4 11 2 13 21 i  i j  j

6 2 9 5 12 8 7 4 11 19 13 21 i  …………………………  j

return 11, SPLIT = and

8.1-2 What value of q does PARTITION return when all elements in the array A[p…r] have the same value?

q = (p+r)/2, where p = index 0, and r = highest index

8.1-3 Give a brief argument that the running time of PARTITION on a subarray of size n is (n).

In the worst case, PARTITION must move the j pointer by one element (to the 2nd to last element), and the i pointer all the way to j, making a comparison at each element along the way. Since there are n comparisons made, the running time is (n)
In the average (and best) case, PARTITION must move the j pointer to an element at or near the half-way point in the array and the i pointer all the way to j, making a comparison at each element along the way. Once again there are n comparisons made and the running time is (n)

8.2-1 Show that the running time of QUICKSORT is (n lg n) when all elements of array A have the same value.

T(n) = 2T(n/2) + (n)
CASE 2 of Master Theorem f(n) lg n = (n lg n)

8.2-2 show that the running time of QUICKSORT is (n2) when the array A is sorted in nonincreasing order.

The recurrence in this case is
T(n) = T(n – 1) + (n) = T(n – 2) + (n – 1) + (n) = T(n – 3) + (n – 2) + (n – 1) + (n) … = (n) +  = (n2)

8.2-3 Banks often record transactions on an account in order of the times of the transactions, but many people like to receive their bank statements with

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Mat 221 Week 4 Dis. 1

    • 293 Words
    • 2 Pages

    The numbers are plugged into the formula P = A(1+r)-n and the quantity raised to a power and has a negative exponent of –n. It will look like:…

    • 293 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Exercise 1: Review of array-based lists Create a project using the classes in the DocSharing area labeled “User-defined array list." Compile it, run it, and review the code that is given carefully. This code tests the ArrayList class provided in the lecture.…

    • 714 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    PT1420 Unit 8 Lab 8

    • 365 Words
    • 2 Pages

    Step 4: Write a for loop that will print 60 seconds to the screen. Complete the missing…

    • 365 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3

    • 3151 Words
    • 13 Pages

    and end heads 31, 63 or 127, then, since it is customary to end partitions on a…

    • 3151 Words
    • 13 Pages
    Good Essays
  • Good Essays

    * What is doubling time? Time it takes initial quantity to increase by a factor of 2…

    • 1410 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    2. What is the term used for the number inside the bracket that specifies the number of values that an array can hold? (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    | c. Rannual = (1 + R1)(1 + R2)(1 + R3)(1 + R4) - 1…

    • 24077 Words
    • 97 Pages
    Satisfactory Essays
  • Good Essays

    big o notation

    • 939 Words
    • 4 Pages

    Consider an algorithm having the given value as N, If N is the no of times or statements to be executed they are needed to be executed no of times as in sorting. The greater the value of N in the algorithm the slower the algorithm will take to execute with efficiency, the algorithm will definitely execute but will take larger amount of time compared to other algorithms having the same code with the smaller value of N. If even there is a loop function or two loop functions involved in an algorithm it is going to take a larger amount of time. This comparison can be also called as the Growth Rates of the value N in an algorithm. The N value in the algorithm can be of any mathematical expression depending on the mathematical expression the Growth Rates vary.…

    • 939 Words
    • 4 Pages
    Good Essays
  • Good Essays

    The first step takes Kristen 6 minutes to wash out the electric mixer’s bowl and beaters, and another 2 minutes to spoon the cookies. The valuable time of Kristen would be 8 minutes. In second step, roommate takes 1 minute to put cookies into oven. And also in final step, it takes roommate 2 minutes to pack each dozen and about 1 minute to accept payment. So the valuable time of roommate is 4 minutes totally.…

    • 708 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Algorithms

    • 324 Words
    • 1 Page

    Algorithm analysis is an important part of a broader computational complexity theory, which provides theoretical estimates for the resources needed by any algorithm which solves a given computational problem. These estimates provide an insight into reasonable directions of search for efficient algorithms.…

    • 324 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    log (n!) = log 1 +log 2 +... + log n log (n/2)+ log (n/2+1)+...+log (n)…

    • 350 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    ii)n(n+1)/2 € O(n2) iii) n(n+1)/2 € θ (n3) iv) n(n+1)/2€ Ω (n) c) Discuss the algorithm for element uniqueness problem for its Efficiency. (06 Marks) 3. a) Explain selection sort algorithm and its efficiency. (08 Marks) b) Discuss the merge sort algorithm with recursive tree and its efficiency.…

    • 379 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    o Taking a list of n items and comparing every item to every other item.…

    • 374 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Vhie

    • 3253 Words
    • 14 Pages

    Amount function, A(t), is the accumulated value at time t ≥ 0 of an original investment k. Then A(t) = k · a(t) and A(0) = k In is the amount of interest earned during the nth period from the date of investment. Then In = A(n) − A(n − 1) for integral n ≥ 1…

    • 3253 Words
    • 14 Pages
    Satisfactory Essays