Skip to main content

Command Palette

Search for a command to run...

Big O: Why learn to use Big O? What makes good code?

Updated
1 min read

Why learn to use Big O?

Use Big O to measure how and why one data structure is better than others. Why do we use an array rather than an object in some cases? Each data structure has pros and cons.

Big O is used to describe how efficiently the code runs. As the code is more efficient, it saves the company more money.

Big O Cheat Sheet to see time complexity and space complexity:

Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell (bigocheatsheet.com)

What is good code?

Readable: easy for others to read and maintain

Scalable: faster speed and less memory

Which code is the best?

Always consider these three pillars:

  • Readable: clean codes, easy to read and maintain

  • Speed: time complexity

  • Memory: space complexity

Most of the time, speed and memory are a trade-off.

Data Structures + Algorithms = Programs

Data Structures: ways to store data

Algorithms: functions or ways to use data structure

了解資料結構的優缺點,就能在適當的情境使用適當的資料結構,搭配適合的演算法撰寫好的程式碼