









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










deq O(N) O(1) O(log 2 N)
enq O(1) O(N) O(log 2 N)*
heap
๋ถ๋ชจ์ ์์น ์ผ์ชฝ ์์์ ์์น: (index-1)/2: (index2)+ ์ค๋ฅธ์ชฝ ์์์ ์์น: (index2)+
hole nextHole
public Object deq() throws QueueUnderflowException{if(isEmpty()) throw new QueueUnderflowException(โโฆโ); Comparable toMove = (Comparable)elements[lastIndex];Object tmp = elements[0]; lastIndexreheapDown(toMove);--; } return tmp; private void reheapDown(Comparable item){int hole = 0; int nextHole;nextHole = findNextHole(hole, item); while(nextHole != hole){elements[hole] = elements[nextHole]; hole = nextHole;nextHole = findNextHole(hole, item); }elements[hole] = item; }
Comparable leftChild = null;// hole์ด ์์์ด ์๋ ๊ฒฝ์ฐ if(left>lastIndex){return hole; }// hole์ด ์ผ์ชฝ ์์๋ฐ์๋ ์๋ ๊ฒฝ์ฐ else if(left==lastIndex){if(item.compareTo(elements[left])>0) return hole; } else return left; // else{ hole์ด ์ผ์ชฝ, ์ค๋ฅธ์ชฝ ์์์ด ๋ชจ๋ ์๋ ๊ฒฝ์ฐ leftChild = (Comparable)elements[left];if(leftChild.compareTo(elements[right])>0){ if(item.compareTo(leftChild)>0) return hole;else return left; }else{ if(item.compareTo(elements[right])>0) return hole;else return right; } } }
O(log 2 N)
O(log 2 N)
deq O(log 2 N) O(1) O(N)
enq O(log 2 N) O(N) O(N)
AVL Tree non AVL Tree
LL Rotate (^) RR Rotate
์ฐพ๊ธฐ ์ฒ๋ฆฌ:: TW (N) = O(log(N) = O(log 2 N) ๊ท ํ: W (N) = O(log^22 N) N ์ ์ฒด: W (N) = O(log 2 N)
๊ฒ์ ์ ์ฒด: T (N) = O(log 2 N)
์ฐพ๊ธฐ ์ฒ๋ฆฌ:: TT (N) = O(log(N) = O(1) 2 N) ๊ท ํ ์ ์ฒด:: WW (N) = O(log(N) = O(log 2 N) 2 N)
์ฆ์ ๋ ดํ๋ฉด์ ๊ฒ์์ ํญ์, AVL ํธ๋ฆฌ๋ ์ผ๋ฐ ์ด์ง ๊ฒ์ ํธ๋ฆฌ์ ๋ฌ๋ฆฌ ์ฝ์ ๊ณผ ์ญ์ ์ ์ฐ์ฐ ๋น์ฉ๋ O(log2N)์ธ ํธ๋ฆฌ์ด๋ค.