Spaces:
Configuration error
Configuration error
Commit
·
7721184
1
Parent(s):
8b76633
Update app.py layout and fix visual alignment
Browse files- README.md +18 -16
- app.py +5 -11
- requirements.txt +4 -48
README.md
CHANGED
|
@@ -1,25 +1,27 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
## Features
|
| 8 |
|
| 9 |
-
- Generates a random
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
- Brief description of algorithm logic
|
| 15 |
-
|
| 16 |
-
## Technologies Used
|
| 17 |
-
|
| 18 |
-
- Python 3
|
| 19 |
-
- Streamlit
|
| 20 |
-
- Plotly
|
| 21 |
|
| 22 |
-
## How to Run
|
| 23 |
|
| 24 |
```bash
|
| 25 |
pip install -r requirements.txt
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Sorting Algorithm Visualizer
|
| 3 |
+
emoji: 📊
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.32.2"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
|
| 12 |
+
# Sorting Algorithm Visualizer
|
| 13 |
|
| 14 |
+
A Streamlit-based web app that visually compares **Insertion Sort** and **Merge Sort** step-by-step using animated bar charts.
|
| 15 |
|
| 16 |
## Features
|
| 17 |
|
| 18 |
+
- Generates a random array for sorting
|
| 19 |
+
- Side-by-side animated visualization of Insertion Sort and Merge Sort
|
| 20 |
+
- Highlights active elements and sorted regions
|
| 21 |
+
- Displays total number of sorting steps
|
| 22 |
+
- Brief algorithm summaries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
## How to Run Locally
|
| 25 |
|
| 26 |
```bash
|
| 27 |
pip install -r requirements.txt
|
app.py
CHANGED
|
@@ -18,10 +18,8 @@ if st.button("Compare Insertion Sort vs Merge Sort"):
|
|
| 18 |
data_insertion = data.copy()
|
| 19 |
data_merge = data.copy()
|
| 20 |
|
| 21 |
-
# Insertion Sort
|
| 22 |
steps_insertion = insertion_sort(data_insertion)
|
| 23 |
|
| 24 |
-
# Merge Sort
|
| 25 |
steps_merge = merge_sort(data_merge)
|
| 26 |
|
| 27 |
st.subheader("Comparison Results")
|
|
@@ -35,10 +33,6 @@ if st.button("Compare Insertion Sort vs Merge Sort"):
|
|
| 35 |
st.markdown("### Merge Sort")
|
| 36 |
st.write(f"Total steps: {len(steps_merge)}")
|
| 37 |
|
| 38 |
-
# --- Görsel Karşılaştırma ---
|
| 39 |
-
st.subheader("Visual Comparison")
|
| 40 |
-
col1, col2 = st.columns(2)
|
| 41 |
-
|
| 42 |
def create_animation(steps, title, color_fn):
|
| 43 |
frames = []
|
| 44 |
for i, step in enumerate(steps):
|
|
@@ -75,6 +69,7 @@ if st.button("Compare Insertion Sort vs Merge Sort"):
|
|
| 75 |
textposition="middle center"
|
| 76 |
)],
|
| 77 |
layout=go.Layout(
|
|
|
|
| 78 |
title=title,
|
| 79 |
xaxis=dict(range=[-0.5, len(initial["array"]) - 0.5]),
|
| 80 |
yaxis=dict(range=[0, max(max(s['array']) for s in steps) + 5]),
|
|
@@ -112,13 +107,12 @@ if st.button("Compare Insertion Sort vs Merge Sort"):
|
|
| 112 |
for j in range(length)
|
| 113 |
]
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
-
# --- Açıklamalar ---
|
| 122 |
st.subheader("About the Algorithms")
|
| 123 |
st.markdown("**Insertion Sort:** A simple comparison-based algorithm that builds the sorted list one element at a time. Best for small or nearly sorted datasets. Time complexity: O(n²).")
|
| 124 |
st.markdown("**Merge Sort:** A divide-and-conquer algorithm that recursively splits the list and merges them in sorted order. Efficient for large datasets. Time complexity: O(n log n).")
|
|
|
|
| 18 |
data_insertion = data.copy()
|
| 19 |
data_merge = data.copy()
|
| 20 |
|
|
|
|
| 21 |
steps_insertion = insertion_sort(data_insertion)
|
| 22 |
|
|
|
|
| 23 |
steps_merge = merge_sort(data_merge)
|
| 24 |
|
| 25 |
st.subheader("Comparison Results")
|
|
|
|
| 33 |
st.markdown("### Merge Sort")
|
| 34 |
st.write(f"Total steps: {len(steps_merge)}")
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def create_animation(steps, title, color_fn):
|
| 37 |
frames = []
|
| 38 |
for i, step in enumerate(steps):
|
|
|
|
| 69 |
textposition="middle center"
|
| 70 |
)],
|
| 71 |
layout=go.Layout(
|
| 72 |
+
height=400,
|
| 73 |
title=title,
|
| 74 |
xaxis=dict(range=[-0.5, len(initial["array"]) - 0.5]),
|
| 75 |
yaxis=dict(range=[0, max(max(s['array']) for s in steps) + 5]),
|
|
|
|
| 107 |
for j in range(length)
|
| 108 |
]
|
| 109 |
|
| 110 |
+
st.subheader("Insertion Sort Visualization")
|
| 111 |
+
st.plotly_chart(create_animation(steps_insertion, "Insertion Sort", insertion_colors))
|
| 112 |
|
| 113 |
+
st.subheader("Merge Sort Visualization")
|
| 114 |
+
st.plotly_chart(create_animation(steps_merge, "Merge Sort", merge_colors))
|
| 115 |
|
|
|
|
| 116 |
st.subheader("About the Algorithms")
|
| 117 |
st.markdown("**Insertion Sort:** A simple comparison-based algorithm that builds the sorted list one element at a time. Best for small or nearly sorted datasets. Time complexity: O(n²).")
|
| 118 |
st.markdown("**Merge Sort:** A divide-and-conquer algorithm that recursively splits the list and merges them in sorted order. Efficient for large datasets. Time complexity: O(n log n).")
|
requirements.txt
CHANGED
|
@@ -1,48 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
cachetools==6.1.0
|
| 6 |
-
certifi==2025.7.14
|
| 7 |
-
charset-normalizer==3.4.2
|
| 8 |
-
click==8.2.1
|
| 9 |
-
contourpy==1.3.2
|
| 10 |
-
cycler==0.12.1
|
| 11 |
-
fonttools==4.59.0
|
| 12 |
-
gitdb==4.0.12
|
| 13 |
-
GitPython==3.1.44
|
| 14 |
-
idna==3.10
|
| 15 |
-
isort==6.0.1
|
| 16 |
-
Jinja2==3.1.6
|
| 17 |
-
jsonschema==4.25.0
|
| 18 |
-
jsonschema-specifications==2025.4.1
|
| 19 |
-
kiwisolver==1.4.8
|
| 20 |
-
MarkupSafe==3.0.2
|
| 21 |
-
matplotlib==3.10.3
|
| 22 |
-
mypy_extensions==1.1.0
|
| 23 |
-
narwhals==1.48.0
|
| 24 |
-
numpy==2.3.1
|
| 25 |
-
packaging==25.0
|
| 26 |
-
pandas==2.3.1
|
| 27 |
-
pathspec==0.12.1
|
| 28 |
-
pillow==11.3.0
|
| 29 |
-
platformdirs==4.3.8
|
| 30 |
-
plotly==6.2.0
|
| 31 |
-
protobuf==6.31.1
|
| 32 |
-
pyarrow==21.0.0
|
| 33 |
-
pydeck==0.9.1
|
| 34 |
-
pyparsing==3.2.3
|
| 35 |
-
python-dateutil==2.9.0.post0
|
| 36 |
-
pytz==2025.2
|
| 37 |
-
referencing==0.36.2
|
| 38 |
-
requests==2.32.4
|
| 39 |
-
rpds-py==0.26.0
|
| 40 |
-
six==1.17.0
|
| 41 |
-
smmap==5.0.2
|
| 42 |
-
streamlit==1.47.0
|
| 43 |
-
tenacity==9.1.2
|
| 44 |
-
toml==0.10.2
|
| 45 |
-
tornado==6.5.1
|
| 46 |
-
typing_extensions==4.14.1
|
| 47 |
-
tzdata==2025.2
|
| 48 |
-
urllib3==2.5.0
|
|
|
|
| 1 |
+
streamlit>=1.25.0,<2.0.0
|
| 2 |
+
plotly>=5.18.0
|
| 3 |
+
numpy<=1.26.4
|
| 4 |
+
matplotlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|