Chapter 09 Advanced Data Structures
Chapter 09 Advanced Data Structures
STRUCTURES
DATA STRUCTURES IN JAVA
PAGE 1
Interval Trees
Interval trees are a powerful data structure that can be used to solve a
variety of problems. They are relatively easy to implement and can be
used to solve problems that would be difficult to solve with other data
structures.
PAGE 2
We can represent the set of intervals as an interval tree. The start points
of the intervals are sorted, and the children of each node represent the
intervals that are completely contained within the interval represented
by the node.
To find the intervals that overlap, we can start at the root of the tree and
recursively check each node. If the start point of the current node is less
than or equal to the end point of the current node, then the current
node represents an interval that overlaps with the current interval. We
can then add the current node to the list of overlapping intervals.
Trie
A trie, also known as a prefix tree, is a tree data structure that is used to
store a set of strings. Each string is stored as a path from the root of the
tree to a leaf node. The nodes in the trie store the characters of the
strings, and the edges in the trie store the relationships between the
characters.
Tries are a very efficient data structure for storing and searching strings.
They can be used to solve a variety of problems, such as:
• String matching: Tries can be used to find all of the strings in a set
that match a given pattern.
• Spell checking: Tries can be used to check if a given word is spelled
correctly.
• Autocomplete: Tries can be used to suggest words that are likely
to be typed next.
PAGE 3
Tries are typically implemented as binary trees, where each node in the
tree stores a character and the children of each node store the characters
that follow the character stored in the node.
Tries are a powerful data structure that can be used to solve a variety of
problems. They are relatively easy to implement and can be used to solve
problems that would be difficult to solve with other data structures.
Suffix Trees
Bloom Filters
A Bloom filter is a probabilistic data structure that allows for fast and
memory-efficient membership testing. It provides a way to answer the
question "Is element X in the set?" without storing the entire set of
elements. Bloom filters can offer significant space savings compared to
traditional data structures like arrays or hash tables.
PAGE 4
the range of 0 to m - 1. For each hash function, we set the bit at the
corresponding index in the bit array to 1.
Bloom filters offer several advantages over traditional data structures for
membership testing. They are:
PAGE 5
• Cannot be used for deletion: Bloom filters cannot be used to delete
elements from the set. Once an element is added to the Bloom
filter, it cannot be removed.
Skip Lists
The bottom level of a skip list is a regular linked list. The next level up
has half as many nodes as the bottom level, and so on. The top level has
only one node.
Each node in a skip list has two pointers: a forward pointer and a down
pointer. The forward pointer points to the next node in the same level.
The down pointer points to the corresponding node in the next level.
PAGE 6
To search for an element in a skip list, we start at the top level and follow
the forward pointers until we reach a node that contains the element we
are looking for. If we don't find the element, we then follow the down
pointer to the next level and repeat the process.
Skip lists have several advantages over other data structures, such as
linked lists and binary search trees. They are typically faster for
searching, insertion, and deletion, and they are also more scalable.
Treaps
Link-Cut Trees
PAGE 7
• Find-root : Given a node, find the root of the tree to which it
belongs.
Link-cut trees are a powerful data structure that can be used to solve a
variety of problems, such as dynamic connectivity, minimum spanning
trees, and range minimum queries.
Overall, link-cut trees are a powerful and versatile data structure that
can be used to solve a variety of problems.
PAGE 8