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

PPT
UNIT-1-PPTS-DAA.ppt
PPTX
Hashing Technique In Data Structures
PPTX
Multiple inheritance possible in Java
PPTX
Inter - thread communication
PPTX
Member Function in C++
PPTX
Inheritance and Polymorphism Java
PPTX
Decision Making Statement in C ppt
PPT
SEARCHING AND SORTING ALGORITHMS
UNIT-1-PPTS-DAA.ppt
Hashing Technique In Data Structures
Multiple inheritance possible in Java
Inter - thread communication
Member Function in C++
Inheritance and Polymorphism Java
Decision Making Statement in C ppt
SEARCHING AND SORTING ALGORITHMS

What's hot (20)

PDF
Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...
PPTX
Javascript alert and confrim box
PPTX
Java basics and java variables
PPTX
STRUCTURE OF SQL QUERIES
PPTX
Switch statement, break statement, go to statement
PPT
YCMOU_FYBCA_DS_Unit-7.ppt
PPTX
Super keyword in java
DOCX
Message queue and shared memory
PPTX
System bus
PDF
Operators in java
PPSX
PPT
pseudo code basics
PPTX
Java Method, Static Block
PPTX
SQL Functions
PDF
C Programming Assignment
PPTX
Sql operator
PDF
Data structure and algorithm notes
PPTX
Html frames
PPTX
Java arrays
Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...
Javascript alert and confrim box
Java basics and java variables
STRUCTURE OF SQL QUERIES
Switch statement, break statement, go to statement
YCMOU_FYBCA_DS_Unit-7.ppt
Super keyword in java
Message queue and shared memory
System bus
Operators in java
pseudo code basics
Java Method, Static Block
SQL Functions
C Programming Assignment
Sql operator
Data structure and algorithm notes
Html frames
Java arrays
Ad

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

PPTX
Hashing techniques, Hashing function,Collision detection techniques
PPTX
Hashing And Hashing Tables
PPTX
Hashing
PPTX
hashing in data structure for Btech.pptx
PPTX
hashing in data structure for engineering.pptx
PPTX
hashing in data structure for Btech .pptx
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
PPTX
Hashing
PPT
PPTX
hashing in data structures and its applications
PPT
Hash presentation
PPTX
unit 3 Divide and Conquer Rule and Sorting.pptx
PPTX
Hashing and Binary Search Tree powerp.pptx
PPTX
Data structures and algorithms lab11
PDF
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
PPTX
asdfew.pptx
PPTX
Data Structures-Topic-Hashing, Collision
PPTX
hashing in data strutures advanced in languae java
Hashing techniques, Hashing function,Collision detection techniques
Hashing And Hashing Tables
Hashing
hashing in data structure for Btech.pptx
hashing in data structure for engineering.pptx
hashing in data structure for Btech .pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Hashing
hashing in data structures and its applications
Hash presentation
unit 3 Divide and Conquer Rule and Sorting.pptx
Hashing and Binary Search Tree powerp.pptx
Data structures and algorithms lab11
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
asdfew.pptx
Data Structures-Topic-Hashing, Collision
hashing in data strutures advanced in languae java
Ad

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Institutional Correction lecture only . . .
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Lesson notes of climatology university.
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
01-Introduction-to-Information-Management.pdf
VCE English Exam - Section C Student Revision Booklet
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 4: Burden of Disease Tutorial Slides S2 2025
Institutional Correction lecture only . . .
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Final Presentation General Medicine 03-08-2024.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Lesson notes of climatology university.
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Basic Mud Logging Guide for educational purpose
01-Introduction-to-Information-Management.pdf

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.