Lecture 015

Complexity Table for Data Structure

Unsorted Sorted by Key Linked List Hash Table Tree
lookup O(n) O(log(n)) O(n) O(1) avg. amt O(log(n))
insert O(1) amt O(n) O(1) O(1) avg. amt O(log(n))
find_min O(n) O(1) O(n) O(n) O(log(n))

But a tree can be a linked list in worst case.

Trees

Tree Data Structure

Tree Data Structure

A tree can be:

Different Trees Structure

Different Trees Structure

Edge Cases of Checking Valid Trees

Binary Search Tree (BST)

More specification: is_tree() && is_ordered().

Check Ordered:

We cannot perform local check (wrong code)

We cannot perform local check (wrong code)

Two correct ways to check

Two correct ways to check

Inserting into BST

Insertion

Insertion

BST Dictionary

It is not sufficient to re-use the old dictionary library

Wrong code

Wrong code

Table of Content