SlideShare a Scribd company logo
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

Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
YibeltalNibretu
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 

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