Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Original array: 5 3 2 4 1
- Number of inversions are -
- Working with subarray from index 0 to 4: 5 3 2 4 1
- Working with subarray from index 0 to 2: 5 3 2
- Working with subarray from index 0 to 1: 5 3
- Working with subarray from index 0 to 0: 5
- Total Inversions in the subarray: 5 is: 0
- Inversions for left subarr: 5 is: 0
- Working with subarray from index 1 to 1: 3
- Total Inversions in the subarray: 3 is: 0
- Inversions for right subarr: 3 is: 0
- For the subarray we are working on: 5 3
- 3 smaller than all elements from index 0 to 0
- i.e all these elements: 5
- Number of inversions is now: 1
- Hopefully sorted: 3 5
- Total inversions for sorted left and right subarr: 3 5 is: 1
- Total Inversions in the subarray: 3 5 is: 1
- Inversions for left subarr: 3 5 is: 1
- Working with subarray from index 2 to 2: 2
- Total Inversions in the subarray: 2 is: 0
- Inversions for right subarr: 2 is: 1
- For the subarray we are working on: 3 5 2
- 2 smaller than all elements from index 0 to 1
- i.e all these elements: 3 5
- Number of inversions is now: 2
- Hopefully sorted: 2 3 5
- Total inversions for sorted left and right subarr: 2 3 5 is: 3
- Total Inversions in the subarray: 2 3 5 is: 3
- Inversions for left subarr: 2 3 5 is: 3
- Working with subarray from index 3 to 4: 4 1
- Working with subarray from index 3 to 3: 4
- Total Inversions in the subarray: 4 is: 0
- Inversions for left subarr: 4 is: 0
- Working with subarray from index 4 to 4: 1
- Total Inversions in the subarray: 1 is: 0
- Inversions for right subarr: 1 is: 0
- For the subarray we are working on: 4 1
- 1 smaller than all elements from index 3 to 3
- i.e all these elements: 4
- Number of inversions is now: 1
- Hopefully sorted: 4 1
- Total inversions for sorted left and right subarr: 4 1 is: 1
- Total Inversions in the subarray: 4 1 is: 1
- Inversions for right subarr: 4 1 is: 4
- For the subarray we are working on: 1 4 5 4 1
- 4 smaller than all elements from index 2 to 2
- i.e all these elements: 5
- Number of inversions is now: 1
- 1 smaller than all elements from index 2 to 2
- i.e all these elements: 5
- Number of inversions is now: 2
- Hopefully sorted: 1 4 4 1 5
- Total inversions for sorted left and right subarr: 1 4 4 1 5 is: 6
- Total Inversions in the subarray: 1 4 4 1 5 is: 6
- 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement