<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>분석 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%eb%b6%84%ec%84%9d/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Mon, 08 May 2023 15:53:27 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>분석 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>알고리즘 – 빅오 표기법(Big-O Notation) 정리</title>
		<link>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%85%ec%98%a4-%ed%91%9c%ea%b8%b0%eb%b2%95big-o-notation-%ec%a0%95%eb%a6%ac/5053/</link>
					<comments>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%85%ec%98%a4-%ed%91%9c%ea%b8%b0%eb%b2%95big-o-notation-%ec%a0%95%eb%a6%ac/5053/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 20 Jan 2023 02:19:48 +0000</pubDate>
				<category><![CDATA[기타]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Average Case Analysis]]></category>
		<category><![CDATA[Best Case Analysis]]></category>
		<category><![CDATA[Big-O]]></category>
		<category><![CDATA[Big-O Notation]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Time Complexity]]></category>
		<category><![CDATA[Worst Case Analysis]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[관리]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[데이터]]></category>
		<category><![CDATA[분석]]></category>
		<category><![CDATA[빅-오]]></category>
		<category><![CDATA[빅오 표기법]]></category>
		<category><![CDATA[생산성]]></category>
		<category><![CDATA[시간복잡도]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[알고리즘을 분석하는 이유]]></category>
		<category><![CDATA[정리]]></category>
		<category><![CDATA[참조]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[테스트]]></category>
		<category><![CDATA[해결]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5053</guid>

					<description><![CDATA[<p>빅오 표기법(Big-O Notation)을 정리한 글입니다.</p>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%85%ec%98%a4-%ed%91%9c%ea%b8%b0%eb%b2%95big-o-notation-%ec%a0%95%eb%a6%ac/5053/">알고리즘 – 빅오 표기법(Big-O Notation) 정리</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1152" height="640" src="https://lycos7560.com/wp-content/uploads/image-1023.png" alt="" class="wp-image-5194" srcset="https://lycos7560.com/wp-content/uploads/image-1023.png 1152w, https://lycos7560.com/wp-content/uploads/image-1023-300x167.png 300w, https://lycos7560.com/wp-content/uploads/image-1023-768x427.png 768w" sizes="(max-width: 1152px) 100vw, 1152px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">시간 복잡도 / 공간 복잡도</h2>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">상황에 맞는 좋은 알고리즘을 선택하기 위해서는 알고리즘의 효율성을 확인해야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">이 때  효율성 측정에는 시간 복잡도(time complexity)와 공간 복잡도(space complexity)라는 두 부분이 있다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph"><strong>시간 복잡도</strong>는 문제를 해결하는데 걸리는 시간과 입력의 함수 관계</p>



<p class="has-medium-font-size wp-block-paragraph"><strong>공간 복잡도</strong>는 문제를 해결하는데 필요로 하는 자원 공간의 양</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Big-O 표기법 (Big-O Notation)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">시간 복잡도의 표기법은</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph"><strong>최선 경우 분석(Best Case Analysis)</strong>&nbsp;=&gt; Big-Ω(빅-오메가) / 하한 점근 </p>



<p class="has-medium-font-size wp-block-paragraph">-&gt; 알고리즘&nbsp;<strong>최상</strong>의 실행 시간을 표기한다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph"><strong>최악 경우 분석(Worst Case Analysis)</strong>&nbsp;=&gt; Big-O(빅-오) / 상한 점근</p>



<p class="has-medium-font-size wp-block-paragraph">-&gt; 알고리즘&nbsp;<strong>최악</strong>의 실행 시간을 표기한다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph"><strong>평균 경우 분석(Average Case Analysis)</strong>&nbsp;=&gt; Big-θ(빅-세타) / 그 둘의 평균</p>



<p class="has-medium-font-size wp-block-paragraph">-&gt; 알고리즘&nbsp;<strong>평균</strong>&nbsp;실행 시간을 표기한다.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">일반적으로 위의 3가지 경우로 분류한다.</p>



<p class="has-medium-font-size wp-block-paragraph">그중에서 <strong>Big-O 표기법은 최소한 보장되는 성능을 표기하기 때문에 가장 많이 사용하는 표기법</strong>이다.</p>



<p class="has-medium-font-size wp-block-paragraph">(불확실성을 제거하기 위해 최악의 경우를 사용)</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1008.png" alt="" class="wp-image-5094" width="800" height="500"/></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size wp-block-paragraph"><strong>O(1) &lt; O(logN) &lt; O(N) &lt; O(N logN) &lt; O(N²) &lt; O(2ᴺ) &lt; O(N!)</strong></p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(1) &#8211; 상수 시간 (Constant<strong> Time</strong>)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">입력한 데이터의 크기에 상관없이 언제나 일정한 시간이 걸리는 알고리즘</p>



<p class="has-medium-font-size wp-block-paragraph">O(1) 알고리즘은 데이터(data)가 증가해도, 처리속도(time)에는 변함이 없는 알고리즘이다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int main()
{
	cout &lt;&lt; "Do Something!!";

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int main()
{
	cout &lt;&lt; "Do Something!!";
	cout &lt;&lt; "Do Something!!";

	return 0;
}</pre>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">두번 출력을 하는 코드는 O(2)가 아닌 O(1)이다.</p>



<p class="has-medium-font-size wp-block-paragraph">왜냐하면 Big O는 함수의 디테일에는 관심이 없기 때문이다.</p>



<p class="has-medium-font-size wp-block-paragraph">그저 input 사이즈에 따라서 달라진다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1000.png" alt="" class="wp-image-5063" width="800" height="500"/></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(N) &#8211; 선형 시간 (Linear<strong> Time</strong>)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">O(N)는 완벽한 대각선</p>



<p class="has-medium-font-size wp-block-paragraph">최악의 경우에 n번의 연산을 수행해야 하는 알고리즘으로 데이터가 추가될 때마다 알고리즘이 한 단계 더 진행된다.</p>



<p class="has-medium-font-size wp-block-paragraph">이것이 선형 시간이라고 하는 이유</p>



<p class="has-medium-font-size wp-block-paragraph">ex) 1중 for문</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int main()
{
	int N = 0;
	cin >> N;
	for (int i = 0; i &lt; N; i++) {
		cout &lt;&lt; "Do Something!!" &lt;&lt; "\n";
	}

	return 0;
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1001.png" alt="" class="wp-image-5064" width="800" height="500"/></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading">* 참고 * O(1) / O(N)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">O(1)과 O(N)의 알고리즘으로 같은 문제를 50까지 수행한다면</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1002.png" alt="" class="wp-image-5070" width="800" height="500"/></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">→ 입력 배열의 요소가 50개 미만일 때 O(N)가 더 효율적</p>



<p class="has-medium-font-size wp-block-paragraph">→ 정확히 50개의 요소에서 두 알고리즘은 동일한 단계 수를 사용</p>



<p class="has-medium-font-size wp-block-paragraph">→ 데이터가 증가할수록 O(N)더 많은 단계가 필요</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">Big-O 표기법은 데이터가 무한대로 커짐에 따라 알고리즘이 어떻게 수행되는지 살펴보기 때문에 </p>



<p class="has-medium-font-size wp-block-paragraph">O(N)가 보다 덜 효율적인 것으로 간주되는 이유다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(N²) &#8211;<strong> 2차 시간</strong> (<strong>Quadratic Time</strong>)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">성능이 입력 요소 크기의 제곱에 비례하는 알고리즘의 복잡성을 나타낸다.&nbsp;일반적으로 매우 느리다.</p>



<p class="has-medium-font-size wp-block-paragraph">주로 <strong>중첩 반복</strong>이 있을 때 발생하게 된다.</p>



<p class="has-medium-font-size wp-block-paragraph">루프안에서 루프가 실행된다면, 20개의 데이터는 400개의 스텝이 된다. O(n^2)</p>



<p class="has-medium-font-size wp-block-paragraph">ex) 2중 for문, 삽입(Insertion)/거품(Bubble)/선택(Selection) 정렬 등&#8230;</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int main()
{
	int N = 0;
	cin >> N;
	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; N; j++) {
			cout &lt;&lt; "Do Something!!" &lt;&lt; "\n";
		}
	}

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1004.png" alt="" class="wp-image-5078" width="800" height="500"/></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(logN) &#8211; <strong>로그 시간 (Logarithmic<strong> Time</strong>)</strong></h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">연산이 한 번 실행될 때 마다 데이터의 크기가 절반 감소하는 알고리즘 (log의 지수는 항상 2)</p>



<p class="has-medium-font-size wp-block-paragraph">데이터의 관점으로 말하면 O(logN)은 <strong>데이터가 두 배가 될 때마다 작업 수가 하나씩 증가</strong>한다.</p>



<p class="has-medium-font-size wp-block-paragraph">ex) binary search 알고리즘, tree 형태 자료구조 탐색</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// 이진 탐색

int BinarySearch(int arr[], int size, int target)
{
	
	int low = 0;
	int high = size - 1;
	int mid = 0;

	while (low &lt;= high)
	{
		mid = (low + high) / 2;

		if (target &lt; arr[mid])
			high = mid - 1;
		else if (target > arr[mid])
			low = mid + 1;
		else
			return mid;  // 반환 값은 인덱스
	}

	return -1;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1005.png" alt="" class="wp-image-5081" width="800" height="500"/></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(N logN) &#8211; 로그 선형 시간 (Log-linear<strong><strong> Time</strong></strong>)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">O(N)의 알고리즘과 O(log N)의 알고리즘이 중첩된 형태</p>



<p class="has-medium-font-size wp-block-paragraph">log(N)작업 N시간을 수행</p>



<p class="has-medium-font-size wp-block-paragraph">ex) 퀵(Quick) / 병합(Merge) / 힙(Heap) 정렬, 분할 정복 알고리즘</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(2ᴺ) &#8211; 지수 시간 (Exponential Time)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">매우 느린 시간 복잡도로 주로 재귀적으로 수행하는 알고리즘이 이에 해당</p>



<p class="has-medium-font-size wp-block-paragraph">ex) fibonacci 수열</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// 피보나치 수열 
int Fibonaci(int n){
    if (n == 1) return 0;
    else if (n == 2) return 1;
    else return Fibo(n - 1) + Fibo(n - 2);
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">O(N!) &#8211; 계승 시간(Factorial Time)</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">&nbsp;입력 크기의 계승에 비례하는 실행 시간 </p>



<p class="has-medium-font-size wp-block-paragraph">가장 느린 알고리즘으로 입력 값이 조금만 커져도 계산이 어렵다. (답없다.)</p>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="빅오-표기법big-o-notation-특징">빅오 표기법(big-O notation)&nbsp;규칙</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="계수-법칙-상수를-제거하라">계수 법칙: 상수를 제거하라</h3>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">계수 법칙은 단순히 입력 크기와 연관되지 않은 상수를 전부 무시하는 것이다</p>



<p class="has-medium-font-size wp-block-paragraph">빅오에서 입력 크기가 클 때 계수를 무시할 수 있다</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">상수 k > 0 인 경우 f(n)이 O(g(n))이면,
kf(n)은 O(g(n)이다.
이 말은 즉, 5f(n)과 f(n)이 모두 동일한 O(f(n))이라는 빅오 표기법을 지님을 의미한다</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="합의-법칙-빅오를-더하라">합의 법칙: 빅오를 더하라</h3>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">합의 법칙은 시간 복잡도를 더할 수 있다는 것을 의미한다</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">f(n)이 O(h(n))이고 g(n)이 O(p(n))이라면
f(n)+g(n)은 O(h(n))+O(p(n))이다
이 때 주의해야할 점은 합의 법칙을 적용한 다음 계수 법칙을 적용해야한다는 점이다</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="곱의-법칙-빅오를-곱하라">곱의 법칙: 빅오를 곱하라</h3>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">곱의 법칙은 빅오가 어떤 식으로 곱해지는지에 관한 것이다</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">f(n)이 O(h(n))이고 g(n)이 O(p(n))이면
f(n)g(n)은 O(h(n)p(n))이다</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="다항-법칙-빅오의-k승">다항 법칙: 빅오의 k승</h3>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">다항 법칙은 다항 시간 복잡도가 동일한 다항 차수를 지닌 빅오 표기법을 지님을 의미한다</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">f(n)이 k차 다항식이면 f(n)은 O(nᵏ)이다</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">쉽게 말해, 빅오 표기법은 제일 영향력 있는 것만 신경쓰겠다는 의미</p>



<p class="has-medium-font-size wp-block-paragraph">(최고 차항을 남기고, 상수는 버린다)</p>



<p class="has-medium-font-size wp-block-paragraph">O(30n³+20n²+500n+3000)로 표시된 값이 있을 때, 빅오 표기법은 제일 영향력 있는 것만 남겨 O(n³)으로만 표기한다</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">참고 사이트</h2>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><a href="https://velog.io/@2seunghye/%EC%9E%90%EB%A3%8C%EA%B5%AC%EC%A1%B0%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%B9%85%EC%98%A4%ED%91%9C%EA%B8%B0%EB%B2%95Big-O-notation" target="_blank" rel="noreferrer noopener">https://velog.io/@2seunghye/%EC%9E%90%EB%A3%8C%EA%B5%AC%EC%A1%B0%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%B9%85%EC%98%A4%ED%91%9C%EA%B8%B0%EB%B2%95Big-O-notation</a></p>



<p class="wp-block-paragraph"><a href="https://towardsdatascience.com/introduction-to-big-o-notation-820d2e25d3fd" target="_blank" rel="noreferrer noopener">https://towardsdatascience.com/introduction-to-big-o-notation-820d2e25d3fd</a></p>



<p class="wp-block-paragraph"><a href="https://wing-beat.tistory.com/17" target="_blank" rel="noreferrer noopener">https://wing-beat.tistory.com/17</a></p>



<p class="wp-block-paragraph"><a href="https://towardsdatascience.com/the-big-o-notation-d35d52f38134" target="_blank" rel="noreferrer noopener">https://towardsdatascience.com/the-big-o-notation-d35d52f38134</a></p>



<p class="wp-block-paragraph"><a href="https://noahlogs.tistory.com/27" target="_blank" rel="noreferrer noopener">https://noahlogs.tistory.com/27</a></p>



<p class="wp-block-paragraph"><a href="https://velog.io/@nana-moon/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%B9%85%EC%98%A4-%ED%91%9C%EA%B8%B0%EB%B2%95big-O-notation%EC%9D%B4%EB%9E%80" target="_blank" rel="noreferrer noopener">https://velog.io/@nana-moon/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%B9%85%EC%98%A4-%ED%91%9C%EA%B8%B0%EB%B2%95big-O-notation%EC%9D%B4%EB%9E%80</a></p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%85%ec%98%a4-%ed%91%9c%ea%b8%b0%eb%b2%95big-o-notation-%ec%a0%95%eb%a6%ac/5053/">알고리즘 – 빅오 표기법(Big-O Notation) 정리</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%85%ec%98%a4-%ed%91%9c%ea%b8%b0%eb%b2%95big-o-notation-%ec%a0%95%eb%a6%ac/5053/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>알고리즘 – 알고리즘 분석에 대한 정리</title>
		<link>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%eb%b6%84%ec%84%9d%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac/4978/</link>
					<comments>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%eb%b6%84%ec%84%9d%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac/4978/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 19 Jan 2023 19:15:08 +0000</pubDate>
				<category><![CDATA[기타]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Average Case Analysis]]></category>
		<category><![CDATA[Best Case Analysis]]></category>
		<category><![CDATA[Big-O]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Time Complexity]]></category>
		<category><![CDATA[Worst Case Analysis]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[관리]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[데이터]]></category>
		<category><![CDATA[분석]]></category>
		<category><![CDATA[빅-오]]></category>
		<category><![CDATA[생산성]]></category>
		<category><![CDATA[시간복잡도]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[알고리즘을 분석하는 이유]]></category>
		<category><![CDATA[참조]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[테스트]]></category>
		<category><![CDATA[해결]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4978</guid>

					<description><![CDATA[<p>알고리즘을 공부하면서 공부한 내용을 정리한 글입니다. (This is an article that summarizes what you studied while studying algorithms.)</p>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%eb%b6%84%ec%84%9d%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac/4978/">알고리즘 – 알고리즘 분석에 대한 정리</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">알고리즘을 분석하는 이유</h1>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>정확성 확인(무결성 확인)</strong></p>



<p class="has-medium-font-size wp-block-paragraph">모든 유효한 입력에 대해서 유한 시간 내에 올바른 해를 찾아내는가를 판단하기 위함</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>효율성 확인</strong></p>



<p class="has-medium-font-size wp-block-paragraph">한정된 자원(기억 장소 사용량, 수행 시간)에서 효율적으로 작동하는지 확인하기 위함</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>궁극적으로 알고리즘을 분석하여 얻는 이점</strong></p>



<p class="has-medium-font-size wp-block-paragraph">문제를 해결하기 위해 중요한 것과 중요하지 않은 것을 판단할 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">문제를 단순화하여 생각할 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">다른 사람의 아이디어에 대한 효율성을 판단할 수 있다.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">같은 문제를 해결하는 알고리즘은 여러 가지가 존재한다.</p>



<p class="has-medium-font-size wp-block-paragraph">최상의 알고리즘은 존재하지 않으며 항상 주어진 상황을 객관적으로 분석하여 알고리즘을 선택해야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">또한 기존의 알고리즘을 개선하기 위해서 적용 가능한 여러 알고리즘을 객관적으로 비교 분석을 할 줄 알아야 한다.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>알고리즘을 분석하는 방법</strong></p>



<p class="has-medium-font-size wp-block-paragraph">일반적으로 알고리즘의 수행 시간에 따른 <strong>시간복잡도(Time Complexity)</strong>와</p>



<p class="has-medium-font-size wp-block-paragraph">작성한 프로그램이 얼마나 많은 공간(메모리)을 차지하느냐를 분석하는 방법인 <strong>공간복잡도(Space&nbsp;Complexity)</strong>로 분석한다.</p>



<p class="has-medium-font-size wp-block-paragraph">시간복잡도의 경우 알고리즘을 잘못 구성하였을 경우 결과값이 나오지 않거나 현저하게 느린속도가 나오기에 </p>



<p class="has-medium-font-size wp-block-paragraph">공간복잡도보다는 시간복잡도를 우선시하여 프로그램을 분석한다. (기술의 발달로 인한 메모리 증가도 큰 영향)</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">알고리즘의 수행 시간</h1>



<p class="has-medium-font-size wp-block-paragraph">알고리즘의 효율성을 분석하는 방법은 다양하지만, 많은 경우에 알고리즘의 수행 시간을 이용하여 효율성을 분석</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>시간복잡도</strong> <strong>(Time Complexity)</strong> : 얼마나 빠른가?</p>



<p class="has-medium-font-size wp-block-paragraph">입력 크기에 비례하여 작업시간이 어떠한 비율로 증가하는지 확인한다.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>시간복잡도를 사용하는 이유</strong></p>



<p class="has-medium-font-size wp-block-paragraph">실측으로 시간을 측정하는 경우 프로그래밍 언어, 컴퓨터의 성능, 프로그래머의 실력 등의 다양한 변수에 따라 달라질 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">(분석에 객관적인 기준이 필요)</p>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size wp-block-paragraph"><strong>수행 시간 분석 방법</strong></p>



<p class="wp-block-paragraph" style="font-size:30px"><strong>최선 경우 분석(Best Case Analysis)</strong> =&gt; Big-Ω(빅-오메가) / 하한 점근</p>



<p class="has-medium-font-size wp-block-paragraph">최선의 경우는 프로그램 실행 시간의 하한을 계산한다. </p>



<p class="has-medium-font-size wp-block-paragraph">선형 탐색의 경우 베스트 케이스는 찾으려는 x가 제일 처음에 위치하는 경우이다. </p>



<p class="has-medium-font-size wp-block-paragraph">최상의 경우 실행되는 연산의 수는 상수이며 입력 크기 n에 영향을 받지 않는다. </p>



<p class="has-medium-font-size wp-block-paragraph">따라서 최상의 경우 시간 복잡도는&nbsp;θ(1)이다.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>최악 경우 분석(Worst Case Analysis)</strong> =&gt; Big-O(빅-오) / 상한 점근</p>



<p class="has-medium-font-size wp-block-paragraph">최악의 경우는 알고리즘이 실행되는 시간의 상한을 결정한다. </p>



<p class="has-medium-font-size wp-block-paragraph">프로그램을 실행 할 때 연산이 수행되는 횟수가 최대가 되는 경우이다. </p>



<p class="has-medium-font-size wp-block-paragraph">선형 탐색의 경우 찾으려는 원소가 배열에 존재하지 않거나 배열의 끝에 존재하는 경우이다. </p>



<p class="has-medium-font-size wp-block-paragraph">배열에 찾으려는 원소가 존재하지 않으면 배열의 전체 원소와 모두 비교를 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">이 때 최악이라는 것은 단위 연산이 수행되는 횟수가 최대라는 것이다. </p>



<p class="has-medium-font-size wp-block-paragraph">입력 크기와 입력 값(내용) 모두에 종속된다. </p>



<p class="has-medium-font-size wp-block-paragraph">선형 탐색의 최악의 경우 시간 복잡도는 θ(n)이다.​</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-995.png" alt="" class="wp-image-5016" width="541" height="424" srcset="https://lycos7560.com/wp-content/uploads/image-995.png 1013w, https://lycos7560.com/wp-content/uploads/image-995-300x235.png 300w, https://lycos7560.com/wp-content/uploads/image-995-768x601.png 768w" sizes="(max-width: 541px) 100vw, 541px" /></figure>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="LLu30oHh8G"><a href="https://lycos7560.com/?p=5053">알고리즘 – 빅오 표기법(Big-O Notation) 정리</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;알고리즘 – 빅오 표기법(Big-O Notation) 정리&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=5053&#038;embed=true#?secret=90kjAk5LHm#?secret=LLu30oHh8G" data-secret="LLu30oHh8G" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<div style="height:80px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>평균 경우 분석(Average Case Analysis)</strong> =&gt; Big-θ(빅-세타) / 그 둘의 평균</p>



<p class="has-medium-font-size wp-block-paragraph">평균적인 경우를 계산하는 방법은 다음과 같다. </p>



<p class="has-medium-font-size wp-block-paragraph">가능한 모든 입력에 대해 실행 시간을 계산한다. </p>



<p class="has-medium-font-size wp-block-paragraph">그리고 이 시간을 모두 더하고, 더한 결과를 입력의 수로 나눈다.</p>



<p class="has-medium-font-size wp-block-paragraph">선형 탐색을 계산하는 방법은 다음과 같다.</p>



<p class="has-medium-font-size wp-block-paragraph">선형 탐색인 경우 모든 경우들이 균등하게 분포한다고 가정하자.</p>



<p class="has-medium-font-size wp-block-paragraph">크기 n의 배열에서 원소 x를 찾으려고 할 때, x의 위치는 1 또는 2, 3, … , n이 될 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">배열을 따라 각 원소를 x와 비교한다. </p>



<p class="has-medium-font-size wp-block-paragraph">만약 배열의 k번째 원소에 도달 했으면 이미 k번 비교를 한 것이다.</p>



<p class="has-medium-font-size wp-block-paragraph">x가 인덱스 1의 위치에 있다면 1번 비교한다.</p>



<p class="has-medium-font-size wp-block-paragraph">x가 인덱스 2의 위치에 있다면 2번 비교한다.</p>



<p class="has-medium-font-size wp-block-paragraph">…</p>



<p class="has-medium-font-size wp-block-paragraph">x가 인덱스 n의 위치에 있다면 n번 비교한다.</p>



<p class="has-medium-font-size wp-block-paragraph">평균을 구하기 위해 비교한 수들을 합하면  1+ 2 + 3 + &#8230; + n = (n+1)n / 2  </p>



<p class="has-medium-font-size wp-block-paragraph">이를 배열의 크기인 n으로 나누면 (n+1) / 2 이다.</p>



<p class="has-medium-font-size wp-block-paragraph">따라서 선형 탐색의 평균 시간 복잡도는 θ(n) 이다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size wp-block-paragraph"><strong>가장 자주 사용되는</strong> <strong>분석</strong></p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph" style="font-size:30px"><strong>최악 경우 분석(Worst Case Analysis)</strong> =&gt; <strong>Big-O(빅-오)</strong><em> </em>/ 상한 점근</p>



<p class="has-medium-font-size wp-block-paragraph">시간 복잡도에는 여러 개념이 있지만 그중에서 </p>



<p class="has-medium-font-size wp-block-paragraph">‘아무리 많이 걸려도 이 시간 안에는 끝날 것‘의 개념이 제일 중요하다.&nbsp;</p>



<p class="has-medium-font-size wp-block-paragraph">예를 들어 동전을 튕겨서 뒷면이 나올 확률을 이야기해본다면 운이 좋으면 한 번에 뒷면이 나올 수도 있고 </p>



<p class="has-medium-font-size wp-block-paragraph">운이 좋지 않으면 3번 4번만에 뒷면이 나올수도 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">운이 나쁜 경우 n번만큼 동전을 튕겨야 하는 최악의 경우가 발생하는데 </p>



<p class="has-medium-font-size wp-block-paragraph">이&nbsp;최악의 경우를 계산하는 방식을&nbsp;<strong>빅-오(Big-O) 표기법</strong>이라고 부르며 이 방식을 가장 많이 사용한다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%eb%b6%84%ec%84%9d%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac/4978/">알고리즘 – 알고리즘 분석에 대한 정리</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%eb%b6%84%ec%84%9d%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac/4978/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
