|
129 | 129 | │
|
130 | 130 | ├── README.md
|
131 | 131 | ├── requirements.txt
|
132 |
| -├── test_runer.py |
133 |
| -└── test_runer.sh |
| 132 | +├── test_runner.py |
| 133 | +└── test_runner.sh |
134 | 134 |
|
135 | 135 |
|
136 | 136 | ```
|
137 | 137 |
|
138 |
| -# pre requirements |
139 |
| -``` bash |
140 |
| -pip install -r requirements.txt |
141 |
| -``` |
142 |
| - |
143 | 138 | # Sorting Algorithms
|
144 |
| -- [Bubble sort](#bubble-sort) |
145 |
| -- [Insertion sort](#insertion-sort) |
146 |
| -- [Selection sort](#selection-sort) |
147 |
| -- [Quick sort](#quick-sort) |
148 |
| - - first |
149 |
| - - last |
150 |
| - - medianOfThree |
151 |
| - - Random |
152 |
| -- [Merge sort](#merge-sort) |
153 |
| -- [Counting sort](#counting-sort) |
154 |
| - |
155 |
| - |
156 |
| -## Bubble Sort |
157 |
| - |
158 |
| -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 pass through the list is repeated until the list is sorted. |
159 |
| - |
160 |
| -### Invariants |
161 |
| -- Initialization: The list is unsorted. |
162 |
| -- Maintenance: After each iteration, the largest unsorted element is placed at its correct position. |
163 |
| -- Termination: The list is sorted. |
164 |
| - |
165 |
| -### Complexity |
166 |
| - |
167 |
| -Time Complexity: |
168 |
| -- Best Case: `O(n)` - When the array is already sorted. |
169 |
| -- Worst Case: `O(n^2)` When the array is sorted in reverse order. |
170 |
| -- Average Case: `O(n^2)` |
171 |
| - |
172 |
| -Space Complexity: |
173 |
| -- `O(1)` - The algorithm sorts the input array in-place. |
174 |
| -## Insertion Sort |
175 |
| -Insertion sort is a simple sorting algorithm that builds the final sorted list one item at a time. It iterates through the input list, removing one element at a time and then finding its correct position within the sorted part of the list. It repeats this process until no unsorted elements remain. |
176 |
| - |
177 |
| -### Invariants |
178 |
| -- Initialization: The list is unsorted. |
179 |
| -- Maintenance: After each iteration, the current element is inserted into its correct position within the sorted part of the list. |
180 |
| -- Termination: The list is sorted. |
181 |
| - |
182 |
| -### Complexity |
183 |
| -Time Complexity: |
184 |
| -- Best Case: `O(n)` - When the array is already sorted. |
185 |
| -- Worst Case: `O(n^2)` - When the array is sorted in reverse order. |
186 |
| -- Average Case: `O(n^2)` |
187 |
| - |
188 |
| -Space Complexity: |
189 |
| -- `O(1)` - The algorithm sorts the input array in-place. |
190 |
| - |
191 |
| - |
192 |
| -## Selection Sort |
193 |
| -Selection sort is a simple sorting algorithm that divides the input list into two parts: the sorted sublist and the unsorted sublist. Initially, the sorted sublist is empty, and the unsorted sublist contains all the elements. The algorithm repeatedly finds the smallest (or largest, depending on the sorting order) element from the unsorted sublist and moves it to the end of the sorted sublist. This process continues until the unsorted sublist becomes empty. |
194 | 139 |
|
195 |
| -### Invariants |
196 |
| -- Initialization: The entire list is unsorted. |
197 |
| -- Maintenance: After each iteration, the smallest (or largest) element from the unsorted sublist is moved to its correct position in the sorted sublist. |
198 |
| -- Termination: The entire list is sorted. |
199 |
| - |
200 |
| -### Complexity |
201 |
| -Time Complexity: |
202 |
| -- Best Case: O(n^2) |
203 |
| -- Worst Case: O(n^2) |
204 |
| -- Average Case: O(n^2) |
205 |
| -Space Complexity: |
206 |
| -- O(1) - The algorithm sorts the input array in-place. |
207 |
| - |
208 |
| -## Quick Sort |
209 |
| - |
210 |
| -## Merge Sort |
211 |
| - |
212 |
| -## Counting Sort |
| 140 | +## pre requirements for Sorting Algorithms test auto run |
213 | 141 |
|
| 142 | +To recreate the environment, you can run: |
214 | 143 |
|
| 144 | +``` bash |
| 145 | +python -m venv .venv |
| 146 | +source .venv/bin/activate # On Windows use `.venv\Scripts\activate` |
| 147 | +pip install -r requirements.txt |
| 148 | +``` |
215 | 149 |
|
| 150 | +Or if using `pipenv`: |
216 | 151 |
|
217 |
| - ## for testing |
218 | 152 | ```bash
|
219 |
| -g++ <path_to_test_file > <path_to_according_src_file> -o <result_name> -lgtest -lgtest_main -pthread |
| 153 | +pipenv install -r requirements.txt |
220 | 154 | ```
|
221 | 155 |
|
222 |
| -## test_bubble_sort |
223 |
| -```bash |
224 |
| -g++ tests/test_bubble_sort.cpp src/1__bubble_sort.cpp -o bubble_sort_test -lgtest -lgtest_main |
225 |
| -``` |
226 | 156 |
|
227 |
| -## test_insertion_sort |
| 157 | +after you can run `test_runner.py` by |
| 158 | + |
228 | 159 | ```bash
|
229 |
| -g++ tests/test_insertion_sort.cpp src/2__insertion_sort.cpp -o insertion_sort_test -lgtest -lgtest_main |
| 160 | +./test_runner.py |
| 161 | +#or |
| 162 | +python test_runner.py |
230 | 163 | ```
|
231 | 164 |
|
232 |
| -## test_merge_sort |
| 165 | +## for manual testing |
| 166 | + |
233 | 167 | ```bash
|
234 |
| -g++ tests/test_merge_sort.cpp src/5__merge_sort.cpp -o merge_sort_test -lgtest -lgtest_main-lgtest_main |
235 |
| -``` |
| 168 | +g++ <path_to_test_file > <path_to_according_src_file> -o <result_name> -lgtest -lgtest_main -pthread |
| 169 | +``` |
0 commit comments