<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>밍의 기록들 </title>
    <link>https://livecoding.tistory.com/</link>
    <description>altiora petamus  ; 더 높은 곳을 찾게 하소서</description>
    <language>ko</language>
    <pubDate>Sat, 9 May 2026 23:41:06 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>민쓰</managingEditor>
    <item>
      <title>altiora petamus -</title>
      <link>https://livecoding.tistory.com/notice/70</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;&lt;b&gt;altiora petamus -&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;더 높은 곳을 찾게 하소서&lt;/span&gt;&lt;/p&gt;</description>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/notice/70</guid>
      <pubDate>Fri, 28 Sep 2018 21:56:01 +0900</pubDate>
    </item>
    <item>
      <title>[문제] 벽 부수고 이동하기</title>
      <link>https://livecoding.tistory.com/60</link>
      <description>&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;문제&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 667px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996EFE4D5B9F50A322&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996EFE4D5B9F50A322&quot; width=&quot;667&quot; height=&quot;643&quot; filename=&quot;maze 4.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 675px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9914344D5B9F50A414&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9914344D5B9F50A414&quot; width=&quot;675&quot; height=&quot;546&quot; filename=&quot;maze 5.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;소스코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.*;

class Pair2{
	int x;
	int y;
	boolean c ; // 부쉈다면 ture, 부수지 않았다면 false
	
	Pair2(int x, int y, boolean c){
		this.x = x;
		this.y = y;
		this.c = c;
	}
}
public class Maze2 {
	public static final int[] dx = {0,0,1,-1};
	public static final int[] dy = {1,-1,0,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] input = sc.nextLine().split(&quot; &quot;);
		int n = Integer.parseInt(input[0]); 
		int m = Integer.parseInt(input[1]); 
		
		int[][] map = new int[n][m];
		for(int i=0; i&amp;lt;n; i++){
			String[] line = sc.nextLine().split(&quot; &quot;);
			for(int j=0; j&amp;lt;m; j++){
				map[i][j] = Integer.parseInt(line[j]);
			}
		}
		int[][] dist = new int[n][m]; // 거리
		boolean[][] check = new boolean[n][m]; // 벽을 부수지 않은 차원
		boolean[][] check2 = new boolean[n][m]; // 벽을 부순 후의 차원
		
		Queue&amp;lt;Pair2&amp;gt; q = new LinkedList&amp;lt;Pair2&amp;gt;(); //bfs
		q.add(new Pair2(n-1, 0, false));
		check[n-1][0] = true;
		dist[n-1][0] = 0;
		
		while(!q.isEmpty()){
			if(dist[0][m-1] != 0){ // 지점에 도착했다면 while문을 멈춤
				break;
			}
			Pair2 p = q.remove();
			int x = p.x;
			int y = p.y;
			boolean c = p.c;
			for(int k=0; k&amp;lt;4; k++){
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(0&amp;lt;=nx &amp;amp;&amp;amp; nx&amp;lt;n &amp;amp;&amp;amp; 0&amp;lt;=ny &amp;amp;&amp;amp; ny&amp;lt;m){ // 길이 있을 경우
					if(c == true){ // 벽을 이미 1번 부쉈을 경우
						if(check[nx][ny] == false &amp;amp;&amp;amp; check2[nx][ny] == false  &amp;amp;&amp;amp; map[nx][ny] == 0){
							q.add(new Pair2(nx, ny, c)); // 벽을 이미 부쉈기 때문에 그대로 
							dist[nx][ny] = dist[x][y] + 1; // 거리를 1 더해줌
							check2[nx][ny] = true; // 벽을 부순 후의 차원에 갔던 길을 true로 표시					
						}
					}
					else{ // 벽을 부순 적이 없을 경우
						if(check[nx][ny] == false){ // 가지 않았던 길일 경우
							if(map[nx][ny] == 0){ // 벽이 없는 경우
								q.add(new Pair2(nx, ny, c)); // 벽을 수지 않았기 때문에 그대로 
							}
							if(map[nx][ny] ==1){ // 벽이 있는 경우
								q.add(new Pair2(nx, ny, true)); // 벽을 부쉈기 때문에 true
							}
							dist[nx][ny] = dist[x][y] + 1; // 거리를 1 더해줌
							check[nx][ny] = true; // 갔던 길을 true로 표시
						}
					}
				}
			}
		}
		System.out.println(dist[0][m-1]);
	}
}
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;풀이&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;미로 찾기 문제와 동일한 방식으로 풀었지만 벽을 한 번 부술 수 있기 때문에 조금 더 생각이 필요한 문제였다.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1. 벽 부수기를 사용한 경우 c == true&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;2. 벽 부수기를 사용하지 않은 경우 c == false&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1. 벽을 부순 후에 차원 check2[]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;2. 벽을 부수지 않은 차원 check[]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;가장 먼저 벽을 부수기를 사용했는지 안했는지를 알기 위해 기존의 미로 찾기보다 Pair2에 c를 사용하여 표시를 할 수 있도록 해두었다. 다음 중요한 개념은 지나온 길을 알려주는 check[] 배열을 2개를 만들어서 차원을 2개로 나누었다. 벽을 부수지 않았을 때는 check[]에 지나온 길을 표시하고, 벽을 부순 후부터는 check2[]에 지나온 길을 표시하여 벽을 부순 후에 차원이 벽을 부수지 않은 차원에 영향을 미치지 못하도록 하였다.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/문제풀이</category>
      <category>2206</category>
      <category>목수의 미로 탈출</category>
      <category>목수의 미로탈출</category>
      <category>목수의미로탈출</category>
      <category>미로 찾기</category>
      <category>백준 2206</category>
      <category>벽 부수고 이동하기</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/60</guid>
      <comments>https://livecoding.tistory.com/60#entry60comment</comments>
      <pubDate>Mon, 17 Sep 2018 16:10:27 +0900</pubDate>
    </item>
    <item>
      <title>[문제] 미로찾기</title>
      <link>https://livecoding.tistory.com/55</link>
      <description>&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;문제&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 778px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/995380345B9B4A0F14&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F995380345B9B4A0F14&quot; width=&quot;778&quot; height=&quot;493&quot; filename=&quot;maze1.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 786px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99DE65345B9B4A0F02&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99DE65345B9B4A0F02&quot; width=&quot;786&quot; height=&quot;555&quot; filename=&quot;maze2.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;소스코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.*;

