This article mainly focuses on the big picture of traditional machine learning algorithms; as for the details, please check or search on your own.

What is the difference between regression and classification?
There are both types of supervised machine learning. The main difference is that the output variable in the regression is numerical (continuous) while that for classification is categorical (discrete).

What is linear regression? [supervised, regression, mean square error]
We find the relationship between independent and dependent variables by fitting the regression line which is polynomial equation. …

In this article, I would like to discuss programming skills, including errors, regularization, and different types of neural networks.

How are weights initialized in a network?
Initializing all weights to 0: This makes your model similar to a linear model. All the neurons and every layer perform the same operation, giving the same output and making the deep net useless.
Initializing all weights randomly: Here, the weights are assigned randomly by initializing them very close to 0. It gives better accuracy to the model since every neuron performs different computations. This is the most commonly used method.

What is the…

In this article, I will focus more on algorithms and theory, including neural network itself, activation function, gradient descent, learning rate, and loss function. And the next piece would discuss programming skills.

What are the steps of deep learning?
1. create a function (neural network)
2. evaluate the goodness of the function
3. pick the best function as the final question answer machine

What is a neural network?
Neural network simulates the ways human learn but is much simpler. It can be imagined as a function. When you feed it input, you are supposed to get an output. …

238. Product of Array Except Self

Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

### Reverse Product List: Time - O(n) / Space - O(n)
import numpy as np
length = len(nums)
tableL = np.ones((length+1, ), dtype="int")
tableR = np.ones((length+1, ), dtype="int")
for k in range(length):
tableL[k+1] = tableL[k] * nums[k]
tableR[length-k-2] = tableR[length-k-1] * nums[length-k-1]
return list(tableL * tableR)[:-1]

240. Search a 2D Matrix II

Write an efficient algorithm that searches for a target value in…

200. Number of Islands

Given an m x n 2d grid map of '1's (land) and '0's (water), return the number of islands.

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

### Breadth First Search: Time - O(n**4) / Space - O(n**2)
def mark(pos):
direction = [(1,0), (0,1), (-1,0), (0,-1)]
stack = [pos]
while stack:
pos = stack.pop()
grid[pos[0]][pos[1]] = "0"
for k in range(4): tmp_pos = (pos[0]+direction[k][0], pos[1]+direction[k][1]) if not 0 <= tmp_pos[0] < len(grid) : continue…

150. Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Valid operators are +, -, *, /. Each operand may be an integer or another expression.


  • Division between two integers should truncate toward zero.
  • The given RPN expression is always valid. That means the expression would always evaluate to a result and there won’t be any divide by zero operation.
### Stack: Time - O(n) / Space - O(n) stack = [] for token in tokens: try: stack.append(int(token)) except: val1 = stack.pop() val2 = stack.pop() if token == "+": stack.append(int(val2 + val1)) if…

125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

### One Pass: Time - O(n) / Space - O(n)
palindrome = ""
for char in string:
if char.isalnum(): palindrome += char.lower()
return palindrome == palindrome[::-1]

127. Word Ladder

A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words such that:

  • The first word in the sequence is beginWord.
  • The last word in the sequence is endWord.
  • Only one…

84. Largest Rectangle in Histogram

Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

### Stack: Time - O(n**2) / Space - O(n)
stack = [-1]
result = 0
for idx in range(len(heights)):
while heights[idx] < heights[stack[-1]]:
h = heights[stack[-1]] # maximum height
w = idx - 1 - stack[-2] # till the further idx (smaller than "h")
result = max(result, w*h)
return result

88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1

49. Group Anagrams

Given an array of strings strings, group the anagrams together. You can return the answer in any order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

### Sorting: Time - O(nklogk) / Space - O(nk)
result = {}
for string in strings:
sort = tuple(sorted(string))
if sort not in result:
result[sort] = []
return result.values()

50. Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n (i.e. xn).

### Recursion: Time - O(logn) / Space…

21. Merge Two Sorted Lists

Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

### Loop: Time - O(m+n) / Space - O(1)
head = ListNode()
tail = head
while l1 or l2:
if l2 is None or (l1 is not None and l1.val <= l2.val): = l1
l1 =
elif l1 is None or (l2 is not None and l1.val >= l2.val): = l2
l2 = = None
tail =
### Recursion if…


BS in Computer Science, National Taiwan University (NTU); MS in Artificial Intelligence, National University of Singapore (NUS)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store