SlideShare a Scribd company logo
1 of 17
AVL TREE & Hash Table
Waseem Usman (BSCS-S16-LC-023)
Irfan Khan (BSCS-S16-LC-007)
Asad Tahir (BSCS-S16-LC-019)
Zafeer Ramzan (BSCS-S16-LC-002)
AVL TREE
A binary search tree x is called an AVL tree, if:
• b(x.key) ∈ {−1, 0, 1}, and
• x.leftChild and x.rightChild are both AVL trees = the height balance of every node
must be -1, 0, or 1
A
B C
D E
0 0
0 0
1
• Named after their inventor Adelson, Velski & Landis, AVL trees are height
balancing binary search tree.
Balance Factor.
AVL tree checks the height of the left and the right sub-trees and assures that the
difference is not more than 1 or less then -1. This difference is called the Balance
Factor.
BalanceFactor = height(left-subtree) − height(right-subtree)
AVL ROTATIONS
To balance itself, an AVL tree may perform the following four kinds of rotations −
• Left rotation
• Right rotation
• Left-Right rotation
• Right-Left rotation
The first two rotations are single rotations and the next two rotations are double
rotations. To have an unbalanced tree, we at least need a tree of height 2. With this
simple tree, let's understand them one by one.
LEFT & RIGHT ROTATION
• If a tree becomes unbalanced, when a
node is inserted into the right subtree of
the right subtree, then we perform a single
left rotation −
• AVL tree may become unbalanced, if a
node is inserted in the left subtree of the
left subtree. The tree then needs a right
rotation.
LEFT-RIGHT ROTATIONS
Double rotations are slightly complex version of already explained versions of rotations.
To understand them better, we should take note of each action performed while
rotation. Let's first check how to perform Left-Right rotation.
RIGHT-LEFT ROTATIONS
The second type of double rotation is Right-Left Rotation. It is a combination of right
rotation followed by left rotation.
HASH TABLE
Asad Tahir
Zafeer Ramzan
HASHING
• Searching technique based on hash table.
• It is the application of a function to the key value that results in mapping the range of
possible key values into smaller range of relative address.
• If two different Keys have assign same address then Collision occurs.
Data
{ Key H(K)
Hash Function
Address
K1
K2
H(K) Address{Collision
TYPES OF HASHING FUNCTIONS
• Direct Hashing.
• Modulo - Division Hashing.
• Mid - Square Hashing.
• Folding Hashing.
• Pseudo Random Hashing.
• Subtraction Hashing.
DIRECT HASHING
• No algorithmic Manipulation.
• No collision (Minimum no of collisions).
• Limited.
• Not suitable for large key values.
MODULO - DIVISION HASHING
• Also known as Division - Remainder.
• Works with any list size.
• If list size is a prime no than fewer collisions.
• In Which “ K ” is a Key and “ n ” is a List size.
H(K) = K mod n
MID - SQUARE HASHING
• Middle of square.
• Key is squared and the address is selected from the middle of the square no.
Problem :-
Non-Uniform distribution of the key.
FOLDING HASHING
1- FOLD – SHIFT HASHING
Key value is divided into two parts whose size matches the size of the required
address.
2- FOLD – BOUNDARY HASHING
Left and Right no are folded on a fixed boundary between them and the
center no.
PSEUDO RANDOM HASHING
• In which “ a ” is a Chosen Coefficient “ c ” is a Constant and “ n ” is a List size.
Y = ax + c
X = key
H(K) = Y mod n
SUBTRACTION HASHING
• Subtract a fixed no from key.
• In which “ c ” is a fixed no.
• Like Direct Hashing.
• No Collision.
• Suitable for small lists.
H(K) = K-c
THANK YOU

More Related Content

Similar to Avl tree-hash-table

Avl tree
Avl treeAvl tree
Avl tree
Van Pham
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
ratnapatil14
 

Similar to Avl tree-hash-table (20)

Avl trees
Avl treesAvl trees
Avl trees
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
3-avl-tree.ppt
3-avl-tree.ppt3-avl-tree.ppt
3-avl-tree.ppt
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
 
Lect 13, 14 (final)AVL Tree and Rotations.pdf
Lect 13, 14 (final)AVL Tree and Rotations.pdfLect 13, 14 (final)AVL Tree and Rotations.pdf
Lect 13, 14 (final)AVL Tree and Rotations.pdf
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
 
Avl tree
Avl treeAvl tree
Avl tree
 
Splay tree
Splay treeSplay tree
Splay tree
 
4.10.AVLTrees[1].ppt
4.10.AVLTrees[1].ppt4.10.AVLTrees[1].ppt
4.10.AVLTrees[1].ppt
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
 
Avl tree detailed
Avl tree detailedAvl tree detailed
Avl tree detailed
 
Lecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptxLecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptx
 
Lec27
Lec27Lec27
Lec27
 
Avl trees final
Avl trees finalAvl trees final
Avl trees final
 
Stats chapter 3
Stats chapter 3Stats chapter 3
Stats chapter 3
 
4. avl
4. avl4. avl
4. avl
 
DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDYAVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 

Avl tree-hash-table

  • 1. AVL TREE & Hash Table Waseem Usman (BSCS-S16-LC-023) Irfan Khan (BSCS-S16-LC-007) Asad Tahir (BSCS-S16-LC-019) Zafeer Ramzan (BSCS-S16-LC-002)
  • 2. AVL TREE A binary search tree x is called an AVL tree, if: • b(x.key) ∈ {−1, 0, 1}, and • x.leftChild and x.rightChild are both AVL trees = the height balance of every node must be -1, 0, or 1 A B C D E 0 0 0 0 1 • Named after their inventor Adelson, Velski & Landis, AVL trees are height balancing binary search tree.
  • 3. Balance Factor. AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1 or less then -1. This difference is called the Balance Factor. BalanceFactor = height(left-subtree) − height(right-subtree)
  • 4. AVL ROTATIONS To balance itself, an AVL tree may perform the following four kinds of rotations − • Left rotation • Right rotation • Left-Right rotation • Right-Left rotation The first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one.
  • 5. LEFT & RIGHT ROTATION • If a tree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation − • AVL tree may become unbalanced, if a node is inserted in the left subtree of the left subtree. The tree then needs a right rotation.
  • 6. LEFT-RIGHT ROTATIONS Double rotations are slightly complex version of already explained versions of rotations. To understand them better, we should take note of each action performed while rotation. Let's first check how to perform Left-Right rotation.
  • 7. RIGHT-LEFT ROTATIONS The second type of double rotation is Right-Left Rotation. It is a combination of right rotation followed by left rotation.
  • 9. HASHING • Searching technique based on hash table. • It is the application of a function to the key value that results in mapping the range of possible key values into smaller range of relative address. • If two different Keys have assign same address then Collision occurs. Data { Key H(K) Hash Function Address K1 K2 H(K) Address{Collision
  • 10. TYPES OF HASHING FUNCTIONS • Direct Hashing. • Modulo - Division Hashing. • Mid - Square Hashing. • Folding Hashing. • Pseudo Random Hashing. • Subtraction Hashing.
  • 11. DIRECT HASHING • No algorithmic Manipulation. • No collision (Minimum no of collisions). • Limited. • Not suitable for large key values.
  • 12. MODULO - DIVISION HASHING • Also known as Division - Remainder. • Works with any list size. • If list size is a prime no than fewer collisions. • In Which “ K ” is a Key and “ n ” is a List size. H(K) = K mod n
  • 13. MID - SQUARE HASHING • Middle of square. • Key is squared and the address is selected from the middle of the square no. Problem :- Non-Uniform distribution of the key.
  • 14. FOLDING HASHING 1- FOLD – SHIFT HASHING Key value is divided into two parts whose size matches the size of the required address. 2- FOLD – BOUNDARY HASHING Left and Right no are folded on a fixed boundary between them and the center no.
  • 15. PSEUDO RANDOM HASHING • In which “ a ” is a Chosen Coefficient “ c ” is a Constant and “ n ” is a List size. Y = ax + c X = key H(K) = Y mod n
  • 16. SUBTRACTION HASHING • Subtract a fixed no from key. • In which “ c ” is a fixed no. • Like Direct Hashing. • No Collision. • Suitable for small lists. H(K) = K-c