class Pair{
	int x;
	int y;
	Pair(int x, int y){
		this.x = x;
		this.y = y;
	}
}
public class Maze {
	public static final int[] dx = {0,0,1,-1};
	public static final int[] dy = {1,-1,0,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] input = sc.nextLine().split(&quot; &quot;);
		int n = Integer.parseInt(input[0]); 
		int m = Integer.parseInt(input[1]); 
		
		int[][] map = new int[n][m];
		for(int i=0; i&amp;lt;n; i++){
			String[] line = sc.nextLine().split(&quot; &quot;);
			for(int j=0; j&amp;lt;m; j++){
				map[i][j] = Integer.parseInt(line[j]);
			}
		}
		int[][] dist = new int[n][m]; //distance
		boolean[][] check = new boolean[n][m]; //check
		Queue&amp;lt;Pair&amp;gt; q = new LinkedList&amp;lt;Pair&amp;gt;(); //bfs
		q.add(new Pair(n-1, 0));
		check[n-1][0] = true;
		dist[n-1][0] = 0;
		while(!q.isEmpty()){
			Pair p = q.remove();
			int x = p.x;
			int y = p.y;
			for(int k=0; k&amp;lt;4; k++){
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(0&amp;lt;=nx &amp;amp;&amp;amp; nx&amp;lt;n &amp;amp;&amp;amp; 0&amp;lt;=ny &amp;amp;&amp;amp; ny&amp;lt;m){
					if(check[nx][ny] == false &amp;amp;&amp;amp; map[nx][ny] == 0){
						q.add(new Pair(nx, ny));
						dist[nx][ny] = dist[x][y] + 1;
						check[nx][ny] = true;
					}
				}
			}
		}
		System.out.println(dist[0][m-1]);
	}
}
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;풀이&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;-&lt;/span&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/문제풀이</category>
      <category>미로 bfs</category>
      <category>미로찾기</category>
      <category>미로찾기 알고리즘</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/55</guid>
      <comments>https://livecoding.tistory.com/55#entry55comment</comments>
      <pubDate>Fri, 14 Sep 2018 14:42:10 +0900</pubDate>
    </item>
    <item>
      <title>[정렬] 퀵 정렬 (Quick Sort) - 개념, 시간복잡도, 구현</title>
      <link>https://livecoding.tistory.com/54</link>
      <description>&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;퀵 정렬 개념&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;원소(&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;pivot(기둥/중심))&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;를 하나 정하여, 해당 원소보다 작은 수들과 큰 수들로 나눈다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;1. pi&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;vot의 위치는 확정된 것&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;2. pivot의 왼쪽과 오른쪽의 자리는 바뀌지 않는다. (= 왼쪽과 오른쪽을 따로 정렬해도 된다.)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;퀵 정렬의 시간복잡도&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;재귀적으로 구해야 한다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;1. pivot을 정한다.&amp;nbsp;= O(1)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;2. 작거나 같은 값과 큰 값을 분류한다.&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-size: 16px;&quot;&gt;= O(n)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;3. 각각을 퀵정렬 한다.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;* T(n) = n개의 숫자를 퀵 정렬로 정렬하는데 걸리는 시간&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;* T(n) = T(left) + T(right) + O(n)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 16px; color: rgb(140, 140, 140);&quot;&gt;// 점화식&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px; color: rgb(140, 140, 140);&quot;&gt;&amp;nbsp; // left = pivot보다 작거나 같은 원소의 개수&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px; color: rgb(140, 140, 140);&quot;&gt;&amp;nbsp; // right = pivot보다 큰 원소의 개수&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px; color: rgb(140, 140, 140);&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;* pivot이 원소의 개수를 절반으로 나눈다고 &lt;u&gt;&lt;span style=&quot;background-color: rgb(250, 244, 192);&quot;&gt;가정&lt;/span&gt;&lt;/u&gt;하자&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;* T(n) = 2T(n/2) + O(n) &lt;span style=&quot;color: rgb(166, 166, 166);&quot;&gt;=&amp;gt; 합병 정렬과 같음&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;b&gt;* &lt;/b&gt;퀵 정렬은 &lt;span style=&quot;background-color: rgb(255, 216, 216);&quot;&gt;평균적으로&lt;/span&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;u style=&quot;font-weight: bold;&quot;&gt;&lt;img class=&quot;txc-formula&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/999FB54E5BA382A518&quot; historydata=&quot;%3Cflashrichtext%20version%3D%221%22%3E%0A%20%20%3Ctextformat%20font%3D%22Dotum%22%20size%3D%2216%22%20color%3D%222236962%22%20bold%3D%22true%22%20italic%3D%22false%22%20underline%3D%22false%22%20url%3D%22%22%20target%3D%22transparent%22%20align%3D%22left%22%20leftMargin%3D%2225%22%20rightMargin%3D%2225%22%20indent%3D%220%22%20leading%3D%220%22%20blockIndent%3D%220%22%20kerning%3D%22true%22%20letterSpacing%3D%220%22%20display%3D%22block%22%3E%28T%5Cleft%28%20n%20%5Cright%29%20%3DO%5Cleft%28%20n%5Clog%20%7B%20n%20%7D%20%20%5Cright%29%20%29%3C/textformat%3E%0A%3C/flashrichtext%3E%2C%0A10%2C%0A0xFFFFFF&quot; width=&quot;116&quot; height=&quot;17&quot; style=&quot;background-color: rgb(238, 238, 238);&quot;&gt;&lt;/u&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;걸린다고 말함&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;* 퀵 정렬은 최악의 경우에는&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;text-decoration-line: underline;&quot;&gt;&lt;img class=&quot;txc-formula&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/99DE75505BA398B02C&quot; historydata=&quot;%3Cflashrichtext%20version%3D%221%22%3E%0A%20%20%3Ctextformat%20font%3D%22Dotum%22%20size%3D%2216%22%20color%3D%222236962%22%20bold%3D%22true%22%20italic%3D%22false%22%20underline%3D%22false%22%20url%3D%22%22%20target%3D%22transparent%22%20align%3D%22left%22%20leftMargin%3D%2225%22%20rightMargin%3D%2225%22%20indent%3D%220%22%20leading%3D%220%22%20blockIndent%3D%220%22%20kerning%3D%22true%22%20letterSpacing%3D%220%22%20display%3D%22block%22%3E%28T%5Cleft%28%20n%20%5Cright%29%20%3DO%5Cleft%28%20%7B%20n%20%7D%5E%7B%202%20%7D%20%5Cright%29%20%29%3C/textformat%3E%0A%3C/flashrichtext%3E%2C%0A10%2C%0A0xFFFFFF&quot; width=&quot;86&quot; height=&quot;19&quot; style=&quot;background-color: rgb(238, 238, 238);&quot;&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;b style=&quot;text-decoration-line: underline;&quot;&gt;&lt;/b&gt;이 걸림&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&amp;nbsp; (pivot을 어떤 식으로 결정하느냐에 따라 시간복잡도가 달라짐)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;b style=&quot;font-size: 18.6667px;&quot;&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;퀵 정렬 구현 코드&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class SortQuick {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int [100];
		
		for(int i=0; i&amp;lt;n; i++){ // 데이터 입력
			data[i] = sc.nextInt();
		}		
		quickSort(data, 0, n-1); // 퀵 정렬
		for(int i=0; i&amp;lt;n; i++){ // 데이터 출력
			System.out.print(data[i]+&quot; &quot;);
		}
	}
	
	// data[]를 start부터 end까지 퀵 정렬하는 함수
	private static void quickSort(int[] data, int start, int end) {
		if(start &amp;gt;= end) // 기저조건 =&amp;gt; 숫자가 하나밖에 남아 있지 않은 경우
			return;
		
		int pivot = data[start]; // 데이터의 맨 앞의 숫자
		int[] left = new int[100];
		int[] right = new int[100];
		
		// pivot 다음 숫자(start+1) ~ 끝까지(end) 중 pivot보다 같거나 작은 값
		int leftCnt = getLeft(data, start+1, end, pivot, left); // left 값 개수 반환받음
		// pivot 다음 숫자(start+1) ~ 끝까지(end) 중 pivot보다 큰 값
		int rightCnt = getRight(data, start+1, end, pivot, right);  // right 값 개수 반환받음
		
		for(int i=0; i&amp;lt;leftCnt; i++){ // 정렬된 왼쪽 값 삽입
			data[start+i] = left[i];
		}
		data[start+leftCnt] = pivot; // pivot 삽입
		for(int i=0; i&amp;lt;rightCnt; i++){ // 정렬된 오른쪽 값 삽입
			data[start+leftCnt+1+i] = right[i];
		}
		
		quickSort(data, start, start+leftCnt-1); // 왼쪽 퀵 정렬
		quickSort(data, start+leftCnt+1, end); // 오른쪽 퀵 정렬
	}
	
	// data[]의 start부터 end까지 숫자들 중에서 
	// pivot보다 작거나 같은 값을 result[]에 채우고 개수 반환하는 함수
	private static int getLeft(int[] data, int start, int end, int pivot, int[] result) {
		int index = 0;
		for(int i=start; i&amp;lt;=end; i++){
			if(data[i] &amp;lt;= pivot){
				result[index++] = data[i];
			}
		}
		return index;
	}
	
	// data[]의 start부터 end까지 숫자들 중에서
	// pivot보다 큰 값을 result[]에 채우고 개수 반환하는 함수
	private static int getRight(int[] data, int start, int end, int pivot, int[] result) {
		int index = 0;
		for(int i=start; i&amp;lt;=end; i++){
			if(data[i] &amp;gt; pivot){
				result[index++] = data[i];
			}
		}		
		return index;
	}
}
&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <category>quicksort</category>
      <category>퀵 정렬</category>
      <category>퀵 정렬 알고리즘</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/54</guid>
      <comments>https://livecoding.tistory.com/54#entry54comment</comments>
      <pubDate>Mon, 10 Sep 2018 16:56:35 +0900</pubDate>
    </item>
    <item>
      <title>[정렬] 합병 정렬 (Merge Sort) - 개념, 시간복잡도, 구현</title>
      <link>https://livecoding.tistory.com/53</link>
      <description>&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;합병 정렬 개념&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;배열을 절반으로 나누어 각각을 정렬한 후, 합친다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;합병 정렬의 시간복잡도&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;재귀적으로 구해야 한다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;1. 왼쪽 합병정렬 = T(n/2)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;2. 오른쪽 합병정렬&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-size: 16px;&quot;&gt;= T(n/2)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;3. 합친다&amp;nbsp; = O(n)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;* T(n) = n개의 숫자를 합병정렬할 때의 시간복잡도&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;* T(n) = 2 x T(n/2) + O(n)&amp;nbsp; &lt;span style=&quot;color: rgb(140, 140, 140);&quot;&gt;// 점화식&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 2(2T(n/4) + O(n/2)) + O(n)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 4T(n/4) + 2O(n) // &lt;span style=&quot;color: rgb(140, 140, 140);&quot;&gt;1번 대입&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 4(2T(n/8) + O(n/4)) + 2O(n)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 8T(n/8) + 3O(n) &lt;span style=&quot;color: rgb(140, 140, 140);&quot;&gt;// 2번 대입&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(140, 140, 140);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...... // k번 대입 k+1 = log n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = n x T(1) + log n x O(n)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = n x O(1) + O(n log n)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = O(n) + O(n log n)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;*&amp;nbsp;&lt;/span&gt;&lt;img class=&quot;txc-formula&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/99121F3F5BA39B0A2D&quot; historydata=&quot;%3Cflashrichtext%20version%3D%221%22%3E%0A%20%20%3Ctextformat%20font%3D%22Dotum%22%20size%3D%2216%22%20color%3D%222236962%22%20bold%3D%22true%22%20italic%3D%22false%22%20underline%3D%22false%22%20url%3D%22%22%20target%3D%22transparent%22%20align%3D%22left%22%20leftMargin%3D%2225%22%20rightMargin%3D%2225%22%20indent%3D%220%22%20leading%3D%220%22%20blockIndent%3D%220%22%20kerning%3D%22true%22%20letterSpacing%3D%220%22%20display%3D%22block%22%3E%28T%5Cleft%28%20n%20%5Cright%29%20%3DO%5Cleft%28%20n%5Clog%20%7B%20n%20%7D%20%20%5Cright%29%20%29%3C/textformat%3E%0A%3C/flashrichtext%3E%2C%0A12%2C%0A0xFFFFFF&quot; width=&quot;139&quot; height=&quot;21&quot; style=&quot;background-color: rgb(238, 238, 238);&quot;&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;line-height: 1.8;&quot;&gt;&lt;b style=&quot;font-size: 18.6667px;&quot;&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;합병 정렬 구현 코드&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class SortMerge {
	// 합병정렬 : 배열을 절반으로 나누어 각각을 정렬한 후, 합침
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int [100];
		
		for(int i=0; i&amp;lt;n; i++){
			data[i] = sc.nextInt();
		}		
		mergeSort(data, 0, n-1);
		
		for(int i=0; i&amp;lt;n; i++){
			System.out.print(data[i]+&quot; &quot;);
		}
	}

	// data의 start부터 end까지를 합병정렬하는 함수
	private static void mergeSort(int[] data, int start, int end) {
		if(start &amp;gt;= end) // 숫자가 한 개 남았을 때
			return;
		else{
			int mid = (start+end)/2;
			mergeSort(data, start, mid); // 1. 왼쪽 절반 합병정렬
			mergeSort(data, mid+1, end); // 2. 오른쪽 절반 합병정렬
			merging(data, start, mid, mid+1, end);// 3. 둘을 합침
		}
	}

	// 정렬된 반쪽들을 정렬해서 하나로 합치는 함수
	private static void merging(int[] data, int s1, int e1, int s2, int e2) {
		int p, q; // 현재 최솟값을 가리키는 변수들
		int [] temp = new int[100]; // 합쳐진 결과를 저장하는 임시배열
		int tempIndex = 0;
		
		p = s1; // 왼쪽 절반의 시작점
		q = s2; // 오른쪽 절반의 시작점
		
		while(p &amp;lt;= e1 &amp;amp;&amp;amp; q &amp;lt;= e2) {
			if(data[p] &amp;lt;= data[q]){
				temp[tempIndex++] = data[p];
				p++;
			}
			else{
				temp[tempIndex++] = data[q];
				q++;
			}			
		}
		if(p &amp;gt; e1){// q에 남은 숫자가 있는 경우
			for(int i=q; i&amp;lt;=e2; i++){
				temp[tempIndex++] = data[i];
			}
		}
		else{// p에 남은 숫자가 있는 경우
			for(int i=p; i&amp;lt;=e1; i++){
				temp[tempIndex++] = data[i];
			}
		}
		
		// temp[] 완성이 되었으니 data[]에 복사
		for(int i=s1; i&amp;lt;=e2; i++){
			data[i] = temp[i-s1]; //data[] 는 0부터 시작하는 것이 아님, temp는 0부터 시작
		}
	}
}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <category>합병정렬</category>
      <category>합병정렬 구현</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/53</guid>
      <comments>https://livecoding.tistory.com/53#entry53comment</comments>
      <pubDate>Mon, 10 Sep 2018 16:56:20 +0900</pubDate>
    </item>
    <item>
      <title>[정렬] 선택 정렬, 삽입 정렬, 버블 정렬의 구현</title>
      <link>https://livecoding.tistory.com/52</link>
      <description>&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;선택 정렬 구현 코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class SortSelection { // 선택 정렬
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int [100];
		
		for(int i=0; i&amp;lt;n; i++){
			data[i] = sc.nextInt();
		}
		// i : 앞의 정렬이 되어 있는 값들의 다음 위치
		// index : (비교대상 1)으로 최솟값이 담김(i부터 n까지의)
		// j : (비교대상 2) 순차적으로 뒤로 가면서 index와 비교함
		for(int i=0; i&amp;lt;n; i++){
			int index = i; 
			for(int j=i+1; j&amp;lt;n; j++){
				if(data[index] &amp;gt; data[j]){ // index값이 j값보다 크다면
					index = j; // index 값이 최솟값이 됨
				}
			}
			int temp;
			temp = data[i];
			data[i] = data[index];
			data[index] = temp;
		}
		for(int i=0; i&amp;lt;n; i++){
			System.out.print(data[i]+&quot; &quot;);
		}
	}
}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;삽입 정렬 구현 코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class SortInsertion { //삽입 정렬

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int [100];
		
		for(int i=0; i&amp;lt;n; i++){
			data[i] = sc.nextInt();
		}
		
		// i가 가리키고 있는 값이 왼쪽 정렬되어 있는 값과 비교 후 자리에 들어감
		// i : 앞의 정렬되어 있는 값들의 다음 위치 (비교대상 1)
		// j : (비교 대상 2) 순차적으로 앞으로 가면서 i와 비교함
		for(int i=1; i&amp;lt;n; i++){
			for(int j=i; j&amp;gt;=1; j--){
				if(data[j-1] &amp;gt; data[j]){
					int temp;
					temp = data[j-1];
					data[j-1] = data[j];
					data[j] = temp;
				}
				else break;
			}
		}
		for(int i=0; i&amp;lt;n; i++){
			System.out.print(data[i]+&quot; &quot;);
		}
	}
}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;버블 정렬 구현 코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class SortBubble { // 버블 정렬

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int [100];
		
		for(int i=0; i&amp;lt;n; i++){
			data[i] = sc.nextInt();
		}
		
		// j가 가리키고 있는 값과 오른쪽 값 비교를 n번함
		for(int i=0; i&amp;lt;n; i++){
			for(int j=0; j&amp;lt;n-i-1; j++){
				if(data[j] &amp;gt; data[j+1]){
					int temp;
					temp = data[j];
					data[j] = data[j+1];
					data[j+1] = temp;
				}
			}
		}
		for(int i=0; i&amp;lt;n; i++){
			System.out.print(data[i]+&quot; &quot;);
		}
	}
}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <category>버블 정렬</category>
      <category>삽입 정렬</category>
      <category>선택 정렬</category>
      <category>정렬 알고리즘</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/52</guid>
      <comments>https://livecoding.tistory.com/52#entry52comment</comments>
      <pubDate>Mon, 10 Sep 2018 16:55:48 +0900</pubDate>
    </item>
    <item>
      <title>[트리] 트리의 순회</title>
      <link>https://livecoding.tistory.com/46</link>
      <description>&lt;p style=&quot;line-height: 1.5;&quot;&gt;&lt;b style=&quot;font-size: 24px;&quot;&gt;트리의 순회(Tree Traversal)&lt;/b&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;트리의 모든 노드를 방문하는 순서&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;트리 내에 어떠한 자료가 담겨있는지를 알기 위함&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;그래프의 경우 DFS와 BFS가 있음&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;트리에서도 위의 두 방법을 사용가능 하지만, 트리에서만 사용할 수 있는 방법이 3가지 있음&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;1) 프리오더 = 전위 순회&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;2) 인오더 = 중위 순회&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;3) 포스트오더 = 후위 순회&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;세 방법의 차이는 노드 방문을 언제 하냐의 차이임&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;전위 순회, 프리오더(Pre-order)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Root - L - R&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;노드 방문 - 왼쪽 서브 트리 순회 - 오른쪽 서브 트리 순회&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;순서 : A-B-D-E-C-F-G&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;그래프의 DFS의 순서와 같음&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;노드 방문&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 457px; font-size: 13px;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/993E16435B90F50B20&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F993E16435B90F50B20&quot; width=&quot;457&quot; height=&quot;218&quot; filename=&quot;그림1.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;font-size: 13px;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;b&gt;왼쪽 서브 트리 순회&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px; font-size: 13px;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99B161435B90F50C2D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99B161435B90F50C2D&quot; width=&quot;820&quot; height=&quot;280&quot; filename=&quot;그림2.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;font-size: 13px;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;b&gt;오른쪽 서브 트리 순회&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px; font-size: 13px;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997B23435B90F50D03&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997B23435B90F50D03&quot; width=&quot;820&quot; height=&quot;288&quot; filename=&quot;그림3.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;font-size: 13px;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;중위 순회, 인오더(In-order)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style=&quot;font-size: 13px; list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;L - Root - R&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;왼쪽 서브 트리 순회 - 노드 방문 -&amp;nbsp;오른쪽 서브 트리 순회&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;순서 : D-B-E-A-F-C-G&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;후위 순회, 포스트오더(Post-order)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;L - R - Root&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 13px;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;왼쪽 서브 트리 순회 - 오른쪽 서브 트리 순회 - 노드 방문&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 13px;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;순서 : D-E-B-F-G-C-A&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p style=&quot;font-size: 16px; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.Scanner;

