Skip to content

Commit

Permalink
Merge branch 'feature/week12'
Browse files Browse the repository at this point in the history
  • Loading branch information
LKHcoding committed Feb 22, 2025
2 parents 8ad770a + 19b5c49 commit ad21fb9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function solution(N) {
const results = [];

function backtrack(sum, selectedNums, start) {
if (sum === 10) {
results.push(selectedNums);
return;
}

for (let i = start; i <= N; i++) {
if (sum + i <= 10) {
backtrack(sum + i, [...selectedNums, i], i + 1);
}
}
}

backtrack(0, [], 1);
return results;
}

console.log(solution(5));
20 changes: 20 additions & 0 deletions src/LKHcoding/jsAlgorithmStudy/week12/Summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 백트래킹

## 백트래킹이란?

어떤 가능성이 없는 곳을 알아보고 되돌아 가는 것을 백트래킹 이라 한다.

## 백트래킹 알고리즘이란?

가능성이 없는 곳에서는 되돌아가고,
가능성이 있는 곳을 탐색하는 알고리즘을 백트래킹 알고리즘이라 한다.
가능성이 없는 곳은 배제할 수 있으므로 단순 완전 탐색보다는 효율적이다.

## 유망 함수란?

해를 찾기위해 탐색해야 하는 경우의 수 중
해를 찾을 수 없는 케이스는 배제 시키는것 처럼(탐색할 필요가 없음)
특정 조건을 정의 하는 것을 유망 함수를 정의한다고 한다.

> 1,2,3,4 중 2개를 뽑아 합을 구해서 6 초과하는 해를 찾아야 할때
> 첫번째 숫자가 1 or 2면 탐색조차 필요없다

0 comments on commit ad21fb9

Please sign in to comment.