Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Consider the following algorithm. // Assume that n is a positive integer (= i.e. n > 1), and A[1..n] is a global array .

1) 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, dont 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;

3. else

4. for i <-- 1 to n do

5. DoSomething(n 1); // Recursive call.

6. if n is odd

7. swap A[1] and A[n];

8. else

9. swap A[i] and A[n];

10. return;

(a) Present execution result of the algorithm where an array A has 3and n is 1.

(b) Present execution result of the algorithm where an array A has 3, 5and n is 2. (Show all the stesp)

(c) Present execution result of the algorithm where an array A has 3, 5, 7and n is 3. (Show all the stesp)

(d) Based on the results of thr question (a), (b), and (c), describe the main purpose of the algorithm.

2) Solve the following recurrence relation. To solve the problem, you have to use the backward substitution and show the intermediate results. After that, you should present the time complexity of the recurrence relations.

M(n) = 2 * M (n-1) // Recurrence relation

M()) = 3 // Initial condition

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago