SlideShare a Scribd company logo
2
Most read
3
Most read
9
Most read
TREES
GRAPHS
AND
HASHING
WHAT IS TREE?
• A tree is a finite nonempty set of elements.
• It is an abstract model of a hierarchical structure.
• consists of nodes with a parent-child relation.
Types of trees:
1.Binary tree
2.Binary search tree
3.AVL trees
4.B trees
5.B+trees
6.Huffman tree
Computers”R”Us
Sales R&DManufacturing
Laptops DesktopsUS International
Europe Asia Canada
BINARY TREE:
 Binary Tree is a rooted tree in which root can have maximum two
children such that each of them is again a binary tree. That means,
there can be 0,1, or 2 children of any node.
 Why do we use trees/need:
1. store information that naturally forms a hierarchy.
2. we can search for a given key in moderate time
3. Manipulate sorted lists of data.
 Applications:
1. Organizing charts
2. File systems
3. Programming environment
 Advantages:
1. Allows easier processing of data
2. It stored on disk very efficiently.
 Disadvantage:
1. Requires more memory space
2. Many rules and restrictions for making connections
GRAPHS:
 A Non linear data structure that consists of a set of nodes (vertices)
and a set of edges that relate the nodes to each other.
 The set of edges describes relationships among the vertices.
Types of graphs:
1.directed graph
2.undirected graph
Graph traversals:
1.Depth-first-search
2.Breadth-first-search
Vertices
Edges=
=
Directed graph Undirected graph
 Why do we use graph:
1. They represent relationship between two or more objects.
2. We can represent the info in network model.
 Applications:
1. facebook.
2. Google maps.
 Advantages:
1. Adapts easily to different kinds of graphs.
2. solve problems from checking whether the nodes are
connected to finding the shortest paths.
 Disadvantage:
In fact the worst case time could be proportional to the number of
vertices.
HASHING:
 In computing, a hash table (hash map) is a data structure which implements
an associative array abstract data type, a structure that can map keys to values. A
hash table uses a hash function to compute an index into an array
of buckets or slots, from which the desired value can be found.
 Hash Table Operations
 Search: compute f(k) and see if a pair exists
 Insert: compute f(k) and place it in that position
 Delete: compute f(k) and delete the pair in that position
 In ideal situation, hash table search, insert or delete takes O(1)
o The size of the array is TableSize.
o Each key is mapped into some number in the range 0 to TableSize – 1.
introduction to trees,graphs,hashing
SOME METHODS
 Truncation:
 e.g. 123456789 map to a table of 1000 addresses by picking 3 digits of the key.
 Folding:
 e.g. 123|456|789: add them and take mod.
 Key mod N:
 N is the size of the table, better if it is prime.
 Squaring:
 Square the key and then truncate
 When an element is inserted, if it hashes to the same value as an already inserted element, then we have a collision.
Collision resolving techniques:
 Separate chaining
Each cell of hash table point to a linked list of records that have same hash function value.
o Open addressing
• In Open Addressing, all elements are stored in the hash table itself.
• Size of table must be greater than or equal to total number of keys
• Linear probing
In linear probing, we linearly probe for next slot.
H(x)=(hash(x)+i)%tablesize
 Quadratic probing
We probe to the i2‘th slot in i’th iteration.
H(x)=(hash(x)+i2)%tablesize
 Double hashing
we perform i*hash2(x) slot in i’th rotation.
COLLISION:
 Why do we need hash tables:
 Internal routers
 We could get O(1) access without a lot of space
 Applications:
 File management- working out where to store records
 Comparing complex values
 Dictionaries
 Security systems
 Advantages:
 It takes O(1) for insertion,searching,deletion
 Hash tables turn out to be more efficient than search trees or any other
table lookup structure.
 They are widely used for associative arrays, database indexing, caches
and sets.
 Disadvantage:
 Hash collisions are practically unavoidable. when hashing a random
