常見排序算法
In its most basic form, an algorithm is a set of detailed step-by-step instructions to complete a task. For example, an algorithm to make coffee in a french press would be:
在最基本的形式中,算法是一組完成任務的詳細分步說明。 例如,在法國媒體中制作咖啡的算法為:
- Pour water into the kettle, close the lid, and turn it on. 將水倒入水壺中,合上蓋子,然后打開。
- Take the lid off the french press and pour in 17 grams of ground coffee. 從法國壓機上取下蓋子,倒入17克咖啡粉。
- When the water in the kettle is boiling, pour 290 grams of hot water into the french press. 當水壺中的水沸騰時,將290克熱水倒入法國壓榨機中。
- Put the lid of the french press back on with the plunger up. 向上推柱塞,重新蓋上法式壓力機的蓋子。
- Wait 4 minutes. 等待4分鐘。
- Gently press the plunger down until it reaches the bottom. 輕輕向下按下柱塞,直至到達底部。
- Pour coffee into a mug. 將咖啡倒入杯子。
In computer science, common algorithms have names like "Quicksort" and "Bogosort". Algorithms are often grouped into different categories like search, sorting, and compression algorithms. Further, algorithms can be described by the approach it takes to complete a task, such as recursive, backtracking, divide and conquer, greedy, and brute force.
在計算機科學中,常用算法的名稱如“ Quicksort”和“ Bogosort”。 算法通常分為不同的類別,例如搜索,排序和壓縮算法。 此外,可以通過完成任務所需的方法來描述算法,例如遞歸,回溯,分而治之,貪婪和蠻力。
Algorithms are often paired with data structures, though they are fundamentally different. Data Structures are methods of storing data so that an algorithm can perform operations on it easily.
盡管算法本質上有所不同,但它們通常與數據結構配對。 數據結構是存儲數據的方法,以便算法可以輕松地對其執行操作。
Some common examples of data structures are arrays, stacks, queues, linked lists, trees, graphs, hash tables, and heaps.
數據結構的一些常見示例是數組,堆棧,隊列,鏈表,樹,圖,哈希表和堆。
效率 (Efficiency)
Algorithms are often judged and compared based on their efficiency and the resources they require. One of the most common ways to evaluate an algorithm is to look at its time complexity through a method called Big O notation.
通常根據算法的效率和所需的資源來對其進行判斷和比較。 評估算法的最常見方法之一是通過稱為Big O表示法的方法查看其時間復雜度。
Big O notation is a way to describe the speed or complexity of an algorithm, and shows the worst case number of operations for a given input size. It's important to understand the possible run time for different algorithms, especially when working with large or growing data sets. Big O notation makes it easier to choose the right algorithm for each task.
大O表示法是描述算法速度或復雜度的一種方式,并顯示了給定輸入大小時最壞情況下的運算次數。 重要的是要了解不同算法的可能運行時間,尤其是在處理大型或不斷增長的數據集時。 大O表示法使您更輕松地為每個任務選擇正確的算法。
排序算法 (Sorting Algorithms)
Sorting algorithms come in various flavors depending on your necessity. Some, very common and widely used are:
排序算法根據您的需要而有不同的風格。 一些非常普遍和廣泛使用的是:
快速排序 (Quick Sort)
No sorting discussion is complete without mentioning Quick Sort.
沒有提及快速排序,就沒有完整的排序討論。
合并排序 (Merge Sort)
The Merge Sort algorithm relies on splitting and sorting smaller arrays before merging them into one sorted array.
合并排序算法依賴于在將較小的數組合并為一個排序的數組之前對它們進行拆分和排序。
freeCodeCamp’s curriculum heavily emphasizes creating algorithms. This is because learning algorithms is a good way to practice programming skills. Interviewers most commonly test candidates on algorithms during developer job interviews.
freeCodeCamp的課程非常強調創建算法。 這是因為學習算法是練習編程技能的好方法。 面試官最常在開發人員工作面試中測試算法候選人。
翻譯自: https://www.freecodecamp.org/news/algorithms-explained-what-they-are-and-common-sorting-algorithms/
常見排序算法