Biantian's Studio.

DS 03

Word count: 281Reading time: 1 min
2020/04/13 Share

Time Complexity

  • Average Case complexity = average complexity over all possible inputs/situations (we need to know the likelihood of each of the input!)

  • Worst Case complexity = the worst complexity over all possible inputs/situations

  • Best Case complexity (mostly useless) = the best complexity over all possible inputs/situations

  • Amortized complexity = average time taken over a sequence of consecutive operations

Trees

Binary Search Tree

1. Definition

Binary Search Tree is a tree which is either empty or

  1. values in the left subtree are smaller than in the root.
  2. values in the right subtree are larger than in the root.
  3. root's left and right subtrees are also Binary Search Trees.

AVL Trees

The imbalance at a node is:

the height of its left subtree - the height of its right subtree

1. Definition

A binary tree is said to be AVL when the imbalance at each node is either 1,0 or -1.

2. Perfect Binary Tree = Maximal AVL tree of a given height

If the tree has height h, then the number of nodes is

3. Fibonacci trees = Minimal AVL trees of a given height

In general, we obtain the Fibonacci tree of height h+2 (called ), from the Fibonacci trees of height h and h+ 1 (called and , respectively) as:

the size of = 1 + size of + size of .

Because all minimal AVL trees of a given height have the same size, we can pick just one representative AVL tree for every height.

Complexities

Fix out the relationship between Fibonacci trees and Fibonacci numbers, then get the height (number of comparation we might take) of tree from its size, then we can find complexities for search(x), insert(x) and delete(x) are .

CATALOG
  1. 1. Time Complexity
  2. 2. Trees
    1. 2.1. Binary Search Tree
      1. 2.1.1. 1. Definition
    2. 2.2. AVL Trees
      1. 2.2.1. 1. Definition
      2. 2.2.2. 2. Perfect Binary Tree = Maximal AVL tree of a given height
      3. 2.2.3. 3. Fibonacci trees = Minimal AVL trees of a given height
        1. 2.2.3.1. Complexities