Java 시간 복잡도와 공간 복잡도에 대해서

이정빈·2023년 11월 11일
0

Java Algorithm

목록 보기
1/8

🔴 Time Complexity


: This means like running time when my code work is by Input and Operation time of it.

📌 this is a ruuning time by input.

whenever we would like to show time complexity, we use Big-O notation which is the algorithm that means it's effective and productive, whem input is lower.

🔎 More details on Time Complexity

We can make a list to distribute on each case to Three.

  • Best Case
    It's a fastest case when we're in putting a best input.
  • Worst Case
    It's a lowest case in reverse compared than the Best case.
  • Average Case
    Considering a bunch of case we can assume in advance. And get a total operating times and divide with it.
    ➡️ Most of case we're tryna use Worst case.

🔴 Space Complexity

: this is a vital memorial Storage for running my code. it basically considered with Time-complexity together. We need to keep this in our mind, Space Complexity is able to be different and depend on the circumstance where we run a code.

As a reasult, we have to think of them at the same time :)

🔴 Big-O notation

: this is a way to be notated Operation time and how the complexity increases on our compiler by the size of Algorithm. We can also find out effective way for best situation of this code.

📌 Big-O Complexity Chart

We can compare our lots of algorithm which one is gonna be effective by BCC(Big-O Complexity Chart).

This graph is gonna be made by Time complexity like down below.

✅ Time Complexity + Big-O


this picture which looks like an equation means effectiveness will be reduced going to the right side.

🔎 More details on getting a Time complexity.

I'll just use Korean cuz idk how to say this sentences in English.

  • 하나의 루프를 사용하여 단일 요소 집합을 반복하는 경우 : O(n)
  • 컬렉션의 정반 이상을 반복하는 경우 : O(n/2) ➡️ O(n)
  • 두 개의 다른 루프를 사용하여 두 개의 개별 콜렉션을 반복하는 경우 : O(n+m) ➡️ O(n)
  • 두 개의 중첩 루프를 사용하여 단일 컬렉션을 반복하는 경우 : O(n²)
  • 두 개의 중첩 루프를 사용하여 두 개의 다른 콜렉션을 반복하는 경우 : O(n * m) ➡️ O(n²)
  • 컬렉션 정렬을 사용하는 경우 : O(n*log(n))

✅ Space Complexity + Big-O

We can think of this easily. It's a result by used memorial Stoage of my Algorithm.

For example )
if we got an array which size is n, and also my algorithm makes an output, n*n, the Space Complexity is gonna be n²

More other examples of Time Complexity.



reference
1. Time-complexity
2. Time-complexity graph by Big-O

profile
백엔드 화이팅 :)

0개의 댓글