first commit

This commit is contained in:
2025-12-18 16:00:22 +08:00
commit 785f306726
69 changed files with 33171 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
# Sorting Algorithm Performance Analysis
This project implements and analyzes the performance of several classic sorting algorithms in C++. It provides a framework to test each algorithm on randomly generated data of various sizes, measuring execution time, comparison counts, and move counts.
A detailed analysis and discussion of the results can be found in [REPORT.md](./REPORT.md).
## Implemented Algorithms
- **Basic Sorting Algorithms:**
- Insertion Sort
- Bubble Sort
- Shell Sort
- Merge Sort
- **Quick Sort Variants:**
- Standard Quick Sort (pivot is the last element)
- Quick Sort with Median-of-Three pivot optimization
- 3-Way Quick Sort (for handling duplicate keys)
- Dual-Pivot Quick Sort
## How to Build and Run
A `Makefile` is provided to simplify the build and execution process.
### 1. Build the Project
To compile all the source files and create the executable, run:
```bash
make
```
This will generate an executable file named `sorting_experiment`.
### 2. Run the Experiment
To run the performance analysis, execute the following command:
```bash
make run
```
Alternatively, you can run the executable directly:
```bash
./sorting_experiment
```
The program will output a formatted table with the performance metrics for each algorithm across different data sizes.
### 3. Clean Up
To remove the compiled object files and the executable, run:
```bash
make clean
```
---
<details>
<summary><strong>Original Experiment Requirements</strong></summary>
### 实验内容
对几种经典的排序算法进行分析,理解算法在不同输入时的表现,深入剖析算法优缺点及其根源。具体要求如下:
1. 实现常见排序算法至少要实现插入排序、冒泡排序、快速排序、归并排序、shell排序算法
2. 在排序算法中插桩,记录关键操作次数(如比较次数、移动次数等);
3. 以待排序文件的行数n为输入规模固定n随机产生多组测试样本统计算法的平均运行时间和关键操作次数改变n的规模重复多次实验并对结果进行统计
4. 改变数组规模,对不同规模问题下各算法的结果进行统计并绘制图表,与理论值进行对照分析;
5. 优化快速排序的中枢点选取,对优化前后的性能进行分析;
6. 对快速排序的三种实现进行性能比较。
### 附加:
- 实现BlockQuickSort就分支预测次数展开分析
- 实现DualPivotQuickSort就递归深度展开分析
- 在超大规模数据上如1亿个整数对比以上快排实现的性能。
### 编写实验文档:
要求对所实现算法的时间进行复杂度分析(结合程序统计关键步骤运行次数,以验证分析结果);程序运行指导,包括程序编译说明、输入输出示例等。如果输入、输出信息较多,建议采用文件进行格式化输入、输出。实验报告:解题思路;所实现算法的时间复杂度分析(结合程序统计关键步骤运行次数,以验证分析结果);程序运行指导,包括程序编译说明、输入输出示例等。如果输入、输出信息较多,建议采用文件进行格式化输入、输出。
</details>