Big O Search Algorithms in JavaScript - Lee-hyuna/33-js-concepts-kr GitHub Wiki

JavaScript์˜ Big O ๊ฒ€์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜

์ด ๊ฒŒ์‹œ๋ฌผ์€ JavaScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ผ๋ถ€ ๊ธฐ๋ณธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ฝ”๋“œ ์˜ˆ์ œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. JavaScript์— ์ต์ˆ™ํ•˜๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ƒ˜ํ”Œ ์ฝ”๋“œ๋ฅผ ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ฐ€์ ธ ์™€์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜๋„์ ์œผ๋กœ JavaScript๋ฅผ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ฐ ์ฝ”๋“œ ์˜ˆ์ œ์— ๋Œ€ํ•ด JSLitmus๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒค์น˜ ๋งˆํฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ž‘์€ ์ž…๋ ฅ, ์ค‘๊ฐ„ ์ž…๋ ฅ ๋ฐ ํฐ ์ž…๋ ฅ์œผ๋กœ ๊ฐ ๋ฐฉ๋ฒ•์„ ์„ธ ๋ฒˆ ๋ฒค์น˜ ๋งˆํฌํ•ฉ๋‹ˆ๋‹ค. JSLitmus์—๋Š” ๊ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์„ฑ๋Šฅ ํŠน์„ฑ์„ ์‹œ๊ฐ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ์œ ์šฉํ•œ ๊ทธ๋ž˜ํ”„ ๊ธฐ๋Šฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ณต ์‹คํ–‰์‹œ ์ดˆ๋‹น ๊ฐ€๋Šฅํ•œ ์ž‘์—… ์ˆ˜๋ฅผ ๋ณด๊ณ ํ•ฉ๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฒค์น˜๋งˆํ‚น์— ๊ด€ํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์„ฑ์žฅ ํŠน์„ฑ์„ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ๋ฒค์น˜ ๋งˆํฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์ ์— ์œ ์˜ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ๋ฅผ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ๋ฐฐ์—ด์„ ๋ชจ๋‘ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

// Set up a simple array of colours
var colours = new Array ("Black", "Blue", "Brown", "Green", "Pink", "Red", "White", "Yellow");

// Set up numbers from 1 to 2500
var numbersHalf = new Array();
 
for (var i = 1; i < 2500; i++) {
  numbersHalf.push(i);
};

// Set up numbers from 1 to 5000
var numbersFull = new Array();
 
for (var i = 1; i < 5000; i++) {
  numbersFull.push(i);
};

๋ฐฐ์—ด colours์€ ์ž‘์€ ๋ฐฐ์—ด์ด๋ฉฐ numbersHalf์—๋Š” 2500๊ฐœ์˜ ํ•ญ๋ชฉ์ด ์žˆ๊ณ  numbersFull์—๋Š” 5000๊ฐœ์˜ ํ•ญ๋ชฉ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐœ๋…์„ ์ตํžˆ๊ธฐ ์œ„ํ•ด ์ด์ „ ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๋ฌผ์„ ๋‹ค์‹œ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.

Constant Complexity (์ผ์ •ํ•œ ๋ณต์žก์„ฑ)

์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค : O(1)

๋ณต์žก์„ฑ(ํ•ญ๋ชฉ ์ˆ˜)์— ๊ด€๊ณ„์—†์ด ๊ฒฐ๊ณผ๋Š” ์ผ์ •ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” ๋‹จ์ˆœํžˆ ๋ฐฐ์—ด์—์„œ ์ฒซ ๋ฒˆ์งธ ํ•ญ๋ชฉ์„ ๊ฐ€์ ธ ์™€์„œ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

// Find the first item
function FindFirstItem(items) {
     return items[0];
}

JSLitmus.test('Find first colour test', function() {
     FindFirstItem(colours);
});
 
JSLitmus.test('Find first number test (2500 items)', function() {
     FindFirstItem(numbersHalf);
});
 
JSLitmus.test('Find first number test (5000 items)', function() {
     FindFirstItem(numbersFull);
});

์•„๋ž˜ ํ‘œ๋Š” ์ดˆ๋‹น ์ž‘์—… ์ˆ˜๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ๋ณด์‹œ๋‹ค์‹œํ”ผ ๊ฒฐ๊ณผ๋Š” ์ž…๋ ฅ ์ˆ˜์— ๊ด€๊ณ„์—†์ด ๊ฑฐ์˜ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ๋Š” ์ผ์ •ํ•ฉ๋‹ˆ๋‹ค.

Test Ops/sec
Find first colour test 102675741
Find first number test (2500 items) 99864381
Find first number test (5000 items) 99273467

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://2.bp.blogspot.com/-PHqGo4yup_w/T5CkDrfB8CI/AAAAAAAAAOY/AkMGNKS2qCc/s400/constant-complexity.png

