Search

Quick Sort

Characteristics

O(nlogn)O(n \log n)
Recursive

Instructions

1.
Instruction
a.
Set pivot from the unsorted array
b.
Split the array into two, based on the pivot’s value
c.
Repeat until all the length of the all unsorted array becomes 1
d.
Merge all the value Lesser + Pivot + Greater
e.
Repeat 1 - 4 until all the values are sorted
import sys from load import load_numbers # load list of numbers numbers = load_numbers(sys.argv[1]) def quicksort(values): if len(values) <= 1: return values less_than_pivot = [] greater_than_pivot = [] pivot = values[0] for value in values[1:]: if value <= pivot: less_than_pivot.append(value) else: greater_than_pivot.append(value) return quicksort(less_than_pivot) + pivot + quicksort(greater_than_pivot)
Python
복사

Reference

Algorithms and Data Structures Tutorial - Full Course for Beginners
In this course you will learn about algorithms and data structures, two of the fundamental topics in computer science. There are three main parts to this course: algorithms, data structures, and a deep dive into sorting and searching algorithms. By the end, you will understand what algorithms and data structures are, how they are measured and evaluated, and how they are used to solve problems. This course was developed by Pasan Premaratne and Jay McGavren. It was made possible by a grant from teamtreehouse.com ⭐️ Course Contents ⭐️ ⌨️ (0:00:00) Introduction to Algorithms ⌨️ (1:57:44) Introduction to Data Structures ⌨️ (4:11:02) Algorithms: Sorting and Searching ⭐️ Code Snippets for Course ⭐️ 💻 Introduction to Algorithms: ⌨️ Algorithms in Code: 🔗 Linear Search Implementations: https://teamtreehouse.com/library/introduction-to-algorithms/algorithms-in-code/linear-search-implementations 🔗 Binary Search Implementations: https://teamtreehouse.com/library/introduction-to-algorithms/algorithms-in-code/binary-search-implementations 💻 Introduction to Data Structures ⌨️ Exploring Arrays: 🔗 Array Characteristics and Storage: https://teamtreehouse.com/library/introduction-to-data-structures/exploring-arrays/array-characteristics-and-storage 🔗 Operations on Arrays: https://teamtreehouse.com/library/introduction-to-data-structures/exploring-arrays/operations-on-arrays ⌨️ Building a Linked List: 🔗 Singly and Doubly Linked Lists: https://teamtreehouse.com/library/introduction-to-data-structures/building-a-linked-list/singly-and-doubly-linked-lists-2 🔗 Linked List Operations: https://teamtreehouse.com/library/introduction-to-data-structures/building-a-linked-list/linked-lists-operations ⌨️ The Merge Sort Algorithm: 🔗 Merge Sort Implementations: https://teamtreehouse.com/library/introduction-to-data-structures/the-merge-sort-algorithm/merge-sort-implementations 🔗 Alternate Versions of Merge Sort: https://teamtreehouse.com/library/introduction-to-data-structures/the-merge-sort-algorithm/alternate-versions-of-merge-sort ⌨️ Merge Sort and Linked Lists: 🔗 Implementing Merge Sort on Linked Lists: https://teamtreehouse.com/library/introduction-to-data-structures/merge-sort-and-linked-lists/implementing-merge-sort-on-linked-lists 💻 Algorithms: Sorting and Searching ⌨️ Sorting Algorithms: 🔗 Code for Bogosort: https://teamtreehouse.com/library/algorithms-sorting-and-searching/sorting-algorithms/code-for-bogosort 🔗 Code for Selection Sort: https://teamtreehouse.com/library/algorithms-sorting-and-searching/sorting-algorithms/code-for-selection-sort 🔗 Code for Quicksort: https://teamtreehouse.com/library/algorithms-sorting-and-searching/sorting-algorithms/code-for-quicksort 🔗 Code for Merge Sort: https://teamtreehouse.com/library/algorithms-sorting-and-searching/sorting-algorithms/code-for-merge-sort ⌨️ Searching Names: 🔗 Code for Linear Search: https://teamtreehouse.com/library/algorithms-sorting-and-searching/searching-names/code-for-linear-search 🔗 Code for Binary Search: https://teamtreehouse.com/library/algorithms-sorting-and-searching/searching-names/code-for-binary-search -- Learn to code for free and get a developer job: https://www.freecodecamp.org Read hundreds of articles on programming: https://freecodecamp.org/news