Github標(biāo)星86.4K+:常見(jiàn)數(shù)據(jù)結(jié)構(gòu)與算法的Python實(shí)現(xiàn)
有人問(wèn)我數(shù)據(jù)結(jié)構(gòu)與算法怎么學(xué)?
免費(fèi)的我推薦嚴(yán)蔚敏老師的數(shù)據(jù)結(jié)構(gòu)課程,網(wǎng)上可以查到,當(dāng)年考博士時(shí)候?qū)W的就是這個(gè)。
收費(fèi)的我推薦王爭(zhēng)老師的《數(shù)據(jù)結(jié)構(gòu)與算法之美》,內(nèi)容挺全面,學(xué)了應(yīng)該對(duì)算法有幫助。
以上兩個(gè)教程都不是用python實(shí)現(xiàn)的,有群友問(wèn)怎么用python實(shí)現(xiàn)常見(jiàn)的數(shù)據(jù)結(jié)構(gòu)算法?我找到一個(gè)github標(biāo)星86.4k+star的倉(cāng)庫(kù),把各種常見(jiàn)算法用python實(shí)現(xiàn)了,而且還有動(dòng)圖演示,非常值得推薦。(黃海廣)
這個(gè)倉(cāng)庫(kù)用python語(yǔ)言實(shí)現(xiàn)了絕大部分算法,主要是用于教學(xué)目的,因此效率稍微低于工業(yè)界。
倉(cāng)庫(kù)地址:
https://github.com/TheAlgorithms/Python
包含了常見(jiàn)的算法的python實(shí)現(xiàn),如二叉樹(shù)、排序、查找等等。這些是算法工程師必須掌握的技能。
文件目錄

動(dòng)畫(huà)演示

冒泡排序

桶排序

快速排序
典型代碼
(這個(gè)是冒泡排序的代碼):
from __future__ import print_function
def bubble_sort(collection):
????"""Pure implementation of bubble sort algorithm in Python
????:param collection: some mutable ordered collection with heterogeneous
????comparable items inside
????:return: the same collection ordered by ascending
????Examples:
????>>> bubble_sort([0, 5, 3, 2, 2])
????[0, 2, 2, 3, 5]
????>>> bubble_sort([])
????[]
????>>> bubble_sort([-2, -5, -45])
????[-45, -5, -2]
????>>> bubble_sort([-23,0,6,-4,34])
????[-23,-4,0,6,34]
"""
????length = len(collection)
????for i in range(length-1):
????????swapped = False
????????for j in range(length-1-i):
????????????if collection[j] > collection[j+1]:
????????????????swapped = True
????????????????collection[j], collection[j+1] = collection[j+1], collection[j]
????????????if not swapped: break # Stop iteration if the collection is sorted.
????????return collection
if __name__ == '__main__':
????try:
????????raw_input # Python 2
????except NameError:
????????raw_input = input # Python 3
????user_input = raw_input('Enter numbers separated by a comma:').strip()
????unsorted = [int(item) for item in user_input.split(',')]
????print(*bubble_sort(unsorted), sep=',')免費(fèi)的我推薦嚴(yán)蔚敏老師的數(shù)據(jù)結(jié)構(gòu)課程,網(wǎng)上可以查到,用c語(yǔ)言實(shí)現(xiàn),當(dāng)年考博士時(shí)候?qū)W的就是這個(gè)。
收費(fèi)的我推薦極客時(shí)間的《數(shù)據(jù)結(jié)構(gòu)與算法之美》,內(nèi)容挺全面,學(xué)了應(yīng)該對(duì)算法有很大幫助?!?/span>可以閱讀原文購(gòu)買(mǎi)”
倉(cāng)庫(kù)地址:
https://github.com/TheAlgorithms/Python

往期精彩回顧
獲取一折本站知識(shí)星球優(yōu)惠券,復(fù)制鏈接直接打開(kāi):
https://t.zsxq.com/662nyZF
本站qq群704220115。
加入微信群請(qǐng)掃碼進(jìn)群(如果是博士或者準(zhǔn)備讀博士請(qǐng)說(shuō)明):
