SlideShare a Scribd company logo
1 of 12
Tree
Tree
 공백이 아닌 유한한 원소들의 집합을 일컫는다.
 root라 불리는 특별한 원소가 존재한다.
ROOT
subtree
트리 용어
 노드(node): 트리의 구성 요소
 루트(root): 부모가 없는 노드, 최상위 노드
 서브 트리(subtree) : 하나의 노드와 그 노드들의 자손들로 이루어진 트리
 단말 노드(terminal node) : 자식이 없는 노드
 비단말노드 : 적어도 하나 이상의 자식을 가지는 노드
 레벨(level) : 트리의 각 층의 번호 (레벨은 1부터)
 높이 : 트리의 최대 레벨
 차수 : 노드가 가지고 있는 자식 노드의 개수
이진 트리(Binary Tree)
 유한개의 노드로 구성된 트리이다.
 트리 중에서 자식 노드의 수가 2개 이하인 것을 지칭한다.
 루트 노드와 2개의 부속 노드로 구성된다. 각각 오른쪽 부속 트리, 왼쪽 부속 트리라 부
른다.
 이진 트리는 순서가 존재한다.
A
B
A
B
두 트리는 서로 다른 이진 트리이다.
수학적 표현
/
* +
+ -
a b c d
e f
• ( a + b ) * ( c - d ) / ( e + f )
트리의 노드 수와 높이
 노드의 수를 n, 트리의 높이를 h라고 가정한다.
 노드의 최소 개수 : h ( h 레벨 까지 모든 노드가 하나의 자식만 갖고 있는 경우)
 노드의 최대 개수 : 2ℎ
− 1 (h 레벨 전에 모든 노드가 자식 노드를 갖고 있는 경우)
 ℎ ≤ 𝑛 ≤ 2ℎ
− 1
 𝐥𝐨𝐠 𝟐(𝒏 + 𝟏) ≤ 𝒉 ≤ 𝒏
Full Binary Tree
 단말 노드가 아닌 모든 노드가 2개의 자식 노드를 갖는 트리를 지칭한다.
 노드의 수는 2ℎ
− 1 이다.
a
b c
d e f g
Height 3의 full binary tree 이다.
Complete Binary Tree
단말 노드들이 트리의 왼쪽 부터 채워진 형태
왼쪽 하위 트리 중 하나라도 비워져 있다면 해당하지 않는다.
a
b c
d e
Skewed Binary Tree
 노드가 한 쪽으로 치우친 모습을 가지고 있다.
 길이는 n+1 ~ 2 𝑛
a
c
g
Binary Tree 탐색
Preorder
‒ / * + a b – c d + e f
‒ 노드 -> 왼쪽 서브 트리 -> 오른쪽 서브 트리
Inorder
‒ a + b * c – d / e + f
‒ 왼쪽 서브 트리 -> 노드 -> 오른쪽 서브 트리
Postorder
‒ a b + c d - * e f + /
‒ 왼쪽 서브 트리 -> 오른쪽 서브 트리 -> 노드
/
* +
+ -
a b c d
e f
Priority Queues
각 원소들은 우선 순위를 가지고 있다.
높은 우선 순위를 가진 원소는 낮은 우선순위를 가진 원소보다 먼저 처리 된다.
같은 우선 순위를 가지는 경우 큐에서 그들의 순서에 따라 처리된다.
2
4 3
4 8 7
9
9
9
Min Tree
루트의 원소가 최소값
9
4 8
4 2 7
1
9
3
Max Tree
루트의 원소가 최eo값
Min & Max Heap
Min Heap
complete binary tree 이다.
min tree를 만족
Max Heap
complete binary tree이다.
max tree를 만족

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Datastructure tree

  • 2. Tree  공백이 아닌 유한한 원소들의 집합을 일컫는다.  root라 불리는 특별한 원소가 존재한다. ROOT subtree
  • 3. 트리 용어  노드(node): 트리의 구성 요소  루트(root): 부모가 없는 노드, 최상위 노드  서브 트리(subtree) : 하나의 노드와 그 노드들의 자손들로 이루어진 트리  단말 노드(terminal node) : 자식이 없는 노드  비단말노드 : 적어도 하나 이상의 자식을 가지는 노드  레벨(level) : 트리의 각 층의 번호 (레벨은 1부터)  높이 : 트리의 최대 레벨  차수 : 노드가 가지고 있는 자식 노드의 개수
  • 4. 이진 트리(Binary Tree)  유한개의 노드로 구성된 트리이다.  트리 중에서 자식 노드의 수가 2개 이하인 것을 지칭한다.  루트 노드와 2개의 부속 노드로 구성된다. 각각 오른쪽 부속 트리, 왼쪽 부속 트리라 부 른다.  이진 트리는 순서가 존재한다. A B A B 두 트리는 서로 다른 이진 트리이다.
  • 5. 수학적 표현 / * + + - a b c d e f • ( a + b ) * ( c - d ) / ( e + f )
  • 6. 트리의 노드 수와 높이  노드의 수를 n, 트리의 높이를 h라고 가정한다.  노드의 최소 개수 : h ( h 레벨 까지 모든 노드가 하나의 자식만 갖고 있는 경우)  노드의 최대 개수 : 2ℎ − 1 (h 레벨 전에 모든 노드가 자식 노드를 갖고 있는 경우)  ℎ ≤ 𝑛 ≤ 2ℎ − 1  𝐥𝐨𝐠 𝟐(𝒏 + 𝟏) ≤ 𝒉 ≤ 𝒏
  • 7. Full Binary Tree  단말 노드가 아닌 모든 노드가 2개의 자식 노드를 갖는 트리를 지칭한다.  노드의 수는 2ℎ − 1 이다. a b c d e f g Height 3의 full binary tree 이다.
  • 8. Complete Binary Tree 단말 노드들이 트리의 왼쪽 부터 채워진 형태 왼쪽 하위 트리 중 하나라도 비워져 있다면 해당하지 않는다. a b c d e
  • 9. Skewed Binary Tree  노드가 한 쪽으로 치우친 모습을 가지고 있다.  길이는 n+1 ~ 2 𝑛 a c g
  • 10. Binary Tree 탐색 Preorder ‒ / * + a b – c d + e f ‒ 노드 -> 왼쪽 서브 트리 -> 오른쪽 서브 트리 Inorder ‒ a + b * c – d / e + f ‒ 왼쪽 서브 트리 -> 노드 -> 오른쪽 서브 트리 Postorder ‒ a b + c d - * e f + / ‒ 왼쪽 서브 트리 -> 오른쪽 서브 트리 -> 노드 / * + + - a b c d e f
  • 11. Priority Queues 각 원소들은 우선 순위를 가지고 있다. 높은 우선 순위를 가진 원소는 낮은 우선순위를 가진 원소보다 먼저 처리 된다. 같은 우선 순위를 가지는 경우 큐에서 그들의 순서에 따라 처리된다. 2 4 3 4 8 7 9 9 9 Min Tree 루트의 원소가 최소값 9 4 8 4 2 7 1 9 3 Max Tree 루트의 원소가 최eo값
  • 12. Min & Max Heap Min Heap complete binary tree 이다. min tree를 만족 Max Heap complete binary tree이다. max tree를 만족