









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
These are algorithm courses materials.
Typology: Lecture notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!
์ฐ์ ์์ ํ
ํ
heap
ํ: enqueue
ํ: enqueue โ ๊ณ์
ํ์ ๊ตฌํ
๋ถ๋ชจ์ ์์น ์ผ์ชฝ ์์์ ์์น: (index-1)/2: (index2)+ ์ค๋ฅธ์ชฝ ์์์ ์์น: (index2)+
Dequeue
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; }
Dequeue _private int findNextHole(int hole, Comparable item){int left = hole2+1;int right = hole2+2; 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; } } }
ํ VS. ๋ค๋ฅธ ์ฐ์ ์์ ํ ๊ตฌํ
AVL ํธ๋ฆฌ(๊ท ํํธ๋ฆฌ)
AVL Tree non AVL Tree
LL, RR ํ์
LL Rotate (^) RR Rotate
LR ํ์
A B C
RL ํ์
A B C
AVL ํธ๋ฆฌ: ์ฝ์ ์ 15 30 15 30 45
AVL ํธ๋ฆฌ: ์ญ์ โ ๊ณ ๋ ค์ฌํญ 1
AVL ํธ๋ฆฌ: ์ญ์ โ ๊ณ ๋ ค์ฌํญ 2
AVL ํธ๋ฆฌ: ์ญ์ ์
AVL ํธ๋ฆฌ: ์ญ์ ์ โ ๊ณ์