Binary Search (2)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

20 Terms

1
New cards

BST Property

Left subtree keys ≤ node key ≤ right subtree keys

2
New cards

BST Node Types

Internal nodes: store keys or key-value pairs; External nodes (leaves): are empty/don't store items

3
New cards

BST Element Requirements

Must have a total order relationship; Must be comparable

4
New cards

Ideal vs Worst Tree Structures

Ideal: Balanced tree with height O(log n); Worst: Linear/degenerate tree with height O(n) (resembles linked list)

5
New cards

BST Time Complexity

Balanced BST: O(log n); Unbalanced BST: O(n)

6
New cards

Binary Search Array Time Complexity

O(log n) in all cases

7
New cards

Space Complexity

O(n) for both BST and arrays

8
New cards

Binary Search Array Requirements

The array must be sorted

9
New cards

BST Remove Operation

No kids: Just cut (remove the node); One kid: Promote (replace with the child); Two kids: Inorder swap (replace with inorder successor)

10
New cards

BST Insert Operation

Search for the position; Reach a leaf node; Plant the new node

11
New cards

BST Search Operation

Compare key with current node; Go left if smaller, right if larger; Repeat until found or reach null

12
New cards

Binary Search in Arrays

Compare target with middle element; Go to left half if smaller, right half if larger; Repeat until found or search space is empty

13
New cards

Key Comparison in BST

Keys less than or equal: left subtree; Keys greater than or equal: right subtree

14
New cards

Degenerate BST

Resembles a linked list with height O(n), making search operations inefficient compared to a balanced tree's O(log n)

15
New cards

BST vs Array Binary Search

Array binary search: Always O(log n); BST search: O(log n) for balanced, O(n) for unbalanced

16
New cards

Total Order Relationship

For any two elements, you must be able to determine their relative order (≤, =, or ≥). All elements must be comparable with each other

17
New cards

External vs Internal Nodes

External nodes represent the endpoints of the tree structure where new nodes can be inserted. They don't store data but mark potential insertion points

18
New cards

Inorder Successor/Predecessor

Replace the node with either its inorder successor (smallest node in right subtree) or inorder predecessor (largest node in left subtree)

19
New cards

BST Height Impact

Height directly impacts time complexity: Height O(log n): Operations are O(log n); Height O(n): Operations degrade to O(n)

20
New cards

Array vs BST Trade-offs

Arrays: Guaranteed O(log n) search but O(n) insertion/deletion; BSTs: O(log n) for all operations when balanced, but can degrade to O(n) if unbalanced