This week's SLOG topic is all about sorting algorithms and efficiency.
As mentioned briefly in last week's SLOG, there are a couple sorting algorithms that we have been taught so far.
Here is the list again for reference:
Insertion Sort
Selection Sort
Quick Sort
Merge Sort
Built-In Python Sort
and the most interesting to me: Customized sorting algorithms
Each of these use different methods to sort order-able objects in a mutable collection such as lists and each have their own advantages in the different ways they sort a collection. Their respective run-times can be deduced by observing the code and identifying the worst case for a big-O run-time complexity. Bubblesort, although commonly seen as an inefficient sorting algorithm with an O(n^2) time complexity, has an advantage over other where we can immediately tell that part of the list is sorted if no exchanges are made after each pass. Merge Sort uses a divide and conquer method which recursively sorts separate parts of a list and has a very efficient time complexity of O(nlog(n)). An interesting thing to note is that these run times in Python are not optimized as opposed to other programming languages like C. Built-in Python Sort (or Timsort) uses language closer to machine code which means it is highly optimized. Timsort usually beats most sorting algorithms in terms of efficiency but some customized sorting algorithms can actually sort faster than Timsort depending on various factors such as number of elements in the list.
Here is the list again for reference:
Insertion Sort
Selection Sort
Quick Sort
Merge Sort
Built-In Python Sort
and the most interesting to me: Customized sorting algorithms
Each of these use different methods to sort order-able objects in a mutable collection such as lists and each have their own advantages in the different ways they sort a collection. Their respective run-times can be deduced by observing the code and identifying the worst case for a big-O run-time complexity. Bubblesort, although commonly seen as an inefficient sorting algorithm with an O(n^2) time complexity, has an advantage over other where we can immediately tell that part of the list is sorted if no exchanges are made after each pass. Merge Sort uses a divide and conquer method which recursively sorts separate parts of a list and has a very efficient time complexity of O(nlog(n)). An interesting thing to note is that these run times in Python are not optimized as opposed to other programming languages like C. Built-in Python Sort (or Timsort) uses language closer to machine code which means it is highly optimized. Timsort usually beats most sorting algorithms in terms of efficiency but some customized sorting algorithms can actually sort faster than Timsort depending on various factors such as number of elements in the list.
Efficiency and optimization of code is such an interesting topic to me because my goal is to become a video game developer. Program efficiency is incredibly important for game developers because people generally want their video game to run smoothly without putting too much strain on our CPU's (Central Processing Unit) or RAM (Random Access Memory). If we did not have optimized games, there would be no way to play them unless everyone was using top tier computers built specifically for gaming. Luckily, because optimization does exist, games are playable on lower end computers and everyone is happy! Asides from program efficiency, there is also graphics optimization which is not part of CSC148 but I hope I will have the opportunity to learn more about that as well.