MergeSort Graph¶
MergeSort Graph 1¶
```mermaid graph TD; A[36, 25, 44, 2, 8, 88, 11] → B1[36, 25, 44, 2] & B2[8, 88, 11] B1 → C1[36, 25] & C2[44, 2] C1 → D1[36] & D2[25] C2 → D3[44] & D4[2] D1 → E1[25, 36] D2 → E1[25, 36] D3 → E2[2, 44] D4 → E2[2, 44] E1 → F1[2, 25, 36, 44] E2 → F1[2, 25, 36, 44]
B2 --> F2[8, 11] & F3[88]
F2 --> G1[8] & G2[11]
F3 --> G3[88]
G1 --> H1[8, 11]
G2 --> H1[8, 11]
H1 --> I1[8, 11, 88]
G3 --> I1[8, 11, 88]
F1 --> I2[2, 8, 11, 25, 36, 44, 88]
I1 --> I2[2, 8, 11, 25, 36, 44, 88]
```
MergeSort Graph 2¶
```mermaid graph TD; %% Level A: Original List subgraph A [A: Original List] A1[36, 25, 44, 2, 8, 88, 11] end
%% Level B: First Split
subgraph B [B: First Split]
B1[36, 25, 44, 2]
B2[8, 88, 11]
end
A1 --> B1
A1 --> B2
%% Level C: Splitting Left Half Further
subgraph C [C: Split L1]
C1[36, 25]
C2[44, 2]
end
B1 --> C1
B1 --> C2
%% Level D: Splitting into Single Elements (Left Branch)
subgraph D [D: Split L2]
D1[36]
D2[25]
D3[44]
D4[2]
end
C1 --> D1
C1 --> D2
C2 --> D3
C2 --> D4
%% Level E: Merging Single Elements (Left Branch)
subgraph E [E: Merge L2]
E1[25, 36]
E2[2, 44]
end
D1 --> E1
D2 --> E1
D3 --> E2
D4 --> E2
%% Level F: Merging Left Branch & Splitting Right Branch
subgraph F [F: Merge L1, Split R1]
F1[2, 25, 36, 44]
F2[8, 11]
F3[88]
end
E1 --> F1
E2 --> F1
B2 --> F2
B2 --> F3
%% Level G: Splitting F2 (Right Branch)
subgraph G [G: Split R2]
G1[8]
G2[11]
G3[88]
end
F2 --> G1
F2 --> G2
F3 --> G3
%% Level H: Merging Elements from F2
subgraph H [H: Merge R2]
H1[8, 11]
end
G1 --> H1
G2 --> H1
%% Level I: Merging Right Branch Results
subgraph I [I: Merge R1 ]
I1[8, 11, 88]
end
H1 --> I1
G3 --> I1
%% Level J: Final Merge
subgraph J [J: Final Merge]
J1[2, 8, 11, 25, 36, 44, 88]
end
F1 --> J1
I1 --> J1
```
Weighing Cartons Graph 1¶
```mermaid
flowchart TD
A[Start: Cartons C1, C2, C3, C4, C5, C6, C7]
B[Divide into Groups:
Group A: C1, C2, C3
Group B: C4, C5, C6
Group C: C7]
C[First Measurement:
Weigh Group A vs Group B]
D{Are the groups equal?}
E[“Case 1: Balanced
Lighter carton is in Group C (C7)”]
F[“Second Measurement:
Weigh C7 against any normal carton (e.g., C1)”]
G[Confirm C7 is lighter]
H[Case 2: Unbalanced
Lighter group contains the lighter carton]
I[Second Measurement:
Weigh two cartons from the lighter group]
J{Are these two equal?}
K[If equal, the unweighed carton is lighter]
L[If unequal, the lighter carton on the scale is identified]
A --> B
B --> C
C --> D
D -- Yes --> E
E --> F
F --> G
D -- No --> H
H --> I
I --> J
J -- Yes --> K
J -- No --> L
```
Weighing Cartons Graph 2¶
```mermaid flowchart TD A[“Start: 7 Cartons (C1, C2, C3, C4, C5, C6, C7)”] B[Observation: One carton is lighter; the rest are equal] C[Step 1: Divide into 3 Groups] D[Group A: C1, C2, C3] E[Group B: C4, C5, C6] F[Group C: C7] G[Step 2: First Measurement] H[Action: Weigh Group A vs Group B] I[Insight: If the groups balance, then the lighter carton must be in Group C] J[“Insight: If they do not balance, the lighter group (A or B) contains the lighter carton”] K[Step 3: Second Measurement] L[For Group C: Weigh C7 against any normal carton] M[For lighter Group: Weigh any two cartons from the lighter group] N[Final Analysis: The outcome of the second measurement identifies the lighter carton]
A --> B
B --> C
C --> D
C --> E
C --> F
D --> G
E --> G
F --> G
G --> H
H --> I
H --> J
I --> K
J --> K
K --> L
K --> M
L --> N
M --> N
```
Weighing Cartons Graph 3¶
mermaid
flowchart TD
A[Start: Cartons C1, C2, C3, C4, C5, C6, C7]-->B[C1, C2, C3] & C[C4, C5, C6] & D[C7]
B --> E["First Measurement:<br/> Weigh C1, C2, C3 against C4, C5, C6"]
C --> E
E --> F1["C1+C2+C3 != C4+C5+C6"] & F2["C1+C2+C3 == C4+C5+C6"]
G1["C7 is lighter"]
F2 --> G1
D --> G1
F1 --> H["Take the group that weighs less. Say: C1, C2, C4"]
H --> I["Second Measurement:<br/> Weigh C1, C2 against each other"]
I --> J["If equal, C4 is lighter"]
I --> K["If unequal, the lighter carton is identified"]
Weighing Cartons Graph 4¶
```mermaid flowchart TD A[Start: Cartons C1, C2, C3, C4, C5, C6, C7] B[C1, C2, C3] C[C4, C5, C6] D[C7]
A --> B
A --> C
A --> D
subgraph M1["First Measurement"]
E["Weigh C1, C2, C3 against C4, C5, C6"]
B --> E
C --> E
F1["Result: C1+C2+C3 ≠ C4+C5+C6"]
F2["Result: C1+C2+C3 = C4+C5+C6"]
E --> F1
E --> F2
end
subgraph Outcome_M1["Outcome of First Measurement"]
G1["Conclusion: C7 is lighter"]
F2 --> G1
D --> G1
end
subgraph M2["Second Measurement"]
H["Select the lighter group (e.g., C1, C2, C4)"]
F1 --> H
I["Weigh C1 against C2"]
H --> I
J["If equal, then C4 is lighter"]
K["If unequal, the lighter one is identified"]
I --> J
I --> K
end
```