SCC.121: Fundamentals of Computer Science - Sorting, Trees and Graphs

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

1/23

flashcard set

Earn XP

Description and Tags

Flashcards covering dictionary ADT, binary search trees, and self-balancing search trees.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

Dictionary (Map) ADT

An ADT with operations insert, delete, and find.

2
New cards

insert(Key k, Value v)

Stores an entry with the key-value pair (k, v). Error if k is already present.

3
New cards

delete(Key k)

Deletes the entry associated with key k. Error if it does not exist.

4
New cards

find(Key k)

Determines whether there is an entry associated with key k. Returns the associated value if it exists, otherwise returns null.

5
New cards

Common implementations of dictionary ADT

Sorted arrays, Search trees, Hashing

6
New cards

Naïve implementation of Dictionary ADT

Storing entries in a linear array without sorting, resulting in O(n) time for find.

7
New cards

Sorted array implementation of Dictionary ADT

Sorting the entries and performing a binary search, resulting in O(log n) time for find but O(n) for updates.

8
New cards

Binary Tree

A tree with at most two children per node: left child and right child.

9
New cards

Binary Search Tree (BST)

A binary tree where each node has a key-value pair, and nodes are sorted by their keys.

10
New cards

Sorted in BST

For every node, its key is greater or equal to all keys in its left subtree and strictly smaller than all keys in its right subtree.

11
New cards

Time Complexity of Find in BST

The worst-case complexity of find() is O(h), where h is the height of the BST.

12
New cards

Height of BST

BST height is between log n and n.

13
New cards

BST Insertion

If x is null, insert new node. If x has key, give error. Else if key < x’s key, recurse left. Else recurse right

14
New cards

Time Complexity of Insertion in BST

For a BST of height h, worst-case time complexity = O(h)

15
New cards

BST Deletion

Find the node to delete. If it's a leaf, remove it. If it has one child, replace it with the child. If it has two children, find the successor, replace the node with the successor, and delete the successor.

16
New cards

Successor of a node

Node in tree with value just above that of provided node value

17
New cards

Operations on a BST

All operations have a worst-case time complexity of O(h), where h is the height.

18
New cards

Self-Balancing Search Trees

Self-balancing search trees that maintain a balanced height to ensure efficient operations.

19
New cards

Examples of Self-Balancing Search Trees

2-3 trees, AVL trees, Red-black trees, B-trees, Splay Trees, Treaps

20
New cards

2-nodes

Nodes with 1 key and 2 children.

21
New cards

3-nodes

Nodes with 2 keys and 3 children.

22
New cards

Find in 2-3 trees

Works almost just as in BSTs.

23
New cards

Insertion in 2-3 Trees

Either a 2-node is transformed into a 3-node, or a 3-node is split into three 2-nodes

24
New cards

Cons of 2-3 Trees

Are quite inconvenient to implement with different types of nodes requiring multiple compares and moving back up the tree to split 4-nodes