Linear Complexity(์„ ํ˜• ๋ณต์žก์„ฑ)

์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค : O(n)

์„ ํ˜• ๋ณต์žก์„ฑ์œผ๋กœ ํ•จ์ˆ˜์˜ ์„ฑ์žฅ๋ฅ ์€ ํ•ญ๋ชฉ ์ˆ˜์™€ ์ง์ ‘ ์—ฐ๊ฒฐ๋ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ ์˜ˆ์ œ์—์„œ๋Š” ๋ชจ๋“  ํ•ญ๋ชฉ์„ ๋ฐ˜๋ณตํ•˜๊ณ  ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ํ•ญ๋ชฉ๊ณผ ์ผ์น˜์‹œํ‚ต๋‹ˆ๋‹ค. ์„ฑ์žฅ์„ ์ธก์ • ํ•  ๋•Œ๋Š” ์ƒํ•œ ๋˜๋Š” ์ตœ์•…์˜ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ๊ณ ๋ คํ•˜๋ฏ€๋กœ ๋ฒค์น˜ ๋งˆํฌ์—์„œ ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ํ•ญ๋ชฉ์„ ์ฐพ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

function FindItem(items, match) {
     for (var i=0; i < items.length; i++) {
          if (items[i] == match) {
               return true;
          }
     }
     return false;
}

JSLitmus.test('Find colour by colour name', function() {
     FindItem(colours, "Yellow");
});

JSLitmus.test('Find number index by number (2500 items)', function() {
     FindItem(numbersHalf, 2500);
});
 
JSLitmus.test('Find number index by number (5000 items)', function() {
     FindItem(numbersFull, 5000);
});

์•„๋ž˜ ๊ทธ๋ž˜ํ”„๋Š” ํ›จ์”ฌ ๋” ์ž‘์€ colours์˜ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์—ฌ ์ดˆ๋‹น ๋” ๋งŽ์€ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ๋ถ„๋ช…ํžˆ ๋ณด์—ฌ ์ฃผ์ง€๋งŒ, ๊ทธ๋ž˜ํ”„์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ƒ๋Œ€์ ์ด๋ฏ€๋กœ 2500 ๋ฐ 5000 ํ•ญ๋ชฉ์˜ ๋ฐฐ์—ด์„ ๋น„๊ตํ•˜๋Š” ๋ฐ๋ณ„๋กœ ์œ ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ์—์„œ ๋น„๊ต๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Test Ops/sec
Find colour by colour name 53659755
Find number index by number (2500 items) 54566
Find number index by number (5000 items) 27168

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://1.bp.blogspot.com/-r4-QbMkytKc/T5ClvsGIWRI/AAAAAAAAAOk/NKwiFOJptE4/s400/linear-complexity.png

์•„๋ž˜๋Š” FindItem ๋ฉ”์„œ๋“œ์˜ 2500 ๋Œ€ 5000 ํ•ญ๋ชฉ์˜ ๊ทธ๋ž˜ํ”„์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ๋‘ ๋ฐฐ๋‚˜ ๋งŽ์€ ์•„์ดํ…œ์˜ ์„ฑ์žฅ๋ฅ ์„ ๋ถ„๋ช…ํžˆ ๋ณด์—ฌ ์ฃผ๋ฉฐ 5000๊ฐœ ์•„์ดํ…œ์€ 2500๊ฐœ๋ณด๋‹ค ๋‘ ๋ฐฐ ๋Š๋ฆฝ๋‹ˆ๋‹ค.

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://2.bp.blogspot.com/-NELJVXcDIJE/T5CmfbiKN3I/AAAAAAAAAOw/7xGTBbFpKDw/s1600/linear-complexity-2.png

Logarithmic Complexity (๋กœ๊ทธ ๋ณต์žก์„ฑ)

์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค : O(log n)

