이분 탐색(Binary Search)
이분 탐색(Binary Search) : 정렬된 원소들에 특정 원소가 존재하는지를 O(log N) 시간에 확인하는 알고리즘 아래 코드는 배열 arr에서 찾고자 하는 값의 index를 확인하는 알고리즘이다. #include using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; typedef tuple tiii; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int arr[10] = {1, 2, 4, 7, 10, 20, 20, 20, 99, 1010}; int x{99}; //찾고자 하는 값 int left{0}, right{10}; while (left ..
알고리즘/algorithm
2023. 4. 24. 14:43