SlideShare una empresa de Scribd logo
Ch 07. 분할 정복
Divide & Conquer
PNU ALCALL 2017 SUMMER
1
도입
7.1
PNU ALCALL 2017 SUMMER
2
분할 정복이란
큰 문제를 분할해서
작은 문제로 만든 뒤
정복한다
PNU ALCALL 2017 SUMMER
3
일반적인 재귀 호출과의 차이
@kugistory.net
PNU ALCALL 2017 SUMMER
4
분할 정복의 구성 요소
1.분할(Divide)
2.병합(Merge)
3.기저 문제(Base Case)
PNU ALCALL 2017 SUMMER
• 작은 문제로 나눌 수 있는가
• 작은 문제의 답을 합칠 수 있는가
• 더 이상 쪼갤 수 없는 최소 문제가 있는가
5
예제: 수열의 빠른 합
PNU ALCALL 2017 SUMMER
• fastsum(n) = 1 + 2 + … + n
=(1 + 2 + … +
𝑛
2
) + ( (
𝑛
2
+ 1) + … + n ) … ⓐ
• ( (
𝑛
2
+ 1) + … + n ) =
𝑛
2
×
𝑛
2
+ fastsum(
𝑛
2
) … ⓑ
• fastsum(n) = ⓐ + ⓑ = 2 * fastsum (
𝑛
2
) +
𝑛2
4
└───
𝑛
2
EA ───┘
6
예제: 수열의 빠른 합
PNU ALCALL 2017 SUMMER
7
예제: 수열의 빠른 합
PNU ALCALL 2017 SUMMER
• O(log N)의 시간복잡도
- 재귀함수, for문 사용시 O(N)
- 확실히 기존의 방법보다 빠름
• N(N+1)/2 는 O(1)
- 하지만 방법 자체는 응용할 수 있음
- 행렬의 거듭제곱이 대표적인 예
8
예제: 행렬의 거듭제곱
PNU ALCALL 2017 SUMMER
9
예제: 행렬의 거듭제곱
PNU ALCALL 2017 SUMMER
• 𝐴 𝑚을 나누는 방법은 𝐴 𝑚−1 × 𝐴 또는 𝐴
𝑚
2 × 𝐴
𝑚
2
• O(N) 과 O(log N)의 차이
- 당연히 빠른 걸 쓰는게 좋습니다
• 𝐴7 = 𝐴3 × 𝐴4 vs 𝐴7 = 𝐴6 × 𝐴
- 전자는 계산횟수 13회, 후자는 12회
- 홀수는 이전처럼 -1해서 짝수로 만드는게 좋음
- 겹치는 계산( 𝐴, 𝐴2) 발생 → Overlapping Subproblem
10
퀵 정렬 / 병합 정렬
PNU ALCALL 2017 SUMMER
• 분할 정복 패러다임 기반
- 작은 배열의 정렬을 통한 큰 배열의 정렬
- 배열을 분리하는 방식의 차이
• 분할 정렬은 배열의 중간 index를 기준으로 나눔
- 분할 과정은 O(1), 병합과정은 O(n), 총 log n개의 단계
- 분할 과정은 빠르고, 병합 과정이 느림
• 퀵정렬은 pivot값과의 대소관계를 기준으로 나눔
- 분할 과정은 O(n), 병합과정은 O(1), 총 log n개의 단계
- 분할과정은 느리고, 병합 과정이 빠름.
- pivot에 따른 편차가 커서 최악의 경우에는 O(𝑛2)을 찍기도 함
11
퀵 정렬 / 병합 정렬
PNU ALCALL 2017 SUMMER
@wikipedia
@saurus2
12
문제: QUADTREE
7.2
PNU ALCALL 2017 SUMMER
13
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
14
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
15
풀이: QUADTREE
7.3
PNU ALCALL 2017 SUMMER
16
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
• 단순하게 풀려면 원본을 구해서 반전 후 재압축
- 원본 크기 제한이 220 × 220
- 메모리 제한 상 불가능
• 압축 화소는 원본이나 반전 이미지나 똑같음
- 압축상태로 뒤집는다면?
17
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
18
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
• 4개의 부분문제로 나눌 수 있음 (분할)
- 총 log (n/2) 개의 단계
- 실제 call 횟수는 문자열의 길이와 같음
• 각각을 뒤집고 상하배치를 바꾸면 원본의 반전이 나옴 (병합)
• ‘b’, ‘w’는 분할할 필요가 없음(기저 사례)
19
쿼드 트리 뒤집기
PNU ALCALL 2017 SUMMER
┐
│
Reverse()를 호출할 때마다 각 사분면의 반전을 불러옴
│
┘
20
PNU ALCALL 2017 SUMMER
21
Q&A
FIN

Más contenido relacionado

Último

암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET
암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET
암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEETSoftwide Security
 
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPTpcupcu20831004
 
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외Jay Park
 
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일justuser0129
 
INU Graduation Powerpoint-Rabbit FootPrint
INU Graduation Powerpoint-Rabbit FootPrintINU Graduation Powerpoint-Rabbit FootPrint
INU Graduation Powerpoint-Rabbit FootPrintahghwo99
 
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptxcho9759
 

Último (6)

