Zziny 2023. 1. 23. 18:29

Two rules of good code 

  1. Readable
  2. Scalable

Scalable

Scalable means worrying about large inputs.

  • Speed - Time Complexity
  • Memory - Space Complexity

Memory - Heap & Stack

Heap: usually where we store variables that we assign values

Stack: usually where we keep track of our function calls

 

What causes Space complexity?

  • Variables
  • Data Structures
  • Function Call
  • Allocations

 

* talking about memory or space complexity is very similar to talking about the time cost

* sometimes there's a tradeoff between saving time and saving space

 

The important thing is that Big O is about how we can scale.

 

It doesn't necessarily mean that O(n) is better than zero and squared because scalability wasn't the only factor.

>> Readability is something that we are concerned with as well.

>> Sometimes readability may be matters more than scalability.

>> Maybe time complexity is less important than space complexity.

 

Premature optimization can be the root of all evil.
(성급한 최적화는 모든 악의 근원이 될 수 있다.)

-Donald Knuth, <<The Art of Computer Programming>>

If we have 20 items in the string, what do you think the Big O notation of this is?

>> The answer to this is depends.

>> It depends on the language that you're working with. we need to know how the method works on the string here.

Notation Rule

  1. Always worst Case
  2. Remove Constants
  3. Different inputs should have different variables.O(a+b).
    • A and B arrays nested would be O(a*b)
      • + for steps in order
      • * for nested steps
  4. Drop Non-dominant terms

Big-O Complexity Chart

https://www.bigocheatsheet.com/

 

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

Know Thy Complexities! Hi there!  This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science.  When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting t

www.bigocheatsheet.com

<Premature optimization>