๋‹ค์Œ ์ฝ”๋“œ๋Š” ์ „ํ™” ๋ฒˆํ˜ธ๋ถ€์—์„œ ์ด๋ฆ„์„ ์ฐพ๋Š” ๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ „ํ™” ๋ฒˆํ˜ธ๋ถ€์—์„œ ์ด๋ฆ„์„ ์ฐพ๊ณ  ์žˆ๋Š”๋ฐ ์ •ํ™•ํžˆ ์ค‘๊ฐ„์— ์ฑ…์„ ์—ฐ๋‹ค ๊ณ  ์ƒ์ƒํ•ด๋ณด์‹ญ์‹œ์˜ค. ์ฐพ๊ณ ์žˆ๋Š” ์ด๋ฆ„์ด ํ•ด๋‹น ํŽ˜์ด์ง€์—์—†๋Š” ๊ฒฝ์šฐ ์•ŒํŒŒ๋ฒณ์„ ๊ธฐ์ค€์œผ๋กœ ์ „ํ™” ๋ฒˆํ˜ธ๋ถ€๋ฅผ ์•„๋ž˜๋กœ ๋˜๋Š” ์œ„๋กœ ์ด๋™ํ•˜๋ฉด์„œ ํ•ด๋‹น ์„น์…˜์˜ ์ค‘๊ฐ„์„ ์ฐพ์€ ๋‹ค์Œ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์„ ์ฐพ์€ ํ›„ ๋‚˜๋จธ์ง€ ์„น์…˜์˜ ์ค‘๊ฐ„์œผ๋กœ ๊ณ„์† ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. ์ฐพ๊ณ ์žˆ๋Š” ์ด๋ฆ„์„ ์ฐพ์„ ๋•Œ๊นŒ์ง€ ์ด๊ฒƒ์€ ์ „ํ™” ๋ฒˆํ˜ธ๋ถ€๊ฐ€ ์•ŒํŒŒ๋ฒณ์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜์–ด ์ƒ‰์ธ์„ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์ ์— ์œ ์˜ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์ด ๊ฐœ๋…์„ ์ด์ง„ ๊ฒ€์ƒ‰์ด๋ผ๊ณ ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” ์ด์ง„ ๊ฒ€์ƒ‰์˜ ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค.

function FindItemBinarySearch(items, match) {
     
      var low = 0,
          high = items.length -1;
           
      while (low <= high) {
          mid = parseInt((low + high) / 2);

           current = items[mid];
         
          if (current > match) {
             high = mid - 1;
           } else if (current < match) {
              low = mid + 1;
            } else {
              return mid;
           }   
      }       
      
      return -1;
    }
 
JSLitmus.test('Find colour by colour name', function() {
     FindItemBinarySearch(colours, "Yellow");
});
 
JSLitmus.test('Find number index by number (2500)', function() {
     FindItemBinarySearch(numbersHalf, 2500);
});
  
JSLitmus.test('Find number index by number (5000)', function() {
     FindItemBinarySearch(numbersFull, 5000);
});

์•„๋ž˜ ๊ฒฐ๊ณผ ์„ธํŠธ์—์„œ ์šฐ๋ฆฌ๋Š” colour ๋ฐฐ์—ด ๋ชฉ๋ก์ด ์ œํ•œ๋œ ํฌ๊ธฐ์˜ ๋ฐฐ์—ด๋กœ ์ธํ•ด ๋” ๋งŽ์€ ์‹คํ–‰์„ ํ•  ์ˆ˜ ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํฅ๋ฏธ๋กญ๊ฒŒ๋„ 2500 ๋ฐ 5000 ๋ฐฐ์—ด ํ•ญ๋ชฉ ์‚ฌ์ด์˜ ์ดˆ๋‹น ์ž‘์—… ์ˆ˜์—๋Š” ํฐ ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ด์ œ ์ด์ง„ ๊ฒ€์ƒ‰ ์‚ฌ์šฉ์˜ ์ด์ ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‘ ๋ฐฐ๋‚˜ ๋งŽ์€ ์•„์ดํ…œ์ด์ง€๋งŒ ๋Œ€๋žต ๊ฐ™์€ ํผํฌ๋จผ์Šค๊ฐ€ ๊ทธ ์ž์ฒด๋ฅผ ๋Œ€๋ณ€ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค!

Test Ops/sec
Find colour by colour name 8081984
Find number index by number (2500 items) 3261082
Find number index by number (5000 items) 3055804

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://3.bp.blogspot.com/-SrIDz0CDt-Y/T5HImW9WHmI/AAAAAAAAAO8/2tGSryvYH1Y/s400/binary-search.png

๋ณด๋‹ค ์‹ฌ์˜คํ•œ ์ฐจ์ด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด 5000 ํ•ญ๋ชฉ ๋ฐฐ์—ด์—์„œ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ฐพ์„ ๋•Œ FindItem๋ฉ”์„œ๋“œ Linear Complexity(์„ ํ˜• ๋ณต์žก๋„)์™€ FindItemBinarySearch๋ฉ”์„œ๋“œ Logarithmic Complexity(๋กœ๊ทธ ๋ณต์žก๋„)๋ฅผ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค.

Test Ops/sec
Find number index by number - FindItem 26349
Find number index by number - Binary Search 844153

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://2.bp.blogspot.com/-09gVF5IrEr8/T5HJLRiRdrI/AAAAAAAAAPI/ojBpAHoeKxU/s400/binary-search-vs-linear.png

