12. (10 points) Consider the following algorithm. // Assume that n is a positive integer (=...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
12. (10 points) Consider the following algorithm. // Assume that n is a positive integer (= i.e. n > 1), and A[1..n] is a global array. // Note that the index of array A starts from one, not zero. // And also, don't forget the array A in the algorithm is global. Algorithm DoSomething (n) 1. if (n = 1) 2. print the current content of the whole array A on the screen: else for i 1 ton do DoSomething(n-1); // Recursive call. 3. 4. 5. 6. 7. swap A[1] and A[n]; 8. else 9. if n is odd 10. return; swap A[i] and A[n]: (a) Present execution result of the algorithm where an array A has "5" and n is 1. (b) Present execution result of the algorithm where an array A has "5, 7" and n is 2. (c) Present execution result of the algorithm where an array A has "5, 7, 9" and n is 3. 12. (10 points) Consider the following algorithm. // Assume that n is a positive integer (= i.e. n > 1), and A[1..n] is a global array. // Note that the index of array A starts from one, not zero. // And also, don't forget the array A in the algorithm is global. Algorithm DoSomething (n) 1. if (n = 1) 2. print the current content of the whole array A on the screen: else for i 1 ton do DoSomething(n-1); // Recursive call. 3. 4. 5. 6. 7. swap A[1] and A[n]; 8. else 9. if n is odd 10. return; swap A[i] and A[n]: (a) Present execution result of the algorithm where an array A has "5" and n is 1. (b) Present execution result of the algorithm where an array A has "5, 7" and n is 2. (c) Present execution result of the algorithm where an array A has "5, 7, 9" and n is 3.
Expert Answer:
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date:
Students also viewed these programming questions
-
Refer to Problem 65. The line x 2y + 4 = 0 is tangent to a circle at (0, 2). The line y = 2x 7 is tangent to the same circle at (3, 1). Find the center of the circle. Data from problem 65 If the...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
a. Distinguish between internal common equity and new common stock. b. Why is there a cost associated with internal common equity? c. Describe two approaches that could be used in computing the cost...
-
Hauswirth Corporation sold (or exchanged) some manufacturing equipment in year 0. Hauswirth bought the machinery several years ago for $65,000 and it has claimed $23,000 of depreciation expense...
-
Given the probability distribution of hours teenagers spend on social media a week, find the following. a. The probability that a teenager spends 15 hours on social media a week. b. The probability...
-
You are auditing trade accounts receivable for the Winston-McCabe Company, a farm equipment retailer doing business in three Midwestern cities. All accounting, shipping, billing, and receivables...
-
A rental car company has an imbalance of cars at seven of its locations. The following network shows the locations of concern (the nodes) and the cost to move a car between locations. A positive...
-
Peder Mueller is a foreign exchange trader for a bank in New York. Using the values and assumptions here,,he decides to seek the full 4.804% return available in U.S. dollars by not covering his...
-
Some nucleus of X74189 (atomic mass = 188.96191 u) undergoes decay to become X175189 (atomic mass = 188.95922 u). What is the energy (in MeV) released in this process?
-
Condensing Logarithms Question Condense the logarithm r log d+ logg Examples
-
Condensing Logarithms Question Condense the logarithm x log b y log c - Examples
-
Simplify 20 4 X 3x= 4 3x+20
-
Given that a typical cell has a diameter of about 1 0 ???? , and the human body has a density of about 1 0 0 0 ???? ???? ???? 3 . Part A Estimate the number of cells in an adult human body of mass 8...
-
Graph the circle. x + y-4x+8y+11=0 -6 $ 3 5 6 7
-
Choose any TWO companies listed in the property sector of the Main Market of Bursa Malaysia. Analyse the companies financial position and performance based on the relevant profitability, debt, and...
-
The Alert Company is a closely held investment-services group that has been very successful over the past five years, consistently providing most members of the top management group with 50% bonuses....
-
For n 3, let Gn = (V, E) be the undirected graph obtained from the complete graph Kn upon deletion of one edge. Determine P(Gn, ) and x(Gn).
-
Determine which of the graphs in Fig. 11.69 are planar. If a graph is planar, redraw it with no edges overlapping. If it is nonplanar, find a subgraph homeomorphic to either K5 or K3 3. b cd u w X y...
-
For k, n Z+, prove that if kn + 1 pigeons occupy n pigeonholes, then at least one pigeonhole has k + 1 or more pigeons roosting in it.
-
Consider the binary variable version of the fixed effects model in Equation (10.11) except with an additional regressor, \(D 1_{i}\); that is, let \[ Y_{i t}=\beta_{0}+\beta_{1} X_{i t}+\gamma_{1} D...
-
Using the regression in Equation (10.11), what are the slope and intercept for a. Entity 1 in time period 1? b. Entity 1 in time period 3? c. Entity 3 in time period 1? d. Entity 3 in time period 3?...
-
Do the fixed effects regression assumptions in Key Concept 10.3 imply that \(\operatorname{cov}\left(\widetilde{v}_{i t}, \widetilde{v}_{i s} ight)=0\) for \(t eq s\) in Equation (10.28)? Explain....
Study smarter with the SolutionInn App