Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bubble Shuffle Lili has just learned about bubble sort in her algorithm class. However, she is having a problem with the implementation of the algorithm.

Bubble Shuffle

Lili has just learned about bubble sort in her algorithm class. However, she is having a

problem with the implementation of the algorithm. Instead of sorting the array A, her

algorithm creates a jumbled shuffle B of the original array. Lili has lost track of how

many changes has been done to the array, so she has asked your help to find out what

is the minimal number of swaps needed to restore the given shuffled array into the original array. As in bubble sort, a swap can only be done on elements adjacent to one another.

Format Input

A single line with an integer N denoting the number of elements followed by 2 lines each

containing N elements denoting the shuffle array B and the original array A respectively.

Format Output

A single line with an integer denoting the minimal number of swaps needed to restore

the original array.

Constraints

1 N 10^3

1 Ai

, Bi 10^9

Each element in A and B does not appear more than once

It is guaranteed that each element of B exist in A

Sample Input 1

5

1 2 5 3 4

5 1 4 2 3

Sample Output 1

4

Sample Input 2

7

1 3 5 7 9 13 11

13 11 9 7 5 3 1

Sample Output 2

20

Note : Use C Language , Dont Use Stdlib as you can

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

Step: 3

blur-text-image

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

=+ How does this differ from the Solow model?

Answered: 1 week ago