Chapter 5

20161016

大綱

  • 安裝&使用jupyter on mac
  • bubble sort
  • 作業

    使用jupyter

安裝

  1. 連線到homebrew的網站, 然後copy上面的指令,打入terminal裡面 install homebrew on mac
  2. 執行&安裝完成後,在terminal打入 brew install python3
  3. 安裝完成後,持續在terminal 打入 sudo -h pip3 install -IU numpy scipy jupyter matplotlib
  4. 安裝完成後,直接在terminal 打入 juypter notebook,應該會看到下圖,那就成功了

    重點指令

  5. 點選右側New, 選擇python3 開啟新檔案
  6. enter 換行
  7. shift+ enter 執行區塊內的程式碼
  8. command + s 儲存編輯檔案(也會自動儲存)

排序演算法

  1. 演算法定義
  2. bubble sort - 氣泡排序
  3. 時間複雜度
  4. 空間複雜度

作業

  1. 請用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))
    
  2. 請找出速度比bubble sort還快的排序演算法(可以google)

results matching ""

    No results matching ""