선형
-
[개념] 검색알고리즘 (선형 VS 이진)알고리즘 2023. 11. 4. 11:44
검색 알고리즘 우리는 프로젝트를 하던 알고리즘 문제를 풀던 어떠한 값을 찾기위해서 배열 또는 객체를 만들어서 그 값을 찾는 로직을 구현을 하는 모습을 자주 보인다. 그렇다면 이러한 검색을 하기위해서 가장 최적의 방법은 무엇일까? 에 대한 고민을 한번쯤은 해봐야 한다. 선형검색 알고리즘(linear search) 아래 이미지는 선형검색 알고리즘의 실행 과정을 보여준다. 선형검색 알고리즘은 0번째 index부터의 비교를 통해서 값을 찾을 수 있다 장점 값을 추가할 때 강점이 있음 간단하고 직관적인 코드 (걍 반복문 돌리면 됨) 단점 크기가 커질수록 step이 비례적으로 증가하기때문에 점진적으로 비효율적으로 되어버림 최악의수로는 배열의 마지막 index에 위치한 값을 찾는 것이다. function linear..