Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] 탐색 알고리즘 (순차 / 이진) #20

Closed
hwangJi-dev opened this issue Sep 23, 2022 · 0 comments
Closed

[Algorithm] 탐색 알고리즘 (순차 / 이진) #20

hwangJi-dev opened this issue Sep 23, 2022 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Sep 23, 2022

💡 순차탐색

➡️ 리스트 안에 있는 특정한 데이터를 찾기 위해 앞에서부터 데이터를 하나씩 차례대로 확인하는 방법

  • 정렬되지 않은 리스트에서 데이터를 찾아야 할 때 사용한다.
  • 리스트 내에 데이터가 아무리 많아도 시간만 충분하다면 항상 원하는 원소(데이터)를 찾을 수 있다는 장점이 있음!
  • 데이터의 정렬 여부와 관계없이 가장 앞에 있는 원소부터 하나씩 확인해야 한다는 점이 특징이므로
    • 데이터 개수가 N개일 대 최대 N번의 비교 연산을 수행한다.
  • 시간 복잡도 : O(N)

💡 이진탐색

➡️ 탐색 범위를 반으로 좁혀가며 빠르게 탐색하는 알고리즘

  • 배열 내부의 데이터가 정렬되어 있어야만 사용할 수 있다.
  • 탐색 범위를 절반씩 좁혀가며 데이터를 탐색하는 특징이 있어 데이터를 매우 빠르게 탐색한다.
  • 한 번 확인할 때마다 확인하는 원소의 개수가 절반씩 줄어든다는 점에서 시간 복잡도가 O(logN)이다.
  • 시간 복잡도 : O(logN)
  • ⭐️⭐️ 탐색 범위가 2,000만을 넘어가면 이진 탐색으로 문제를 접근하자.

[이진 탐색의 구현 방법]

이진 탐색은 위치를 나타내는 변수 3개를 사용한다.
-> 탐색 범위의 시작점, 끝점, 중간점
찾으려는 데이터와 중간점 위치에 있는 데이터를 반복적으로 비교해서 원하는 데이터를 찾는다.!!!!

  1. 재귀함수를 사용하는 방법

  2. 반복문을 이용하는 방법

@hwangJi-dev hwangJi-dev self-assigned this Sep 23, 2022
@hwangJi-dev hwangJi-dev changed the title [Algorithm] 이진 탐색 [Algorithm] 탐색 알고리즘 (순차 / 이진) Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant