Chapter 4
Data structures
Chapter about..
• Elementary data structures
• Hash tables
• Binary search trees
• Red black trees
• Augmenting data structures
Elementary data structures
• Stacks and queues
• Linked lists
• Implementing pointers and objects
• Binary trees
• Representing rooted trees
• The representation of dynamic sets by simple
data structures that use pointers.
• Complex data structures can be fashioned
using pointers.
Stacks and queues
• In a stack, the element deleted from the set is
the one most recently inserted: the stack
implements a last-in, first-out, or LIFO, policy.
• In a queue , the element deleted is always the
one that has been in the set for the longest
time: the queue implements a first-in, first-
out, or FIFO, policy.
Stacks
• INSERT operation on a stack  PUSH
• DELETE operation POP.
• top[S] that indexes the most recently inserted
element.
• The stack consists of elements S[1..top[S]], where
S[1] is the element at the bottom of the stack and
S[top[S]] is the element at the top.
• When top [S] = 0, the stack contains no elements
and is empty
• If an empty stack is popped, stack underflows,
which is normally an error.
• If top[S] exceeds n, the stack overflows.
An array implementation of a stack S. Stack elements
appear only in the lightly shaded positions. (a) Stack
S has 4 elements. The top element is 9. (b) Stack S
after the calls PUSH(S, 17) and PUSH(S, 3). (c) Stack S
after the call POP(S) has returned the element 3,
which is the one most recently pushed. Although
element 3 still appears in the array, it is no longer in
the stack; the top is element 17.
Queue
INSERT operation on a queue ENQUEUE,
DELETE operation DEQUEUE; like the stack
operation POP, DEQUEUE takes no element
argument.
The FIFO property of a queue causes it to
operate like a line of people in the registrar's
office. The queue has a head and a tail
Chapter 4.pptx
Linked lists
• A linked list is a data structure in which the
objects are arranged in a linear order.
• Unlike an array, though, in which the linear
order is determined by the array indices, the
order in a linked list is determined by a pointer
in each object.
• Linked lists provide a simple, flexible
representation for dynamic sets
doubly linked list
Hash Table
• A hash table is an effective data structure for
implementing dictionaries. Although searching
for an element in a hash table can take as long
as searching for an element in a linked list.
• Direct-address tables
• Hash tables are a common approach to the
storing/searching problem.
What is a Hash Table ?
 Each record has a special
field, called its key.
 In this example, the key is a
long integer field called
Number.
[ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]
. . .
[ 700]
[ 4 ]
Number 506643548
 Each record has a special
field, called its key.
 In this example, the key is a
long integer field called
Number.
 Each record has a special
field, called its key.
 In this example, the key is a
long integer field called
Number.
Collisions
 This is called a collision,
because there is already
another valid record at [2].
[ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 700]
Number 506643548
Number 233667136
Number 281942902
Number 155778322
. . .
Number 580625685
Number 701466868
When a collision
occurs,
move forward until you
find an empty spot.
Hash functions
 uniform hashing
A good hash function satisfies (approximately) the
assumption of simple uniform hashing: each key is
equally likely to hash to any of the m slots.
 Hashing by division
 Hashing by multiplication
 Universal hashing.
Hashing by division
 division method for creating hash functions, we
map a key k into one of m slots by taking the
remainder of k divided by m. That is, the hash
function is
h(k) = k mod m
Hashing by multiplication
 The multiplication method for creating hash
functions operates in two steps. First, we multiply
the key k by a constant A in the range 0 < A < 1 and
extract the fractional part of kA. Then, we multiply
this value by m and take the floor of the result. In
short, the hash function is
 h(k) = m (k A mod 1)
Universal hashing
 choose the hash function randomly in a way that is
independent of the keys that are actually going to
be stored. This approach, called universal hashing
 h(x) = h(y) is precisely
 be a finite collection of hash functions that
map a given universe U of keys into the range
{0,1, . . . , m - 1}.
BINARY SEARCH TREES
 Search trees are data structures that support many
dynamic-set operations, including
 SEARCH,
 MINIMUM,
 MAXIMUM,
 PREDECESSOR,
 SUCCESSOR,
 INSERT, and DELETE.
 Thus, a search tree can be used both as a
dictionary and as a priority queue.
 Basic operations on a binary search tree take time
proportional to the height of the tree. For a
complete binary tree with n nodes, such operations
run in (lg n) worst-case time.
 Example:
