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

  • 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

    it the functions listed below for Exercise 2. In each case, the appropriate error message should be generated if an invalid condition occurs. For example, an error message should be generated when trying to insert an item in a given location in the list and the location is out of range, a. ArrayList(inl size): create a constructor that sets the size of the array list to the value passed in size (note that the class variable SIZE cannot be final anymore), b. int length(): create this function to determine the number of items in the list (accessor function), c. int gelSize(): create this function to determine the size of the list (accessor function), d. void clear(): create this function to remove all of the items from the list. After this operation, the length of the list is zero, e. void replace(int location, int item): create this function to replace the item in the list at the position specified by location. The item should be replaced with item. f. void insert(int location, int item): create this function to add an item to the list at the position specified by location, g. void remove(int item): create this function to delete an item from the list. All ...…

    • 714 Words
    • 3 Pages
    Good 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

    2. Use the definition {n \choose k} = \frac{n!}{k!(n -k)!} to show that the equation in question (1) is true.…

    • 527 Words
    • 3 Pages
    Good Essays
  • Good Essays

    ECET 370 Week 5 Lab 5

    • 650 Words
    • 3 Pages

    Exercise 3: Searching Applications Select one of the following two problems to solve: Problem 1: Design and implement an algorithm that determines whether or not a given array of elements, listl, is completely contained within another given array of elements, Iist2. Consider two different scenarios: 1) both arrays are sorted; 2) both arrays are unsorted. Problem 2: Design an algorithm that when given a collection of integers in an unsorted array, determines the second smallest number (or second minimum). For example, if the array consists of the values 12, 23, 9, 17, 3, the algorithm should report the value 9, since it is the second smallest number in the array. Write a function that...…

    • 650 Words
    • 3 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
  • Good Essays

    Concept Programing

    • 443 Words
    • 3 Pages

    1) n > 0 and count = n => count > 0 before the while loop…

    • 443 Words
    • 3 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

    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

    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

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

    • 374 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

    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