DFS(깊이우선탐색)

    9/26 (화) 이진 트리 후위 순회 구현 TIL

    공부한 것LeetCode #145. Binary Tree Postorder TraversalLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/binary-tree-postorder-traversal/description/후위 순회(Postorder traversal): ‘나’와 두 자식을 기준으로, “왼 자식 → 오른 자식 → 나” 순..

    9/25 (월) 이진 트리 전위 순회와 중위 순회 구현하기 TIL

    공부한 것LeetCode #144. Binary Tree Preorder TraversalLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/binary-tree-preorder-traversal/description/전위 순회(Preorder traversal): ‘나’와 두 자식을 기준으로, “나 → 왼 자식 → 오른 자식” 순으로 ..

    9/12 (화) 재귀를 스스로 풀다 TIL

    공부한 것LeetCode #1448. Count Good Nodes in Binary TreeLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/count-good-nodes-in-binary-tree/⇒ 어제에 이어서 스스로 풀어본 해답이 통했다! (스택을 이용한 해답은 다른 사람들의 해답을 참고함.) 재귀를 이용한 DFS도, 스택을 ..

    9/5 (화) 재귀함수와 백트래킹 TIL

    9/5 (화) 재귀함수와 백트래킹 TIL

    공부한 것오늘은 재귀함수에 대한 유튜브 강의를 듣다가 백트래킹(Backtracking)이라는 용어가 나오길래 정확히 어떤 건지 궁금하여 찾아보았다. 백트래킹(Backtracking, 퇴각검색)길이 여러 갈래로 나뉘어진 재귀호출이다. 가능한 모든 경우의 수를 낱낱이 탐색할 때 사용한다. 주로 다음과 같은 경우에 백트래킹을 적용한다: 일정한 크기의 조건들이 주어지고, 그 안에서 완전탐색을 통해 최적비용 또는 최적경로를 탐색해야 하는 경우.각 조건에서 선택할 수 있는 경우의 수가 정해져 있을 경우 (이차원 배열 등)예제 1) 주사위 던지기: 주사위를 N개 던져서 나올 수 있는 경우의 수를 모두 출력하기코드: // 주사위를 N번 던진 결과의 모든 조합을 배열 형태로 출력하기. // 예를 들어 3번 던진 결과는 ..

    9/1 (금) 트리 문제 기초 접근법을 3가지로 정리하다 TIL

    공부한 것LeetCode #226. Invert Binary TreeLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/invert-binary-tree/description/트리를 뒤집어 반환하는 문제이다. 각 노드별로 좌우 자식을 바꿔주면 되고 이는 결국 노드를 전부 방문해야 한다는 얘기가 된다. 기초적인 전위 순회(Preorder ..

    8/31 (목) 트리 순회 3형제는 깊이 우선 탐색(DFS)의 일종이다 TIL

    공부한 것LeetCode #572. Subtree of Another TreeLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/subtree-of-another-tree/description/처음 생각해낸 방법이 대부분의 사람들이 채택한 로직임을 알게 되어서 뿌듯했다. DFS와 BFS에 대하여: 트리나 그래프와 같은 자료구조에서 노드를..

    8/30 (수) 깊이 우선 탐색(DFS) 예제 코드TIL

    공부한 것LeetCode #110. Balanced Binary TreeLeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.https://leetcode.com/problems/balanced-binary-tree/description/이상한 테스트 케이스 하나가 있는 것으로 결론 내리고 마무리 지었다. 배운 것깊이 우선 탐색(DFS)에 해당하는 예제와 생각 과정은 다음과 같다: 로직: 1..