subset of a large set of possible keys.
 Hash tables become quite inefficient when there are many collisions.
 Hash table does not allow null values, like hash map.

More Related Content

What's hot (20)

PPTX
Doubly Linked List
V.V.Vanniaperumal College for Women
 
PPT
Heaps
Hafiz Atif Amin
 
PPTX
Trees (data structure)
Trupti Agrawal
 
PDF
AD3251-Data Structures Design-Notes-Tree.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
PPTX
Tree Traversal
Md. Israil Fakir
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Searching and sorting
PoojithaBollikonda
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
PDF
Sorting Algorithms
Mohammed Hussein
 
PPT
Data structures using c
Prof. Dr. K. Adisesha
 
PPTX
Queue in Data Structure
Janki Shah
 
PPT
data structure
hashim102
 
PPT
Linked lists
SARITHA REDDY
 
PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PPTX
Multi ways trees
SHEETAL WAGHMARE
 
PPTX
Selection sort
Jay Patel
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
B and B+ tree
Ashish Arun
 
Trees (data structure)
Trupti Agrawal
 
AD3251-Data Structures Design-Notes-Tree.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Tree Traversal
Md. Israil Fakir
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Searching and sorting
PoojithaBollikonda
 
sparse matrix in data structure
MAHALAKSHMI P
 
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
Sorting Algorithms
Mohammed Hussein
 
Data structures using c
Prof. Dr. K. Adisesha
 
Queue in Data Structure
Janki Shah
 
data structure
hashim102
 
Linked lists
SARITHA REDDY
 
Red black tree
Dr Sandeep Kumar Poonia
 
Multi ways trees
SHEETAL WAGHMARE
 
Selection sort
Jay Patel
 
Linked list
KalaivaniKS1
 
B and B+ tree
Ashish Arun
 

Similar to introduction to trees,graphs,hashing (20)

PPTX
Hashing
LavanyaJ28
 
PDF
Hash pre
Waed Shagareen
 
PPT
Chapter 12 ds
Hanif Durad
 
PDF
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
PPTX
hashing in data strutures advanced in languae java
ishasharma835109
 
PPTX
Presentation.pptx
AgonySingh
 
PPTX
hashing in data structures and its applications
manjeshbngowda
 
PPTX
Hashing And Hashing Tables
Chinmaya M. N
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPTX
asdfew.pptx
hunterkurosaki
 
PPTX
Hashing_and_collision.pptx
punit444kaushik
 
PPTX
Data Structures-Topic-Hashing, Collision
sailaja156145
 
PPTX
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
PPTX
hashing in data structure for Btech .pptx
soniasharmafdp
 
PPTX
hashing in data structure for engineering.pptx
soniasharmafdp
 
PPTX
hashing in data structure for Btech.pptx
soniasharmafdp
 
PPTX
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
PPTX
Hashing
Amar Jukuntla
 
PDF
Data Structure viva questions for lab exam
truparanicse
 
PPTX
presentation on important DAG,TRIE,Hashing.pptx
jainaaru59
 
Hashing
LavanyaJ28
 
Hash pre
Waed Shagareen
 
Chapter 12 ds
Hanif Durad
 
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
hashing in data strutures advanced in languae java
ishasharma835109
 
Presentation.pptx
AgonySingh
 
hashing in data structures and its applications
manjeshbngowda
 
Hashing And Hashing Tables
Chinmaya M. N
 
Hashing Technique In Data Structures
SHAKOOR AB
 
asdfew.pptx
hunterkurosaki
 
Hashing_and_collision.pptx
punit444kaushik
 
Data Structures-Topic-Hashing, Collision
sailaja156145
 
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
hashing in data structure for Btech .pptx
soniasharmafdp
 
hashing in data structure for engineering.pptx
soniasharmafdp
 
hashing in data structure for Btech.pptx
soniasharmafdp
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
Hashing
Amar Jukuntla
 
