Blog posts

2022

Binary Search

3 minute read

Published:

While we discuss an algorithm problem, we focus on time and space complexity. O(n), linear time, is a good enough solution. There are a few methods that can beat linear time. However, binary search is one of the O(logN) solutions. The timing that we can use the binary search is whether we discover some kind of monotonicity. Usually, a sorted structure problem is a fine candidate.

Python - Map, Filter, Reduce

4 minute read

Published:

There are three functions I frequently use in Python - map, filter, and reduce. They make complicated code simple, clear, and readable. With these powerful tools, we can reduce the repeated block that we need to apply to the array every time. The for loop and temporary variables are replaced.

Python - Scope (nonlocal, global)

3 minute read

Published:

Python does not need to declare variables. However, when we assign a value to a variable. It would decide its scope, the valid zone where you can see the variable. Python searches a variable from inside to outside.

Python - Yield

1 minute read

Published:

yield is a special keyword like return. It can create an iterator in Python. If you want to get a value from an iterator, you need to use the next function or a for loop. Sometimes, we find that the list index can’t be used directly, map and filter output. It might mean that the output is an iterator yet to be called in the normal way.