Question
12. (10 points) Consider the following algorithm. // Assume that n is a positive integer (= i.e. n > 1), and A[1..n] is a
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Discrete and Combinatorial Mathematics An Applied Introduction
Authors: Ralph P. Grimaldi
5th edition
201726343, 978-0201726343
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App