๋ณด์‹œ๋‹ค์‹œํ”ผ ์„ฑ์žฅ์˜ ์ฐจ์ด๋Š” ๋†€๋ž์Šต๋‹ˆ๋‹ค.

Linear Complexity vs. Logarithmic Complexity

์•ž์œผ๋กœ ๋น„์Šทํ•œ ๋กœ์ง์— ๋Œ€ํ•œ ์ด์ง„ ๊ฒ€์ƒ‰์„ ์‹œ์ž‘ํ•˜๊ณ  ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๋ช‡ ๊ฐ€์ง€ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์ณ ์ปจํ…์ŠคํŠธ๋ฅผ ๊ณ ๋ คํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์„ ํ˜• ๋ณต์žก๋„๋ฅผ ์ด์šฉํ•œ colour ๋ฉ”์†Œ๋“œ์™€ ์ด์ง„๊ฒ€์ƒ‰์„ ์ด์šฉํ•œ colour ๋ฉ”์†Œ๋“œ๋ฅผ ๋น„๊ตํ•ด ๋ด…์‹œ๋‹ค. ์ด์ „์— ๋ณธ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ฒ€์ƒ‰์ด ๋” ๋นจ๋ผ์งˆ ๊ฒƒ์œผ๋กœ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๊นŒ?

๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Test Ops/sec
Find colour by colour name 51804043
Find colour by colour name - Binary Search 7902378

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://3.bp.blogspot.com/-z3bxn1mjU5Y/T5HczUk2iyI/AAAAAAAAAPU/lAaduS7LXlg/s400/battle.png

์ด ๊ฒฝ์šฐ ์„ ํ˜• ๋ณต์žก์„ฑ ์˜ˆ์ œ๊ฐ€ ๋” ์„ฑ๋Šฅ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ž‘์€ ๋ฐฐ์—ด์—์„œ ์ด์ง„ ๊ฒ€์ƒ‰์˜ ์ถ”๊ฐ€ ๋ณต์žก์„ฑ์œผ๋กœ ์ธํ•ด ๋ถˆํ•„์š”ํ•œ ์˜ค๋ฒ„ ํ—ค๋“œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ์˜ ๊ตํ›ˆ์€ ํ•ญ์ƒ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค!

๋‘ ๋ฐฉ๋ฒ•์ด ์„œ๋กœ ๋™์ผํ•œ ์ง€์ ์„ ์‹๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด ๋‘ ๋ฒˆ์งธ ๋ฒค์น˜ ๋งˆํฌ ์„ธํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” 85 ๊ฐœ์˜ ํ•ญ๋ชฉ์ด์žˆ๋Š” ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

// Set up numbers from 1 to 85 
 JSLitmus.test('Find numbers - linear', function() {
  FindItem(numbers, 85);
 });
 
 JSLitmus.test('Find numbers - Binary Search', function() {
  FindItemBinarySearch(numbers, 85);
 });
Test Ops/sec
Find numbers - linear 6045812
Find numbers - Binary Search 6116343

๊ทธ๋ž˜ํ”„ ์ด๋ฏธ์ง€ ์ฃผ์†Œ : http://1.bp.blogspot.com/-APP7aI1q68c/T5HmE-PGDsI/AAAAAAAAAPg/_QdjelVPOvQ/s400/linear-vs-binary.png

์ด๊ฒƒ์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์„ ํƒํ•  ๋•Œ ํ•ญ์ƒ ์ปจํ…์ŠคํŠธ๋ฅผ ๊ณ ๋ คํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์„ ๊ฐ•์กฐํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๋ก 

์ด๋Ÿฌํ•œ ์˜ˆ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Big O ํ‘œ๊ธฐ๋ฒ•์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ๊ฐ€ ์•„๋‹˜์ด ๋ช…๋ฐฑํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ปจํ…์ŠคํŠธ ๊ฐœ๋…์ด ์—†์œผ๋ฉฐ ๋ชจ๋“  ์š”์†Œ๋ฅผ ๊ณ ๋ คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ CPU ์†๋„, ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰ ๋“ฑ์ด ๋‹ค์–‘ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ž…๋ ฅ ํฌ๊ธฐ๊ฐ€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์„ ํƒ์„ ์ถ”๋ก  ํ•  ์ˆ˜ ์žˆ์Œ์„ ๋ณด์—ฌ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์ด ์šฐ๋ฆฌ์—๊ฒŒ ์ฃผ๋Š” ๊ฒƒ์€ ํŠนํžˆ ํฐ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ ์šฐ๋ฆฌ๊ฐ€ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค.