https://github.com/guanshiyin28/bubble-sort-and-insert-sort
Bubble Sort dan Insert Sort (Python & C++)
https://github.com/guanshiyin28/bubble-sort-and-insert-sort
bubble-sort cpp insertion-sort python
Last synced: 4 months ago
JSON representation
Bubble Sort dan Insert Sort (Python & C++)
- Host: GitHub
- URL: https://github.com/guanshiyin28/bubble-sort-and-insert-sort
- Owner: guanshiyin28
- License: apache-2.0
- Created: 2024-12-26T23:30:34.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-01-25T19:07:32.000Z (5 months ago)
- Last Synced: 2025-01-25T19:24:59.246Z (5 months ago)
- Topics: bubble-sort, cpp, insertion-sort, python
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Bubble Sort and Insert Sort
This repository aims to provide a comprehensive starting point for understanding and implementing two fundamental sorting algorithms: Bubble Sort and Insertion Sort. These algorithms are implemented in Python and serve as a great introduction to sorting techniques for beginners and intermediate programmers.
## Purpose of This Repository
### Bubble Sort
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The process is repeated until the list is sorted. Although it is not the most efficient sorting algorithm for large datasets, it is easy to understand and implement.
### Insertion Sort
Insertion Sort is another simple sorting algorithm that builds the final sorted array one item at a time. It is much more efficient than Bubble Sort for small or nearly sorted datasets. It works by taking elements from the unsorted part of the array and inserting them into their correct position in the sorted part.
## Demonstration
Here is a quick demo of the sorting algorithms in action:
### Bubble Sort Example
```python
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr# Example usage
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = bubble_sort(arr)
print("Sorted array is:", sorted_arr)
```### Insertion Sort Example
```python
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr# Example usage
arr = [12, 11, 13, 5, 6]
sorted_arr = insertion_sort(arr)
print("Sorted array is:", sorted_arr)
```
## Features
- Easy-to-understand implementations of Bubble Sort and Insertion Sort
- Well-commented code for better understanding
- Suitable for beginners and intermediate programmers
## Technologies Used
- Python
## Project Setup
1. Clone the repository:
```bash
git clone https://github.com/guanshiyin28/Bubble-Sort-and-Insert-Sort.git
```
2. Navigate to the project directory:
```bash
cd Bubble-Sort-and-Insert-Sort
```
## Steps to Run
1. Ensure you have Python installed on your system.
2. Run the Python scripts:
```bash
python program.py
```
## License
This project is licensed under the Apache-2.0 License. See the [LICENSE](LICENSE) file for details.