status
type
date
slug
summary
tags
category
icon
password

2471. Minimum Number of Operations to Sort a Binary Tree by Level

 
2nd approach deals with with cycle lengths. This approach is more Math. That one is related to the permutation group on [0,1,..qz-1]. That one is based on the fact that each permutation is a series of cyclic transformations.
A cyclic transformation can be denoted by (i0​,i1​,...,ik​) which is fn fact i0​→i1​,i1​→i2​,⋯,ik−1​→ik​,ik​→i0​. A cyclic transformation of length k+1 can be performed by k 2-cycles(i.e. swaps).
The length's counting is using DFS.
notion image
For better understanding the permuation, let's consider the nodes on 2th level.
=>
The permutations are listed by the following
They can be represented by a cyclic transform (0,2,3) which has length 3. This cyclic transform of length 3 can be proceeded by 2 swaps (2,3) then (0, 2) (order cannot be reversed, 2=|cycle|-1=3-1)
 
#1718. Construct the Lexicographically Largest Valid Sequence
 
 
 
 
 
 
 
 
GGUFFlutter 基础 记录
Loading...
ran2323
ran2323
忘掉名字吧
Latest posts
SFT + DPO 塔罗解读
2025-4-14
Backtracking
2025-4-14
Leetcode 0001-1000 分组
2025-4-14
mcp 记录(1)
2025-4-14
DPO 相关
2025-3-29
今日paper(3/25) - MAGPIE
2025-3-27
Announcement
 
 
 
 
暂时没有新的内容