Save
Trees
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
kawther
Visit profile
Cards (75)
What time complexity does binary search have for an n-element sorted array?
O
(
log
n
)
O(\log n)
O
(
lo
g
n
)
View source
Why can't binary search implement a dictionary storing an array of key-value pairs sorted by key?
Insertion
and
removal
in the middle of a
sorted array
take
Ω
(
n
)
\Omega(n)
Ω
(
n
)
time
Finding the halfway point in a
linked list
also takes
Ω
(
n
)
\Omega(n)
Ω
(
n
)
time
View source
What data structure can be used instead of a sorted array or linked list to implement a dictionary with efficient insertion and deletion?
Binary search tree
View source
What characterizes a binary search tree in terms of node structure and child relationships?
Each node has 0–2
children
For a node with value
x
:
x:
x
:
All left
descendants
have
values
<
x
x
x
All right descendants have values >
x
x
x
Values are assumed to be
distinct
View source
What are the time complexities for finding, inserting, and deleting nodes in a binary search tree?
Finding:
O
(
log
n
)
O(\log n)
O
(
lo
g
n
)
on
average
Insertion and deletion:
O
(
d
)
O(d)
O
(
d
)
time where
d
d
d
is the
depth
of the tree
View source
What is the main idea behind 2-3-4 trees?
Force the tree to be perfectly balanced with all levels full
Allow nodes to contain more than one value to maintain balance
View source
How many children can a
k
−
n
o
d
e
k-node
k
−
n
o
d
e
have in a 2-3-4 tree, and how many values can it contain?
Up to
k
k
k
children
Contains
k
−
1
k-1
k
−
1
values
Allowed values for
k
:
k:
k
:
{
2, 3, 4
}
View source
What is the time complexity for finding a value in a 2-3-4 tree?
O
(
log
n
)
O(\log n)
O
(
lo
g
n
)
View source
What problem can arise in binary search trees that is solved by using 2-3-4 trees?
An
unbalanced
binary search tree can lead to a depth of
Ω
(
n
)
\Omega(n)
Ω
(
n
)
2-3-4 trees force perfect balance, keeping the depth at
Θ
(
log
n
)
\Theta(\log n)
Θ
(
lo
g
n
)
View source
How does inserting a value in a 2-3-4 tree differ depending on whether the leaf node is a 2-node or a 3-node?
For 2-nodes or 3-nodes: Simply add the new value
For
4-nodes
: Split the node, sending one value to the parent and keeping the others as 2-nodes
View source
What happens when inserting a value into a 4-node in a 2-3-4 tree?
It is split into two
2-nodes
, with the middle value sent up to the parent node.
View source
What is the first step to insert a value k in a 2-3-4 tree?
Find the
leaf
that would contain k if it was there
View source
What can be done if the leaf is a 2-node or a 3-node when inserting a new value k?
Add
the
new value
to
the
leaf.
View source
What happens if the leaf is a 4-node when inserting a new value k?
First split it, sending one value up to its parent and keeping the others as 2-nodes.
View source
What is the first step to insert a value k in a 2-3-4 tree?
Find the
leaf
that would contain k if it was there.
View source
What is the time complexity of splitting 4-nodes in a 2-3-4 tree?
O(d)
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What happens to the height d if the root of a 2-3-4 tree is split during insertion?
d increases by
1
.
View source
What can be done if the leaf is a 2-node or a 3-node when inserting a new value k?
Add
the
new value
to
the
leaf.
View source
What happens if the leaf is a 4-node when inserting a new value k?
First split it, sending one value up to its parent and keeping the others as
2-nodes
.
View source
What happens if a 4-node is encountered during insertion in a 2-3-4 tree, and its parent is also a 4-node?
Split all
4-nodes
encountered on the
way down
View source
What is the time complexity of splitting 4-nodes in a 2-3-4 tree?
O(d)
View source
What does a 2-3-4 tree with distinct values look like so far?
A balanced tree with nodes that can hold 2, 3, or 4
keys
View source
How do you find a value v in a 2-3-4 tree?
Let x be the
root
.
If v ∈ x, return a pointer to x.
Otherwise, if x is a
leaf
, return
Not Found
.
Let x be a k-node.
Let x1 ≤ · · · ≤ xk−1 be the values in x.
Let x0 = −∞ and xk = ∞.
Find
xi−1
< v < xi for some i.
Let c be the i’th
child
of x.
Repeat the process with x = c.
View source
How do you insert a value v in a 2-3-4 tree?
Attempt to find v as in finding a value.
Split any
4-nodes
encountered, including the root.
After reaching a leaf L, split it if it is a 4-node.
Add v to L.
View source
When is deleting a value v in a 2-3-4 tree handled?
Next
time
!
View source
What is the first step in finding a value
v
v
v
in a 2-3-4 tree?
Let x be the
root
.
View source
If
v
v
v
is found in the root
x
,
x,
x
,
what is the function's return value?
A
pointer to
x
.
x.
x
.
View source
If
v
v
v
is not found in the root
x
x
x
and
x
x
x
is a leaf, what is the function's return value?
Not Found.
View source
What defines a
k
−
n
o
d
e
k-node
k
−
n
o
d
e
in a 2-3-4 tree?
A node containing
k
k
k
distinct
values
View source
In finding a value in a
k
−
n
o
d
e
,
k-node,
k
−
n
o
d
e
,
how are the values
x
0
x_0
x
0
and
x
k
x_k
x
k
defined?
x
0
=
x_0 =
x
0
=
−
∞
−∞
−
∞
x
k
=
x_k =
x
k
=
∞
∞
∞
View source
What is the recursive step in finding a value in a 2-3-4 tree?
Repeat the process from the start, taking
x
=
x =
x
=
c
,
c,
c
,
where
c
c
c
is the
i
−
t
h
i-th
i
−
t
h
child
of
x
.
x.
x
.
View source
What is the first step in inserting a value
v
v
v
into a 2-3-4 tree?
Attempt to find
v
v
v
using the
finding algorithm
, splitting any
4-nodes
encountered.
View source
After reaching a leaf and splitting it if it is a 4-node, what is the next step in inserting a value into the tree?
Add
v
v
v
to the leaf.
View source
See all 75 cards