SlideShare a Scribd company logo
1 of 13
2016.11.12
1주차
Insertiojn sort,
Bubble sort,
Selection sort
1. Insertion sort
2. Bubble sort
3. Selection sort
목차
1. Insertion Sort – 삽입 정렬
레코드를 이미 정렬된 배열의 적절한 위치에 “삽입”
3 / 141. Insertion Sort
x
1) 배열 S
: i번째 슬롯에 있는 키 값을 x라고 가정합니다.
S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
2) (i-1)번째, (i-2)번째 슬롯에서 부터 차례로
x보다 작은 키를 찾을 때까지 비교를 반복합니다.
1. Insertion Sort – 삽입 정렬
4 / 141. Insertion Sort
x
1) S[j] : x보다 작은 키가 위치한 슬롯이라 가정합니
다.
S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
2) (j+1) ~ (i-1)번째 슬롯에 있는 키들을
(j+2) ~ i번째 슬롯으로 옮깁니다.
x
S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
1. Insertion Sort – 삽입 정렬
5 / 141. Insertion Sort
x
S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
3) (j+1)번째 슬롯에 x를 삽입합니
다.
x
S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
4) 이 과정을 i=2에서부터 i=n까지 반복합
니다.
1. Insertion Sort in C
6 / 141. Insertion Sort
1. 정수를 입력받아
배열 array에 대입 → 출력
1. Insertion Sort in C
7 / 141. Insertion Sort
2. For문
: 정렬할 범위 넓혀 나가기
- array의 처음부터 끝까지
(1 ~ n-1)
- 변수 d : insert position
3. While문 반복
: 새로운 요소의 위치 찾기
- Insert position이 0보다 클 때
- 삽입 위치를 찾지 못했을때까
지
- 앞으로 이동하면서 자신보다
더 큰 값이면 자리를 교체
* printf문은 이후 생략
2. Bubble Sort
옆과 비교해서 왼쪽이 더 크면 좌우 교환하는 정렬
8 / 142. Bubble Sort
2. Bubble Sort in C
9 / 142. Bubble Sort
1. 정수를 입력받아
배열 array에 대입 → 출력
2. Bubble Sort in C
10 / 142. Bubble Sort
2. array 배열의 첫번째 인덱스부터 바로 옆 오른쪽 인덱스와 크기를
비교
3. 비교 후 왼쪽의 요소가 클 경우 좌우 교환
3. Selection Sort
정렬되지 않은 데이터들에서,
가장 작은 데이터를 찾아 가장 앞의 데이터와 교환하는 정렬
11 / 143. Selection Sort
3. Selection Sort in C
1. 정수를 입력받아
배열 array에 대입 → 출력
12 / 143.Selection Sort
3. Selection Sort in C
2. for문
c : array 배열의 첫번째 인덱스
부터
3. 중첩 for문
: 가장 작은 값이 들어있는 배열
의 인덱스 찾기 & position에 저
장
4.position과 c의 위치 교환
13 / 143.Selection Sort

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...
 

[알고리즘 스터디 1주차]삽입정렬/버블정렬/선택정렬

  • 2. 1. Insertion sort 2. Bubble sort 3. Selection sort 목차
  • 3. 1. Insertion Sort – 삽입 정렬 레코드를 이미 정렬된 배열의 적절한 위치에 “삽입” 3 / 141. Insertion Sort x 1) 배열 S : i번째 슬롯에 있는 키 값을 x라고 가정합니다. S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i] 2) (i-1)번째, (i-2)번째 슬롯에서 부터 차례로 x보다 작은 키를 찾을 때까지 비교를 반복합니다.
  • 4. 1. Insertion Sort – 삽입 정렬 4 / 141. Insertion Sort x 1) S[j] : x보다 작은 키가 위치한 슬롯이라 가정합니 다. S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i] 2) (j+1) ~ (i-1)번째 슬롯에 있는 키들을 (j+2) ~ i번째 슬롯으로 옮깁니다. x S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i]
  • 5. 1. Insertion Sort – 삽입 정렬 5 / 141. Insertion Sort x S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i] 3) (j+1)번째 슬롯에 x를 삽입합니 다. x S[j] S[j+1] S[j+2] ………………………… S[i-2] S[i-1] S[i] 4) 이 과정을 i=2에서부터 i=n까지 반복합 니다.
  • 6. 1. Insertion Sort in C 6 / 141. Insertion Sort 1. 정수를 입력받아 배열 array에 대입 → 출력
  • 7. 1. Insertion Sort in C 7 / 141. Insertion Sort 2. For문 : 정렬할 범위 넓혀 나가기 - array의 처음부터 끝까지 (1 ~ n-1) - 변수 d : insert position 3. While문 반복 : 새로운 요소의 위치 찾기 - Insert position이 0보다 클 때 - 삽입 위치를 찾지 못했을때까 지 - 앞으로 이동하면서 자신보다 더 큰 값이면 자리를 교체 * printf문은 이후 생략
  • 8. 2. Bubble Sort 옆과 비교해서 왼쪽이 더 크면 좌우 교환하는 정렬 8 / 142. Bubble Sort
  • 9. 2. Bubble Sort in C 9 / 142. Bubble Sort 1. 정수를 입력받아 배열 array에 대입 → 출력
  • 10. 2. Bubble Sort in C 10 / 142. Bubble Sort 2. array 배열의 첫번째 인덱스부터 바로 옆 오른쪽 인덱스와 크기를 비교 3. 비교 후 왼쪽의 요소가 클 경우 좌우 교환
  • 11. 3. Selection Sort 정렬되지 않은 데이터들에서, 가장 작은 데이터를 찾아 가장 앞의 데이터와 교환하는 정렬 11 / 143. Selection Sort
  • 12. 3. Selection Sort in C 1. 정수를 입력받아 배열 array에 대입 → 출력 12 / 143.Selection Sort
  • 13. 3. Selection Sort in C 2. for문 c : array 배열의 첫번째 인덱스 부터 3. 중첩 for문 : 가장 작은 값이 들어있는 배열 의 인덱스 찾기 & position에 저 장 4.position과 c의 위치 교환 13 / 143.Selection Sort