Mathlife
Mathlife의 학습 노트
Mathlife
전체 방문자
오늘
어제
  • 분류 전체보기
    • CS
      • 알고리즘
      • 자료구조
      • 운영체제
      • 네트워크
      • 데이터베이스
    • 프로그래밍 언어
      • Java
      • JavaScript
      • C·C++
      • Python
    • Backend
      • Spring
    • Frontend
      • HTML
      • CSS
    • Math
      • Linear Algebra
      • Calculus
    • AI
      • ML
      • DL
      • RL
    • Git

블로그 메뉴

  • 홈
  • 관리
  • 글쓰기
  • 태그
  • 방명록

공지사항

인기 글

태그

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Mathlife

Mathlife의 학습 노트

CS/자료구조

Tree (Introduction)

2022. 4. 18. 00:36

Types of trees

 

기본적으로 tree는 binary tree를 의미한다.

 

 

A full tree is a tree in which every node has either 0 or 2 children.

 

        13

      /     \

    7        8

  /  \

2     4

      /  \

    1    9

 

 

A complete tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

 

         13

      /       \

    7          8

  /  \        /

2     4    9



 

A perfect tree is a binary tree in which all interior nodes have two children and all leaves have the same level.

 

         13

      /       \

    7           8

  /  \        /   \

2     4    3      5

 

 

 

traversal

Pre order traversal (DFS)
- visit root node
- visit left child
- visit right child

In order traversal (DFS)
- visit left child
- visit root
- visit right child

Post order traversal (DFS)
- visit left child
- visit root
- visit right child

BFS

- level 순서대로 방문한다

- tree를 다룰 때는 잘 사용하지 않는다

 

 

DFS는 재귀로 구현하기 때문에 실제로는 그렇게 복잡하지 않다.

 

 

 

Methods for storing binary trees

Arrays

Breadth-first order로 저장한다.

특히 complete tree를 구현할 때 배열을 사용하면 공간의 낭비가 없다.

 

Nodes and references

Tree 클래스와 Node 클래스를 만들어서 구현한다.

'CS > 자료구조' 카테고리의 다른 글

Binary Search Tree (BST)  (0) 2022.04.18
Max Heap  (0) 2022.04.18
Hash (2)  (0) 2022.04.14
Hash (1)  (0) 2022.04.13
Linked List  (0) 2022.04.13
    'CS/자료구조' 카테고리의 다른 글
    • Binary Search Tree (BST)
    • Max Heap
    • Hash (2)
    • Hash (1)
    Mathlife
    Mathlife

    티스토리툴바