Querying a binary search tree
 the SEARCH operation, binary search trees can
support such queries as MINIMUM, MAXIMUM,
SUCCESSOR, and PREDECESSOR.
RED-BLACK TREES
 the set operations are fast if the height of the
search tree is small; but if its height is large, their
performance may be no better than with a linked
list.
 Red-black trees are one of many search-tree
schemes that are "balance" in order to guarantee
that basic dynamic-set operations take O(lg n)
time in the worst case.
Properties of red-black trees
Each node of the tree now contains the fields color,
key, left, right, and p.
If a child or the parent of a node does not exist, the
corresponding pointer field of the node contains the
value NIL.
red-black properties:
1) Every node has a color either red or black.
2) Root of tree is always black.
3) There are no two adjacent red nodes (A red node
cannot have a red parent or red child).
4) Every path from root to a NULL node has same
number of black nodes
Example
Rotations
AUGMENTING DATA STRUCTURES
It introduced the notion of Dynamic order
statistics
size[x] = size[left[x]] + size[right[x]] + 1 .

More Related Content

PPTX
hashing in data strutures advanced in languae java
PPTX
searching techniques.pptx
PPTX
Unit viii searching and hashing
PPTX
Stack and queue power point presentation data structure and algorithms Stack-...
PPTX
Hashing Technique In Data Structures
PPTX
Unit 8 searching and hashing
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
hashing in data strutures advanced in languae java
searching techniques.pptx
Unit viii searching and hashing
Stack and queue power point presentation data structure and algorithms Stack-...
Hashing Technique In Data Structures
Unit 8 searching and hashing
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Lec12-Hash-Tables-27122022-125641pm.pptx

Similar to Chapter 4.pptx (20)

PPT
1.2 Kernel Data Structures.ppt
PPT
Data Structures 8
PDF
advanced searching and sorting.pdf
PDF
DATA STRUCTURES USING C -ENGGDIGEST
PPTX
stack.pptx
PPTX
Working with python Nice PPT must try very good
PPTX
Data structure and algorithms
PPT
Fundamentalsofdatastructures 110501104205-phpapp02
PPTX
data science
PDF
The List Data Model
PPTX
presentation 1 binary search tree in data structures.pptx
PPTX
Presentation.pptx
PPTX
introduction to trees,graphs,hashing
PPTX
Python Data Structures and Algorithms.pptx
PPTX
Queues
PPTX
Data structfghz€zdsrgnhlhlfdshllures.pptx
PPTX
Sorting and hashing concepts
PPTX
Sorting and hashing concepts
PPTX
data structures with algorithms vtu 2023 notes.pptx
1.2 Kernel Data Structures.ppt
Data Structures 8
advanced searching and sorting.pdf
DATA STRUCTURES USING C -ENGGDIGEST
stack.pptx
Working with python Nice PPT must try very good
Data structure and algorithms
Fundamentalsofdatastructures 110501104205-phpapp02
data science
The List Data Model
presentation 1 binary search tree in data structures.pptx
Presentation.pptx
introduction to trees,graphs,hashing
Python Data Structures and Algorithms.pptx
Queues
Data structfghz€zdsrgnhlhlfdshllures.pptx
Sorting and hashing concepts
Sorting and hashing concepts
data structures with algorithms vtu 2023 notes.pptx
Ad

More from Tekle12 (20)

PPTX
MAD-4 (2).pptx mobile application development
PPTX
MAD-3 (2).pptx mobile application development
PPTX
MAD-2.pptx mobile application development
PPTX
MAD-1.pptx mobile application development
PPTX
MAD-4 (2).pptx mobile application development
PPTX
MAD-3 (2).pptx mobile application development
PPTX
MAD-2.pptx mobile application development
PPTX
Chapter 3 - EMTE.pptx artificial intelligence
PPTX
Chapter 2.pptx emerging technology data science
PPTX
Chapter 4 - EMTE.pptx internet of things
PPTX
This is Emerging Technology Power point shared here
PPTX
ch1introduction about android development.pptx
PPTX
Chapter 3 Naming in distributed system.pptx
PPTX
Chapter Introductionn to distributed system .pptx
PPTX
Chapter 6emerging technology - EMTE.pptx
PPTX
Chapter 4about internet of things IoT.pptx
PPTX
Design and analysis of algorithm chapter two.pptx
PPT
Chapter1.1 Introduction to design and analysis of algorithm.ppt
PPT
Chapter 6 WSN.ppt
PPTX
Chapter 2.1.pptx
MAD-4 (2).pptx mobile application development
MAD-3 (2).pptx mobile application development
MAD-2.pptx mobile application development
MAD-1.pptx mobile application development
MAD-4 (2).pptx mobile application development
MAD-3 (2).pptx mobile application development
MAD-2.pptx mobile application development
Chapter 3 - EMTE.pptx artificial intelligence
Chapter 2.pptx emerging technology data science
Chapter 4 - EMTE.pptx internet of things
This is Emerging Technology Power point shared here
ch1introduction about android development.pptx
Chapter 3 Naming in distributed system.pptx
Chapter Introductionn to distributed system .pptx
Chapter 6emerging technology - EMTE.pptx
Chapter 4about internet of things IoT.pptx
Design and analysis of algorithm chapter two.pptx
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter 6 WSN.ppt
Chapter 2.1.pptx
Ad

