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 / 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 |
Given a sorted array of n integers that has been rotated i(unknown) number of times, give a (log n) algorithm that finds an element in the array.
Give a general algorithm for converting a m-array tree to a 2-ary tree.
What is Na?ve Bayes Algorithm?
Explain the Canny's Algorithm.
What is breadth-first search algorithm?
Give an example of an O (n) algorithm and O (n*n) algorithm such that the algorithm is slower.
What is bidirectional search algorithm?
What is depth-first search algorithm?
What is breath-first search algorithm?
Which is the most straight forward approach for planning algorithms?
Draw a flowchart to find the average of four number?
What is informed (heuristic) search strategies algorithm?