Backtracking(백트래킹)

2011. 8. 6. 10:32·Algorithms/Backtracking

Basic Concept


If you were trying to find your way through the well-known maze of hedges by Hampton Court Palace in England, you would have no choice but to follow a hopeless path until you reached a dead end. When that happened, you’d go back to a fork and pursue another path. Think how much easier it would be if there were a sign, positioned a short way down a path, that told you that the path led to nothing but dead ends. If the sign were positioned near the beginning of the path, the time savings could be enormous, because all forks after that sign would be eliminated from consideration. This means that not one but many dead ends would be avoided. There are no such signs in the famous maze of hedges or in most maze puzzles. However, as we shall see, they do exist in backtracking algorithms.

 

👉 백트래킹의 개념을 의미하는 미로그림이 챕터 앞부분에 실려있다. 미로 속에서 길을 찾다가 막다른 곳에 조우했다면 가장 최근의 갈림길로 돌아가 다른 길을 갈 것이다.
갈림길의 시작지점에 막힌 곳으로 가는 경로가 표시되어 있다면, 표지판 뒤에 있는 모든 분기점들을 고려대상에서 제외시키기 때문에 탐색시간을 엄청나게 절약할 수 있을 것이다. 백트래킹 알고리즘에는 그런 표시가 존재한다.

 

 

The Backtracking Technique


Backtracking is used to solve problems in which a sequence of objects is chosen from a specified set so that the sequence satisfies some criterion. Backtracking is a modified depth-first search of a tree. Although the depth-first search is defined for graphs in general, we will discuss only searching of trees, because backtracking involves only a tree search.

 

 

A preorder tree traversal is a depth-first search of the tree. This means that the root is visited first, and a visit to a node is followed immediately by visits to all descendants of the node. Although a depth-first search does not require that the children be visited in any particular order, we will visit the children of a node from left to right in the applications in this chapter. The nodes are numbered in the order in which they are visited.

Notice that in a depth-first search, a path is followed as deeply as possible until a dead end is reached. At a dead end we back up until we reach a node with an unvisited child, and then we again proceed to go as deep as possible.

 

👉 백트랙킹 기법은 지정된 집합(a specified set)에서 어떤 기준(creiterion)을 만족하면서 그 집합에 속한 대상의 순서(sequence)를 선택하는 문제를 푸는데 사용된다. 이 기법은 수정 된 깊이우선탐색(depth-first search)이다.
깊이우선탐색은 트리 방문방법 중 하나인 전위순회(preorder)와 같다. 루트가 되는 노드를 먼저 방문한 뒤, 그 노드의 모든 후손 노드들을 차례로(일반적으로 왼쪽에서 오른쪽) 방문한다.
깊이우선탐색에서의 방문경로는 더 이상 갈 수 없는 노드까지 내려간다. 그렇게 내려간 마지막 노드에서 다시 방문하지 않은 자식노드가 있는 노드로 되돌아가고, 거기서부터 다시 가능한 깊이까지 내려간다.

 

Pseudocode 

There is a simple recursive algorithm for doing a depth-first search. Because we are presently interested only in preorder traversals of trees, we give a version that specifically accomplishes this. The procedure is called by passing the root at the top level.

  • Depth-first search
void depth_first_tree_search (node v)
{   
    node u;
    visit v;    
    for (each child u of v)     
        depth_first_tree_search(u)
}

 

'Algorithms > Backtracking' 카테고리의 다른 글

Backtracking with the 0-1 Knapsack problem(Depth-First Search)(0-1 배낭 문제-깊이우선탐색)  (2) 2011.12.24
Graph Coloring(그래프 채색)  (0) 2011.12.23
The Sum-of-Subsets Problem(부분집합의 합 구하기)  (2) 2011.12.23
n-Queens Problem(n-퀸 문제)  (0) 2011.10.03
'Algorithms/Backtracking' 카테고리의 다른 글
  • Backtracking with the 0-1 Knapsack problem(Depth-First Search)(0-1 배낭 문제-깊이우선탐색)
  • Graph Coloring(그래프 채색)
  • The Sum-of-Subsets Problem(부분집합의 합 구하기)
  • n-Queens Problem(n-퀸 문제)
Zakarum
Zakarum
  • Zakarum
    Zakr. _archives
    Zakarum
  • 전체
    오늘
    어제
    • Zakarum
      • Cogito, ergo sum
      • Algorithms
        • Eff, Anal, and Order
        • Divide-and-Conquer
        • Dynamic Programming
        • The Greedy Approach
        • Backtracking
        • Branch-and-Bound
      • Et Cetera
        • Job-seeking
      • Not Public
        • MBA
        • Finance
        • 2.3. Civil•Commercial Law
        • 2.2. Credit Analysis (Basic..
        • 2.4. Foreign Exchange
        • 2.1. Accounting Principles ..
        • ITSM
        • Theory of NP
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글쓰기
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    대만여행
    일본여행
    분기한정법
    분할정복법
    ITIL
    SNU MBA
    외국환
    자바스크립트
    재무회계
    네트워크
    백트래킹
    회계원리기초1
    0-1 배낭 문제
    os concept
    회계원리기초2
    이탈리아여행
    동적계획법
    소프트웨어공학
    최소신장트리
    미국여행
    민상법기초3
    p-np problem
    금융IT 채용정보
    베트남여행
    process scheduling
    민상법기초1
    알고리즘
    process management
    신용분석기초
    탐욕 알고리즘
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
Zakarum
Backtracking(백트래킹)
상단으로

티스토리툴바