public class treeTraversal {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //node
		sc.nextLine();
		
		int[][] a = new int[n][2];
		for(int i=0; i&amp;lt;n; i++){
			String[] line = sc.nextLine().split(&quot; &quot;);
			int x = Integer.parseInt(line[0]);
			a[x][0] = Integer.parseInt(line[1]);
			a[x][1] = Integer.parseInt(line[2]);
		}
		
		preorder(a,0);
		System.out.println();
		inorder(a,0);
		System.out.println();
		postorder(a,0);
		System.out.println();
	}

	private static void preorder(int[][] a, int x) {
		if(x == -1) return;
		System.out.print(x+ &quot; &quot;);
		preorder(a, a[x][0]);
		preorder(a, a[x][1]);
	}
	
	private static void inorder(int[][] a, int x) {
		if(x == -1) return;
		inorder(a, a[x][0]);
		System.out.print(x+ &quot; &quot;);
		inorder(a, a[x][1]);
	}
	
	private static void postorder(int[][] a, int x) {
		if(x == -1) return;
		postorder(a, a[x][0]);
		postorder(a, a[x][1]);
		System.out.print(x+ &quot; &quot;);
	}
}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <category>인오더</category>
      <category>트리 구현</category>
      <category>트리 코드</category>
      <category>트리순회</category>
      <category>포스트오더</category>
      <category>프리오더</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/46</guid>
      <comments>https://livecoding.tistory.com/46#entry46comment</comments>
      <pubDate>Sun, 9 Sep 2018 21:54:34 +0900</pubDate>
    </item>
    <item>
      <title>[트리] 트리의 표현</title>
      <link>https://livecoding.tistory.com/45</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;&lt;b&gt;트리의 표현&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;트리는 그래피이기 때문에, 그래프의 표현과 같은 방식으로 저장할 수 있음&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;트리의 모든 노드는 부모를 하나 또는 0개만 가지기 때문에 부모만 저장하는 방식으로 저장 가능&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;부모가 0개인 경우는 트리의 루트인데, 이 경우 부모를 -1이나 0으로 처리하는 방식을 사용함&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;트리의 부모만 저장하는 방식&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 473px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A020405B90EE0224&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A020405B90EE0224&quot; width=&quot;473&quot; height=&quot;294&quot; filename=&quot;6.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;이진 트리&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;이진 트리의 경우는 배열로 표현 가능&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;부모의 노드가 x인 경우&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;자식의 노드는 2*x, 2*x+1로 나타냄&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 290px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996632375B90EF3926&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996632375B90EF3926&quot; width=&quot;290&quot; height=&quot;174&quot; filename=&quot;1.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;이진 트리의 경우는 배열로 표현 가능&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;A[i][0]에 i의 왼쪽 자식, A[i][1]에 i의 오른쪽 자식을 저장&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 285px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99D352375B90EF391A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99D352375B90EF391A&quot; width=&quot;285&quot; height=&quot;172&quot; filename=&quot;2.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;* 백준 알고리즘 참고&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/45</guid>
      <comments>https://livecoding.tistory.com/45#entry45comment</comments>
      <pubDate>Sun, 9 Sep 2018 21:54:16 +0900</pubDate>
    </item>
    <item>
      <title>[트리] 트리의 기본</title>
      <link>https://livecoding.tistory.com/42</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;&lt;b&gt;트리(Tree)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 198px; font-size: 16px;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C3973A5B90E08C09&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C3973A5B90E08C09&quot; width=&quot;198&quot; height=&quot;175&quot; filename=&quot;1.PNG&quot; filemime=&quot;image/jpeg&quot; style=&quot;font-size: 16px;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;자료구조의 일종&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;사이클이 없는 그래프&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;정점(Node, Vertex)&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;간선(Edge) : 정점간의 관계를 나타냄&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: left; line-height: 1.2;&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;정점의 개수 : V / 간선의 개수 : V-1&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;루트가 있는 트리&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 467px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99ECBF4E5B90E1AD03&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99ECBF4E5B90E1AD03&quot; width=&quot;467&quot; height=&quot;220&quot; filename=&quot;2.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1번이 루트(root)임&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;루트부터 아래로 방향을 정할 수 있음&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;루트 노드, 리프 노드, 단말 노드, 가지 노드&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 461px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C3A74B5B90E36903&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C3A74B5B90E36903&quot; width=&quot;461&quot; height=&quot;222&quot; filename=&quot;3.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1번은 루트 노드(root node) 즉, 부모가 없는 최상위 노드&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;4, 5, 6, 7번은 리프 노드(leaf node) 즉, 맨 마지막 끝 노드&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;4, 5, 6, 7번은 단말 노드(terminal node)도 됨. 가지를 가지지 않는 노드. 즉 degree가 0인 노드&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1, 2, 3번은 가지 노드(branch node) 가지를 가지는 노드. 즉, degree가 0이 아닌 노드&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;부모와 자식&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 467px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99ECBF4E5B90E1AD03&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99ECBF4E5B90E1AD03&quot; width=&quot;467&quot; height=&quot;220&quot; filename=&quot;2.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;부모노드(Parent)와 자식노드(Child)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1의 자식은 2와 3&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;2의 자식은 4와 5&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;3의 자식은 6과 7&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;형제&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 458px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E0603E5B90E5D42E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E0603E5B90E5D42E&quot; width=&quot;458&quot; height=&quot;220&quot; filename=&quot;4.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;형제 노드(Sibling)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;4와 5는 형제&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;6과 7은 형제&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;2와 3도 형제&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;같은 부모를 가지면 형제&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;깊이, 높이, 레벨&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 577px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992DD1435B90EAA104&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992DD1435B90EAA104&quot; width=&quot;577&quot; height=&quot;225&quot; filename=&quot;5.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;깊이(Depth)&lt;/b&gt; : 루트에서 어떤 노드까지의 경로 길이&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;4의 깊이는 2&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;높이(Height)&lt;/b&gt; : 가장 긴 깊이. 즉 가장 긴 경로 길이&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;트리의 높이는 2&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;레벨(Level)&lt;/b&gt; : 트리의 특정 깊이를 가지는 노드의 집합&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;루트의 레벨은 0으로 하는 경우와 1로 하는 경우가 있음&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;1 노드의 레벨은 1&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;2와 3 노드의 레벨은 2&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;4, 5, 6, 7 노드의 레벨은 3&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 24px;&quot;&gt;&lt;b&gt;조상과 자손&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 458px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9940C3475B90EB6511&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9940C3475B90EB6511&quot; width=&quot;458&quot; height=&quot;220&quot; filename=&quot;4.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;ul style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;p-&amp;gt;q로 갈 수 있을 때&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;p가 q보다 루트에 가까우면&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;p는 q의 조상&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;q는&amp;nbsp;p의 자손&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/기본다지기</category>
      <category>트리</category>
      <category>트리 용어</category>
      <category>트리의 개념</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/42</guid>
      <comments>https://livecoding.tistory.com/42#entry42comment</comments>
      <pubDate>Sun, 9 Sep 2018 21:54:02 +0900</pubDate>
    </item>
    <item>
      <title>[문제] 깊이우선탐색과 너비우선탐색</title>
      <link>https://livecoding.tistory.com/51</link>
      <description>&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;문제&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;img id=&quot;tx_entry_78319_&quot; class=&quot;txc-image&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/994541405B8FE65F22&quot; width=&quot;694&quot; height=&quot;503&quot;&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;img id=&quot;tx_entry_81767_&quot; class=&quot;txc-image&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/99695E405B8FE65F08&quot; width=&quot;691&quot; height=&quot;312&quot;&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;소스코드&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;brush:java&quot;&gt;import java.util.*;

