개발
-
알고리즘 - 최대공약수 : 유클리드 호제법(Euclidean algorithm) GCDDev/알고리즘 2021. 5. 3. 19:24
유클리드 호제법 (BPEuclidean algorithm) GCD - 최대 공약수 구하기 유클리드 호제법(-互除法, Euclidean algorithm) 또는 유클리드 알고리즘은 2개의 자연수 또는 정식(整式)의 최대공약수를 구하는 알고리즘의 하나이다. 호제법이란 말은 두 수가 서로(互) 상대방 수를 나누어(除)서 결국 원하는 수를 얻는 알고리즘을 나타낸다. - 위키백과 예시 2958, 1088 의 최대공약수를 구해보자 2958을 1088로 나눈다. 정확히 나누어지지 않기때문에 나머지를 구한다. 나머지 -> 782 1088을 782로 나눈다. 정확히 나누어지지 않기때문에 나머지를 구한다. 나머지 -> 306 782을 306로 나눈다. 정확히 나누어지지 않기때문에 나머지를 구한다. 나머지 -> 170 30..
-
알고리즘 - 완전 탐색(Brute-Force Search) : 무차별 대입Dev/알고리즘 2021. 3. 11. 21:16
브루트 포스 (BP) - 완전 탐색 알고리즘 브루트 포스는 Brute(짐승, 이성이 없는) + Force(힘) 짐승 같은 힘, 폭력이라는 뜻으로 무차별적이라는 뜻이다. 브루트 포스는 가장 단순하지만 가능한 모든 경우의 수를 탐색하며 정확도 100%의 중요한 알고리즘이며 '해가 하나 이상 존재 한다.'는 가정을 세우고 가능한 모든 경로를 탐색한다. 정확도가 100%라면 모든 문제를 브루트 포스를 사용하면 되지! 라고 생각했다면 반은 맞고 반은 틀린 문제이다. 물론 브루트 포스를 이용한다면 분명 답은 나올 것이다. 하지만 우리에게는 자원과 시간이 무한하지 않다는 것을 알아야한다. (핸드폰 비밀번호나 자물쇠 비밀번호와 같은 3, 4자리 비밀번호도 풀기 위해 많은 인내가 필요하다.) 브루트 포스를 이용하여 4자..