Recently uploaded (20)

PDF
CS3352FOUNDATION OF DATA SCIENCE _1_MAterial.pdf
PPT
DU, AIS, Big Data and Data Analytics.ppt
PDF
Loose-Leaf for Auditing & Assurance Services A Systematic Approach 11th ed. E...
PPT
expt-design-lecture-12 hghhgfggjhjd (1).ppt
PDF
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
PPTX
CYBER SECURITY the Next Warefare Tactics
PPTX
ai agent creaction with langgraph_presentation_
PDF
©️ 01_Algorithm for Microsoft New Product Launch - handling web site - by Ale...
PPTX
New ISO 27001_2022 standard and the changes
PPTX
CHAPTER-2-THE-ACCOUNTING-PROCESS-2-4.pptx
PPTX
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
PPTX
Caseware_IDEA_Detailed_Presentation.pptx
PPTX
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
PPTX
Phase1_final PPTuwhefoegfohwfoiehfoegg.pptx
PDF
©️ 02_SKU Automatic SW Robotics for Microsoft PC.pdf
PDF
Navigating the Thai Supplements Landscape.pdf
PPT
statistics analysis - topic 3 - describing data visually
PPTX
AI AND ML PROPOSAL PRESENTATION MUST.pptx
PPTX
eGramSWARAJ-PPT Training Module for beginners
PDF
ahaaaa shbzjs yaiw jsvssv bdjsjss shsusus s
CS3352FOUNDATION OF DATA SCIENCE _1_MAterial.pdf
DU, AIS, Big Data and Data Analytics.ppt
Loose-Leaf for Auditing & Assurance Services A Systematic Approach 11th ed. E...
expt-design-lecture-12 hghhgfggjhjd (1).ppt
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
CYBER SECURITY the Next Warefare Tactics
ai agent creaction with langgraph_presentation_
©️ 01_Algorithm for Microsoft New Product Launch - handling web site - by Ale...
New ISO 27001_2022 standard and the changes
CHAPTER-2-THE-ACCOUNTING-PROCESS-2-4.pptx
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
Caseware_IDEA_Detailed_Presentation.pptx
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
Phase1_final PPTuwhefoegfohwfoiehfoegg.pptx
©️ 02_SKU Automatic SW Robotics for Microsoft PC.pdf
Navigating the Thai Supplements Landscape.pdf
statistics analysis - topic 3 - describing data visually
AI AND ML PROPOSAL PRESENTATION MUST.pptx
eGramSWARAJ-PPT Training Module for beginners
ahaaaa shbzjs yaiw jsvssv bdjsjss shsusus s