암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET
암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET
암호화 보안USB & 외장하드 중앙관리 솔루션 ‘DataLocker SafeConsole’_DATASHEET
 
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT
인천대학교 컴퓨터공학과 아틀란티스 졸업작품 commINUty PPT
 
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외
2024년 5월 27일 개발자 이야기 - AWS 람다의 내부 동작 방식 외
 
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일
인천대학교 캡스톤디자인(2) Pencil me 프레젠테이션 발표자료 파일
 
INU Graduation Powerpoint-Rabbit FootPrint
INU Graduation Powerpoint-Rabbit FootPrintINU Graduation Powerpoint-Rabbit FootPrint
INU Graduation Powerpoint-Rabbit FootPrint
 
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx
캡스톤-디자인-최종-발표-(대상혁) 24년도 졸업작품발표회 ppt.pptx
 

Destacado

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
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Destacado (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

PNU ALCALL 2017 SUMMER STUDY - CH07. DIVIDE & CONQUER ALGORITHM

  • 1. Ch 07. 분할 정복 Divide & Conquer PNU ALCALL 2017 SUMMER 1
  • 3. 분할 정복이란 큰 문제를 분할해서 작은 문제로 만든 뒤 정복한다 PNU ALCALL 2017 SUMMER 3
  • 4. 일반적인 재귀 호출과의 차이 @kugistory.net PNU ALCALL 2017 SUMMER 4
  • 5. 분할 정복의 구성 요소 1.분할(Divide) 2.병합(Merge) 3.기저 문제(Base Case) PNU ALCALL 2017 SUMMER • 작은 문제로 나눌 수 있는가 • 작은 문제의 답을 합칠 수 있는가 • 더 이상 쪼갤 수 없는 최소 문제가 있는가 5
  • 6. 예제: 수열의 빠른 합 PNU ALCALL 2017 SUMMER • fastsum(n) = 1 + 2 + … + n =(1 + 2 + … + 𝑛 2 ) + ( ( 𝑛 2 + 1) + … + n ) … ⓐ • ( ( 𝑛 2 + 1) + … + n ) = 𝑛 2 × 𝑛 2 + fastsum( 𝑛 2 ) … ⓑ • fastsum(n) = ⓐ + ⓑ = 2 * fastsum ( 𝑛 2 ) + 𝑛2 4 └─── 𝑛 2 EA ───┘ 6
  • 7. 예제: 수열의 빠른 합 PNU ALCALL 2017 SUMMER 7
  • 8. 예제: 수열의 빠른 합 PNU ALCALL 2017 SUMMER • O(log N)의 시간복잡도 - 재귀함수, for문 사용시 O(N) - 확실히 기존의 방법보다 빠름 • N(N+1)/2 는 O(1) - 하지만 방법 자체는 응용할 수 있음 - 행렬의 거듭제곱이 대표적인 예 8
  • 9. 예제: 행렬의 거듭제곱 PNU ALCALL 2017 SUMMER 9
  • 10. 예제: 행렬의 거듭제곱 PNU ALCALL 2017 SUMMER • 𝐴 𝑚을 나누는 방법은 𝐴 𝑚−1 × 𝐴 또는 𝐴 𝑚 2 × 𝐴 𝑚 2 • O(N) 과 O(log N)의 차이 - 당연히 빠른 걸 쓰는게 좋습니다 • 𝐴7 = 𝐴3 × 𝐴4 vs 𝐴7 = 𝐴6 × 𝐴 - 전자는 계산횟수 13회, 후자는 12회 - 홀수는 이전처럼 -1해서 짝수로 만드는게 좋음 - 겹치는 계산( 𝐴, 𝐴2) 발생 → Overlapping Subproblem 10
  • 11. 퀵 정렬 / 병합 정렬 PNU ALCALL 2017 SUMMER • 분할 정복 패러다임 기반 - 작은 배열의 정렬을 통한 큰 배열의 정렬 - 배열을 분리하는 방식의 차이 • 분할 정렬은 배열의 중간 index를 기준으로 나눔 - 분할 과정은 O(1), 병합과정은 O(n), 총 log n개의 단계 - 분할 과정은 빠르고, 병합 과정이 느림 • 퀵정렬은 pivot값과의 대소관계를 기준으로 나눔 - 분할 과정은 O(n), 병합과정은 O(1), 총 log n개의 단계 - 분할과정은 느리고, 병합 과정이 빠름. - pivot에 따른 편차가 커서 최악의 경우에는 O(𝑛2)을 찍기도 함 11
  • 12. 퀵 정렬 / 병합 정렬 PNU ALCALL 2017 SUMMER @wikipedia @saurus2 12
  • 14. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER 14
  • 15. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER 15
  • 17. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER • 단순하게 풀려면 원본을 구해서 반전 후 재압축 - 원본 크기 제한이 220 × 220 - 메모리 제한 상 불가능 • 압축 화소는 원본이나 반전 이미지나 똑같음 - 압축상태로 뒤집는다면? 17
  • 18. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER 18
  • 19. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER • 4개의 부분문제로 나눌 수 있음 (분할) - 총 log (n/2) 개의 단계 - 실제 call 횟수는 문자열의 길이와 같음 • 각각을 뒤집고 상하배치를 바꾸면 원본의 반전이 나옴 (병합) • ‘b’, ‘w’는 분할할 필요가 없음(기저 사례) 19
  • 20. 쿼드 트리 뒤집기 PNU ALCALL 2017 SUMMER ┐ │ Reverse()를 호출할 때마다 각 사분면의 반전을 불러옴 │ ┘ 20
  • 21. PNU ALCALL 2017 SUMMER 21 Q&A FIN