Bubble Sort Step-by-Step Visualization
Đang tải video…
Đang tải video…
Pro
0:00 / 0:00
Bubble Sort Animation Specification (Defaults)
1. Overview
- Purpose: Visually demonstrate the Bubble Sort algorithm step‑by‑step, highlighting comparisons, swaps, and the progression of sorted elements.
- Target Audience: Students learning basic sorting algorithms.
- Runtime: Approximately 30 seconds.
2. Data Setup
- Array Size: 10 elements.
- Initial Values: Random integers between 1 and 20 (e.g.,
[12, 5, 17, 3, 9, 14, 2, 11, 6, 8]). - Representation: Vertical bars whose heights correspond to the element values.
3. Visual Elements
| Element | Shape | Color (default) | Description |
|---|---|---|---|
| Unsorted bar | Rectangle | GRAY (#7f8c8d) |
All bars at start. |
| Currently compared bars | Rectangle | RED (#e74c3c) |
Two adjacent bars being compared. |
| Swapped bars | Rectangle | GREEN (#27ae60) |
Bars that have just been swapped (brief flash). |
| Sorted portion | Rectangle | BLUE (#2980b9) |
Bars that are confirmed in final position (right‑most part of array). |
| Background | — | BLACK (#2c3e50) |
Full scene background. |
| Pseudocode panel | Text box | WHITE text on DARK_GRAY (#34495e) background |
Shows Bubble Sort pseudocode with the current line highlighted in YELLOW. |
| Loop counters | Text | WHITE |
Displays i (outer loop) and j (inner loop) values above the array. |
4. Layout
- Scene Size: 16:9 aspect ratio (1920 × 1080).
- Array Position: Center‑bottom of the frame, bars spaced evenly.
- Pseudocode Panel: Left side of the screen, vertically centered.
- Counters: Small text above the array, aligned left for
iand right forj.
5. Animation Sequence & Timing
| Step | Action | Duration | Notes |
|---|---|---|---|
| 1 | Title fade‑in: "Bubble Sort Visualization" | 2 s | Title appears, then fades out. |
| 2 | Display initial array bars | 1 s | Bars grow from height 0 to their values. |
| 3 | Show outer loop counter i = 0 |
0.5 s | Counter appears. |
| 4 | For each inner loop iteration (j):‑ Highlight two bars in RED ‑ Pause 0.4 s ‑ If swap needed, animate swap (bars slide horizontally) with GREEN flash |
0.5 s per comparison, 0.8 s per swap | The inner loop runs n‑i‑1 times. |
| 5 | After inner loop completes, color the last sorted bar BLUE and decrement the active range. | 0.6 s | Update i counter. |
| 6 | Repeat steps 3‑5 for all outer loop passes until array sorted. | — | Total passes = n‑1. |
| 7 | Final highlight: all bars BLUE, display "Sorted!" text. | 2 s | Fade‑out of counters and pseudocode. |
| 8 | Summary screen: total comparisons, total swaps, time‑complexity O(n^2). |
3 s | Text on dark background. |
6. Pseudocode Highlighting
1 for i in range(0, n-1):
2 for j in range(0, n-i-1):
3 if A[j] > A[j+1]:
4 swap A[j], A[j+1]
- The line corresponding to the current operation is highlighted in YELLOW.
- When a comparison occurs, line 2 is highlighted; when a swap occurs, line 4 is highlighted.
7. Camera
- Static camera throughout the animation (no zoom or pan). The view comfortably fits the entire array and pseudocode panel.
8. Audio / Voice‑over (Placeholders)
- Insert placeholder markers for optional narration:
[[VO: Comparing A[j] and A[j+1]]][[VO: Swapping elements]][[VO: Pass i completed, largest element placed at position n-i-1]]
9. Export Settings
- Resolution: 1920 × 1080 (16:9).
- Frame Rate: 30 fps.
- File Format: MP4 (H.264).
10. Implementation Notes (Manim Community Edition)
class BubbleSortScene(Scene):
def construct(self):
# 1. Setup data
values = [12, 5, 17, 3, 9, 14, 2, 11, 6, 8]
n = len(values)
# 2. Create bars
bars = VGroup(*[Rectangle(height=v, width=0.5, fill_color=GRAY, fill_opacity=1)
for v in values])
bars.arrange(RIGHT, buff=0.2).to_edge(DOWN, buff=1)
# 3. Add pseudocode text
code = Code(...).to_edge(LEFT, buff=1)
# 4. Add counters
i_counter = Text("i = 0").to_edge(UP, buff=0.5).align_to(bars, LEFT)
j_counter = Text("j = 0").to_edge(UP, buff=0.5).align_to(bars, RIGHT)
# 5. Animation loops (use self.play with Transform, Indicate, etc.)
# Follow the timing table above.
The actual implementation can follow the timing and color changes described above.
Tạo bởi
Mô tả
An engaging 30‑second animation demonstrates the Bubble Sort algorithm on a ten‑element array. Vertical bars represent values, with red highlighting for each comparison, green flashes for swaps, and blue indicating sorted elements. Loop counters i and j and a side panel show the pseudocode, highlighting the active line in yellow. The scene progresses through each pass, ending with a “Sorted!” message and a summary of comparisons, swaps, and O(n²) complexity.
Ngày tạo
Dec 29, 2025, 07:37 AM
Thẻ
bubble-sortsorting-algorithmsalgorithm-visualization
Trạng thái
Hoàn thành
Nhân bản
Sao chép animation này vào tài khoản để chỉnh sửa và xuất bản phiên bản của bạn. Cần đăng nhập.