There are numbers from 1 to n, which are inverted such that
it results in numbers from n to 1. If only two consecutive
numbers are stampled at a time and are inverted, how many
moves are required?
Answer Posted / venomvendor
Answer is
Sigma(count), where count ranges from [1 to {n-(swap per time -1)}]
n-(swap per time - 1)
Σ i
i=1
Image Notation >> http://imgur.com/6HkcXzP
In this case.
n = n
swap per time = 2
Substituting this, we get
n-(2 - 1)
Σ i
i=1
n-1
Σ i
i=1
1+2+3+ . . . + (n-1)
if n = 5
Total swaps would be
1+2+3+4 = 10
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Define Routing Algorithm?
What is depth-first search algorithm?
What is software cycle? Give a diagrammatic representation?
Consider the following algorithm, where the array A is indexed 1 through n: int add_them ( int n , int A[ ] ) { index i , j , k ; j = 0 ; for ( i = 1 ; i <= n ; i++) j = j + A[i] ; k = 1 ; for ( i = 1 ; i <= n ; i++) k = k + k ; return j + k ; } (a) If n = 5 and the array A contains 2, 5, 3, 7, and 8, what is returned? (b) What is the time complexity T(n) of the algorithm?
Give a general algorithm for converting a m-array tree to a 2-ary tree.
Which is the most straight forward approach for planning algorithms?
What is meant by uniform cost search algorithm?
Which search algorithm will use a limited amount of memory in an online search?
Write a code/algorithm to find the frequency of each element in an array?
What are disadvantages uniform cost search algorithm?
Which algorithm inverts a complete resolution strategy?
Which algorithm is used for solving temporal probabilistic reasoning?
Can you pick an algorithm. Write the psuedo-code for a parallel implementation?
list the types of linked list with aid of diagram?
What do you mean by overfitting and underfitting algorithms?