public class bfsdfs {
	static ArrayList&amp;lt;Integer&amp;gt;[] a;
	static boolean[] check;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] input = sc.nextLine().split(&quot; &quot;);
		int n = Integer.parseInt(input[0]);
		int m = Integer.parseInt(input[1]);

		a = (ArrayList&amp;lt;Integer&amp;gt;[]) new ArrayList[n+1];
		for(int i=1; i&amp;lt;=n; i++){
			a[i] = new ArrayList&amp;lt;Integer&amp;gt;();
		}
		for(int i=0; i&amp;lt;m; i++){
			String line = sc.nextLine();
			int u = line.charAt(0)-'@';
			int v = line.charAt(2)-'@';
			a[u].add(v);
			a[v].add(u);
		}
		for(int i=1; i&amp;lt;=n; i++){
			Collections.sort(a[i]);
		}
		int start = sc.next().charAt(0)-'@';
		
		check = new boolean[n+1];
		dfs(start);
		System.out.println();
		
		check = new boolean[n+1];
		bfs(start);
		System.out.println();
	}

	private static void bfs(int start) {
		Queue&amp;lt;Integer&amp;gt; q = new LinkedList&amp;lt;Integer&amp;gt;();
		q.add(start);
		check[start] = true;
		while(!q.isEmpty()){
			int x = q.remove(); // head return
			System.out.print((char)(x+'@'));
			for(int y : a[x]){
				if(check[y] == false){
					check[y] = true;
					q.add(y);
				}
			}
		}
	}

	private static void dfs(int x) {
		check[x] = true;
		System.out.print((char)(x+'@'));
		for(int y : a[x]){
			if(check[y] == false){
				dfs(y);
			}
		}
	}
}
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: 18pt;&quot;&gt;풀이&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;-&lt;/span&gt;&lt;/p&gt;</description>
      <category>자료구조, 알고리즘/문제풀이</category>
      <category>BFS</category>
      <category>bfsdgs</category>
      <category>DFS</category>
      <category>깊이우선탐색</category>
      <category>너비우선탐색</category>
      <category>탐색알고리즘</category>
      <author>민쓰</author>
      <guid isPermaLink="true">https://livecoding.tistory.com/51</guid>
      <comments>https://livecoding.tistory.com/51#entry51comment</comments>
      <pubDate>Sun, 9 Sep 2018 21:26:26 +0900</pubDate>
    </item>
  </channel>
</rss>