Using BFS approach
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
function minSwapsToSort(arr) {
    let swaps = 0;
    const n = arr.length;
    const visited = new Array(n).fill(false);
    const pos = arr.map((val, index) => ({ val, index })).sort((a, b) => a.val - b.val);

    for (let i = 0; i < n; i++) {
        if (visited[i] || pos[i].index === i) continue;
        let cycleSize = 0;
        let j = i;
        while (!visited[j]) {
            visited[j] = true;
            j = pos[j].index;
            cycleSize++;
        }
        swaps += cycleSize - 1;
    }
    return swaps;
}

function minimumOperations(root) {
    if (!root) return 0;
    let operations = 0;
    const q = [root];

    while (q.length) {
        const level = [];
        const size = q.length;
        for (let i = 0; i < size; i++) {
            const node = q.shift();
            level.push(node.val);
            if (node.left) q.push(node.left);
            if (node.right) q.push(node.right);
        }
        operations += minSwapsToSort(level);
    }
    return operations;
}
```
['JavaScript']