이진 탐색(Binary Search) 알고리즘과 시간 복잡도 분석
#include int BSearch(int ar[], int len, int target) { int first = 0; int last = len - 1; int mid; while (first last) { return -1; } int mid; mid = (first + last) / 2; if (ar[mid] == target) { return mid; } else if (target < ar[mid]) return BSearchRec(first, mid - 1, ar, target); else return BSearchRec(mid + 1, last, ar, target); } int main(void) { int index; int arr[] = { 1, 3, 5, 7, 9 }; index ..
더보기