Chapter 5
20161016
大綱
- 安裝&使用jupyter on mac
- bubble sort
- 作業
使用jupyter
安裝
- 連線到homebrew的網站, 然後copy上面的指令,打入terminal裡面
- 執行&安裝完成後,在terminal打入 brew install python3
- 安裝完成後,持續在terminal 打入 sudo -h pip3 install -IU numpy scipy jupyter matplotlib
- 安裝完成後,直接在terminal 打入 juypter notebook,應該會看到下圖,那就成功了
重點指令
- 點選右側New, 選擇python3 開啟新檔案
- enter 換行
- shift+ enter 執行區塊內的程式碼
- command + s 儲存編輯檔案(也會自動儲存)
排序演算法
- 演算法定義
- bubble sort - 氣泡排序
- 時間複雜度
- 空間複雜度
作業
請用python 寫出bubble sort(請根據以下程式碼為基礎, TODO就是作業請填好讓它輸出)
class Sort: def swap(self,a,b): #TODO def sort(self,arr): self.arr = arr #TODO return self.arr s = Sort() a = [1,4,3,7,2,9,5,9,3] print (s.sort(a))
- 請找出速度比bubble sort還快的排序演算法(可以google)