Question
Given an array of integers of any size, n 4, write an algorithm as a pseudo code (not a program!) that would reverse every
Given an array of integers of any size, n ≥ 4, write an algorithm as a pseudo code (not a program!) that would reverse every two consecutive elements of the left half of the array (i.e. reverse elements at index 0 &1, at index 2 & 3, etc.). Additionally, for the right half of the array, the algorithm must change the second element of every two consecutive elements to have to the product (multiplication) of the two elements. For instance, if the right half starts at index 14, and the values at index 14 & 15 are 5 and 12, then the value at index 15 is changed to 60. If the given array is of an odd size, then the left half is considered as the ceiling value of n/2. Finally, your algorithm must use the smallest auxiliary/additional storage to perform what is needed.
b) What is the time complexity of your algorithm, in terms of Big-O?
c) What is the space complexity of your algorithm, in terms of Big-O?
Step by Step Solution
3.29 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
arrn given array procedure swapint aint b tmp a a b b tmp if n2 0 1 2 3 4 5 6 7 8 9 for i ...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 Started