Given the method mystery below, show all output printed for the method call mystery(test), where test...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given the method mystery below, show all output printed for the method call mystery(test), where test is the array [15, 20, 25, 30]. Write down JUST the output. public static void systery(int[] arr) { int total = 0; int index = 0; } while (total < 100) ( try ( } int value are[Index]; total index + 2; System.out.println(total); } catch } value; (ArrayIndexOutOfBoundsException e) ( index index-3; System.out.println("done"); Part B The Quick Sort algorithm is an efficient way to sort an array. Similar to Merge Sort, it uses recursion to take a divide-and-conquer approach. The basic steps is as follows: 1. If the array has 1 or less elements, do nothing. 2. Choose an element from the list, called the pivot. This will be used to divide the list into two sub- lists. 3. Reorder all the elements around the pivot the ones with smaller value are placed before it, and all the elements greater than the pivot after it. After this step, the pivot is in its final position. 4. Create two sub-lists on the left and right of the pivot. Apply the above steps recursively to both sub-lists. Assume that you are given the method below that creates the partitions mentioned in step 3 and returns the pivot in it's optimal position. private int partition(int arr[], int begin, int end) Write the recursive method quickSort as described in step 1, 2 and 4. Use the method above to get a pivot value and call the quickSort method recursively on the two sub-arrays generated from [0 to pivot] and [pivot+1 to arr.length-1]. public void quicksort(int arr[], int begin, int end) Given the method mystery below, show all output printed for the method call mystery(test), where test is the array [15, 20, 25, 30]. Write down JUST the output. public static void systery(int[] arr) { int total = 0; int index = 0; } while (total < 100) ( try ( } int value are[Index]; total index + 2; System.out.println(total); } catch } value; (ArrayIndexOutOfBoundsException e) ( index index-3; System.out.println("done"); Part B The Quick Sort algorithm is an efficient way to sort an array. Similar to Merge Sort, it uses recursion to take a divide-and-conquer approach. The basic steps is as follows: 1. If the array has 1 or less elements, do nothing. 2. Choose an element from the list, called the pivot. This will be used to divide the list into two sub- lists. 3. Reorder all the elements around the pivot the ones with smaller value are placed before it, and all the elements greater than the pivot after it. After this step, the pivot is in its final position. 4. Create two sub-lists on the left and right of the pivot. Apply the above steps recursively to both sub-lists. Assume that you are given the method below that creates the partitions mentioned in step 3 and returns the pivot in it's optimal position. private int partition(int arr[], int begin, int end) Write the recursive method quickSort as described in step 1, 2 and 4. Use the method above to get a pivot value and call the quickSort method recursively on the two sub-arrays generated from [0 to pivot] and [pivot+1 to arr.length-1]. public void quicksort(int arr[], int begin, int end)
Expert Answer:
Answer rating: 100% (QA)
The given function mystery when execute with the array test containing the elements 15202530 the fol... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Robotron-Elotherm company is known for its expertise in power electronics for welding, induction bonding, and process heating. Originally known as Robotron, the company manufactured bonding...
-
The observational unit and explanatory variable are the same as in Exercise 9.CE.17. Th e dotplots for Exercise 9.CE.19 are for a third set of response variables: precipitation (a states annual...
-
Glass bottles can be either recycled (crushed and re-melted) or reused. The market will tend to choose the cheapest path. What factors will tend to affect the relative cost of these options? Is the...
-
Determine the rate of heat transfer per unit length from a 5-cm-OD pipe at 150?C placed eccentrically within a larger cylinder of 85% Magnesia wool as shown in the sketch. The outside diameter of the...
-
Using the source documents of H Alwart in figure 5.19, prepare the sales journal (or general journal), post to the general ledger and at the end of the month prepare a trial balance. Use the...
-
1. Identify an entrepreneur in your area you would like to interview. 2. Contact the person you have selected and make an appointment. Be sure to explain why you want the appointment and to give a...
-
Wig Creations Company supplies wigs and hair care products to beauty salons throughout Texas and the Southwest. The accounts receivable clerk for Wig Creations prepared the following partially...
-
2. Prove that for any integer n 1, and any set of n real numbers {x1,. . . Xn} |x1 + . . . + xn| |x1|+ . . . + |xn|. Can you identify exactly in which cases equality hold for n = 2 (i.e., the...
-
Burnard (1992) sent a questionnaire to a stratified sample of nursing tutors and students in Wales, to study what the tutors and students understood by the term experiential learning. The population...
-
Tax Preparers, Inc. works 250 days per year. The company uses adding machine tape at a rate of eight rolls per day. Usage is believed to be normally distributed with a standard deviation of three...
-
The issue of age differences is one I deal with every day, as many younger employees work their way up the ladder and work with older employees. This can lead to the misinterpretation of ideas and...
-
Approximately 88.5% of the US population has access to the internet as reported by Internet Live Stats. Find a website that consumers might use to gather information about a an upcoming purchase....
-
Asset allocation funds typically invest in Blank______. Multiple select question. money market instruments broadway plays bonds stocks real estate
-
Name something good about an emergency purchase and something not so good.
-
You own a $1,000 bond that pays 9 percent interest. What is the amount of interest you will receive each six months? Multiple Choice $9.00 $45.00 $4.50 $90.00 $22.50
-
Simon Company's year-end balance sheets follow. At December 31 Assets Cash Accounts receivable, net Merchandise inventory Prepaid expenses Plant assets, net Total assets Liabilities and Equity...
-
Using (1) or (2), find L(f) if f(t) if equals: t cos 4t
-
Consider the following class declaration: class Golfer { private: char * fullname; // points to string containing golfer's name int games; // holds number of golf games played int * scores; // points...
-
Whats the difference between an entry-condition loop and an exit-condition loop? Which kind is each of the C++ loops?
-
What would the following code fragment print if it were part of a valid program? int k = 8; do cout <
-
Consider a Lagrangian \(L^{\prime}=L+d f / d t\), where the Lagrangian is \(L=\) \(L\left(q_{k}, \dot{q}_{k}, tight)\), and the function \(f=f\left(q_{k}, tight)\). (a) Show that...
-
Show that the function \(L^{\prime}\) given in the preceding problem must obey Lagrange's equations if \(L\) does, directly from the principle of stationary action. Lagrange's equations do not have...
-
In Example 4.8 we analyzed the case of a bead on a rotating parabolic wire. The energy of the bead was not conserved, but the Hamiltonian was: There is an equilibrium point at \(r=0\) which is...
Study smarter with the SolutionInn App