Algorithm

Quote from COMP90038_2021_SM1: Algorithms and Complexity courseware, by Dr. Michael Kirley

ClosestPair

二维空间里n个点,找到一对距离最短的点
image.png
image.png

  1. def ClosestPair(nodes):
  2. min = float("inf") //positive infinity
  3. n = len(nodes)
  4. for i in range(0, n - 1):
  5. xi, yi = nodes[i]
  6. for j in range(i + 1, n):
  7. xj, yj = nodes[j]
  8. d = ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
  9. if d < min:
  10. min = d
  11. pi = i
  12. pj = j
  13. return pi, pj
  14. def test():
  15. N = [(1, 3), (5, 8), (-2, 7), (-9, 0), (-4, -6)]
  16. print(ClosestPair(N))

StringMatching

很像KMP字符串匹配

  1. def StringMatching(pattern, text):
  2. m = len(pattern)
  3. n = len(text)
  4. for i in range(0, n - m + 1):
  5. j = 0
  6. while j < m and pattern[j] == text[i + j]:
  7. j = j + 1
  8. if j == m:
  9. return i
  10. return -1
  11. def test():
  12. print(StringMatching("hello", "abchellodef"))

Review

Starting a Codebase on Github

How to push Code to Github

Understanding the Github Flow

tells basic process, like opening a pull request, deploy, merge on GitHub projects
image.png

Tip

Analyse & Capture The Packets in Wireshark

Type Conversions in Java

image.png
cast 投,抛;计算
E.g., short x; int y = 50; x = (short) y;
E.g., double average = (double) sum / count;

Java Scanner Class

Share

Java Class VS JavaScript Prototype

image.png

Fundamental Algorithms’ Visualization

involves the basic idea of algorithms
image.pngimage.png