Advanced Data Structurer
Advanced Data Structurer
Structures
Segment Tree
Red-Black Tree
Expression Tree
B-Tree
Table of Conclusion
Contents Q&A
References
Bellman-Ford
Algorithm
o Negative Cycle
Detection:
Perform one more pass:
For each edge (u, v) with
weight w:
If d[u] + w < d[v], a
negative cycle exists
Bellman-Ford Algorithm - Pseudocode
# Step 1: Initialization
for each vertex v in G:
if v is s:
d[v] = 0
else:
d[v] = ∞
π[v] = null
Bellman-Ford Algorithm - Pseudocode
# Step 2: Relaxation
for i from 1 to |V| - 1:
for each edge (u, v) in G:
if d[u] + w(u, v) < d[v]:
d[v] = d[u] + w(u, v)
π[v] = u
Bellman-Ford Space
Algorithm - Complexity: O(V)
Complexity
Segment Tree
Query: O(log n)
Segment
Tree -
Complexity
Update: O(log n)
Red-Black
Tree
o Purpose: Self-balancing
binary search tree
o Key features: Maintains
balance through coloring
nodes
Every node is either red or black
# Delete a node
Delete: O(log n)
Red-Black
Tree -
Search: O(log n)
Complexity
Expression
Tree
o Purpose: Represent and
evaluate arithmetic
expressions
o Key features: Leaves
represent operands, internal
nodes represent operators
Expression
Tree - Key
Concepts
• function buildExpressionTree(expression):
• # Construct the expression tree
•
• function evaluateExpressionTree(node):
• # Evaluate the expression
Build: O(n)
o Purpose: Efficient
cumulative frequency
counting and updating
o Key features: Each
element stores
cumulative frequency of
a range
Binary Indexed
Tree - Key
Concepts
o Structure:
Represented as an
array
Each element stores
cumulative frequency
Build: Construct the binary
indexed tree from an array
• function queryBinaryIndexedTree(index):
Delete: Remove a
key from the B-tree
: B-Tree - Pseudocode
• # Delete a key
B-Tree -
Complexity SEARCH: O(LOG INSERT: O(LOG
N) N)
DELETE: O(LOG
N)