Chapter 4.pptx

  • 2. Chapter about.. • Elementary data structures • Hash tables • Binary search trees • Red black trees • Augmenting data structures
  • 3. Elementary data structures • Stacks and queues • Linked lists • Implementing pointers and objects • Binary trees • Representing rooted trees • The representation of dynamic sets by simple data structures that use pointers. • Complex data structures can be fashioned using pointers.
  • 4. Stacks and queues • In a stack, the element deleted from the set is the one most recently inserted: the stack implements a last-in, first-out, or LIFO, policy. • In a queue , the element deleted is always the one that has been in the set for the longest time: the queue implements a first-in, first- out, or FIFO, policy.
  • 5. Stacks • INSERT operation on a stack  PUSH • DELETE operation POP. • top[S] that indexes the most recently inserted element. • The stack consists of elements S[1..top[S]], where S[1] is the element at the bottom of the stack and S[top[S]] is the element at the top. • When top [S] = 0, the stack contains no elements and is empty • If an empty stack is popped, stack underflows, which is normally an error. • If top[S] exceeds n, the stack overflows.
  • 6. An array implementation of a stack S. Stack elements appear only in the lightly shaded positions. (a) Stack S has 4 elements. The top element is 9. (b) Stack S after the calls PUSH(S, 17) and PUSH(S, 3). (c) Stack S after the call POP(S) has returned the element 3, which is the one most recently pushed. Although element 3 still appears in the array, it is no longer in the stack; the top is element 17.
  • 7. Queue INSERT operation on a queue ENQUEUE, DELETE operation DEQUEUE; like the stack operation POP, DEQUEUE takes no element argument. The FIFO property of a queue causes it to operate like a line of people in the registrar's office. The queue has a head and a tail
  • 9. Linked lists • A linked list is a data structure in which the objects are arranged in a linear order. • Unlike an array, though, in which the linear order is determined by the array indices, the order in a linked list is determined by a pointer in each object. • Linked lists provide a simple, flexible representation for dynamic sets
  • 11. Hash Table • A hash table is an effective data structure for implementing dictionaries. Although searching for an element in a hash table can take as long as searching for an element in a linked list. • Direct-address tables
  • 12. • Hash tables are a common approach to the storing/searching problem.
  • 13. What is a Hash Table ?  Each record has a special field, called its key.  In this example, the key is a long integer field called Number. [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . [ 700] [ 4 ] Number 506643548  Each record has a special field, called its key.  In this example, the key is a long integer field called Number.  Each record has a special field, called its key.  In this example, the key is a long integer field called Number.
  • 14. Collisions  This is called a collision, because there is already another valid record at [2]. [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 700] Number 506643548 Number 233667136 Number 281942902 Number 155778322 . . . Number 580625685 Number 701466868 When a collision occurs, move forward until you find an empty spot.
  • 15. Hash functions  uniform hashing A good hash function satisfies (approximately) the assumption of simple uniform hashing: each key is equally likely to hash to any of the m slots.  Hashing by division  Hashing by multiplication  Universal hashing.
  • 16. Hashing by division  division method for creating hash functions, we map a key k into one of m slots by taking the remainder of k divided by m. That is, the hash function is h(k) = k mod m
  • 17. Hashing by multiplication  The multiplication method for creating hash functions operates in two steps. First, we multiply the key k by a constant A in the range 0 < A < 1 and extract the fractional part of kA. Then, we multiply this value by m and take the floor of the result. In short, the hash function is  h(k) = m (k A mod 1)
  • 18. Universal hashing  choose the hash function randomly in a way that is independent of the keys that are actually going to be stored. This approach, called universal hashing  h(x) = h(y) is precisely  be a finite collection of hash functions that map a given universe U of keys into the range {0,1, . . . , m - 1}.
  • 19. BINARY SEARCH TREES  Search trees are data structures that support many dynamic-set operations, including  SEARCH,  MINIMUM,  MAXIMUM,  PREDECESSOR,  SUCCESSOR,  INSERT, and DELETE.
  • 20.  Thus, a search tree can be used both as a dictionary and as a priority queue.  Basic operations on a binary search tree take time proportional to the height of the tree. For a complete binary tree with n nodes, such operations run in (lg n) worst-case time.  Example:
  • 21. Querying a binary search tree  the SEARCH operation, binary search trees can support such queries as MINIMUM, MAXIMUM, SUCCESSOR, and PREDECESSOR.
  • 22. RED-BLACK TREES  the set operations are fast if the height of the search tree is small; but if its height is large, their performance may be no better than with a linked list.  Red-black trees are one of many search-tree schemes that are "balance" in order to guarantee that basic dynamic-set operations take O(lg n) time in the worst case.
  • 23. Properties of red-black trees Each node of the tree now contains the fields color, key, left, right, and p. If a child or the parent of a node does not exist, the corresponding pointer field of the node contains the value NIL. red-black properties: 1) Every node has a color either red or black. 2) Root of tree is always black. 3) There are no two adjacent red nodes (A red node cannot have a red parent or red child). 4) Every path from root to a NULL node has same number of black nodes
  • 26. AUGMENTING DATA STRUCTURES It introduced the notion of Dynamic order statistics size[x] = size[left[x]] + size[right[x]] + 1 .