Data Structure viva questions for lab exam
truparanicse
 
presentation on important DAG,TRIE,Hashing.pptx
jainaaru59
 
Ad

Recently uploaded (20)

PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Dimensions of Societal Planning in Commonism
StefanMz
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPT on the Development of Education in the Victorian England
Beena E S
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
Ad

introduction to trees,graphs,hashing

  • 2. WHAT IS TREE? • A tree is a finite nonempty set of elements. • It is an abstract model of a hierarchical structure. • consists of nodes with a parent-child relation. Types of trees: 1.Binary tree 2.Binary search tree 3.AVL trees 4.B trees 5.B+trees 6.Huffman tree Computers”R”Us Sales R&DManufacturing Laptops DesktopsUS International Europe Asia Canada
  • 3. BINARY TREE:  Binary Tree is a rooted tree in which root can have maximum two children such that each of them is again a binary tree. That means, there can be 0,1, or 2 children of any node.
  • 4.  Why do we use trees/need: 1. store information that naturally forms a hierarchy. 2. we can search for a given key in moderate time 3. Manipulate sorted lists of data.  Applications: 1. Organizing charts 2. File systems 3. Programming environment  Advantages: 1. Allows easier processing of data 2. It stored on disk very efficiently.  Disadvantage: 1. Requires more memory space 2. Many rules and restrictions for making connections
  • 5. GRAPHS:  A Non linear data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other.  The set of edges describes relationships among the vertices. Types of graphs: 1.directed graph 2.undirected graph Graph traversals: 1.Depth-first-search 2.Breadth-first-search Vertices Edges= = Directed graph Undirected graph
  • 6.  Why do we use graph: 1. They represent relationship between two or more objects. 2. We can represent the info in network model.  Applications: 1. facebook. 2. Google maps.  Advantages: 1. Adapts easily to different kinds of graphs. 2. solve problems from checking whether the nodes are connected to finding the shortest paths.  Disadvantage: In fact the worst case time could be proportional to the number of vertices.
  • 7. HASHING:  In computing, a hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.  Hash Table Operations  Search: compute f(k) and see if a pair exists  Insert: compute f(k) and place it in that position  Delete: compute f(k) and delete the pair in that position  In ideal situation, hash table search, insert or delete takes O(1) o The size of the array is TableSize. o Each key is mapped into some number in the range 0 to TableSize – 1.
  • 9. SOME METHODS  Truncation:  e.g. 123456789 map to a table of 1000 addresses by picking 3 digits of the key.  Folding:  e.g. 123|456|789: add them and take mod.  Key mod N:  N is the size of the table, better if it is prime.  Squaring:  Square the key and then truncate  When an element is inserted, if it hashes to the same value as an already inserted element, then we have a collision. Collision resolving techniques:  Separate chaining Each cell of hash table point to a linked list of records that have same hash function value. o Open addressing • In Open Addressing, all elements are stored in the hash table itself. • Size of table must be greater than or equal to total number of keys • Linear probing In linear probing, we linearly probe for next slot. H(x)=(hash(x)+i)%tablesize  Quadratic probing We probe to the i2‘th slot in i’th iteration. H(x)=(hash(x)+i2)%tablesize  Double hashing we perform i*hash2(x) slot in i’th rotation. COLLISION:
  • 10.  Why do we need hash tables:  Internal routers  We could get O(1) access without a lot of space  Applications:  File management- working out where to store records  Comparing complex values  Dictionaries  Security systems  Advantages:  It takes O(1) for insertion,searching,deletion  Hash tables turn out to be more efficient than search trees or any other table lookup structure.  They are widely used for associative arrays, database indexing, caches and sets.  Disadvantage:  Hash collisions are practically unavoidable. when hashing a random subset of a large set of possible keys.  Hash tables become quite inefficient when there are many collisions.  Hash table does not allow null values, like hash map.