Binary Search Tree Theory

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

1/13

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.

14 Terms

1
New cards

Binary Traversal - Preorder traversal

  • visit root

  • traverse left subtree in preorder

  • traverse right subtree in preorder

<ul><li><p>visit root </p></li><li><p>traverse left subtree in preorder </p></li><li><p>traverse right subtree in preorder</p></li></ul>
2
New cards

Build Binary Tree

public class BinaryTreeNode{

int val ;

BinaryTreeNode left ;

BinaryTreeNode right;

}

3
New cards

Post Order Traversal

  • Traverse the left subtree in Postorder.

  • Traverse the right subtree in Postorder.

  • Visit the root.

<p></p><ul><li><p><span>Traverse the left subtree in Postorder.</span></p></li><li><p><span>Traverse the right subtree in Postorder.</span></p></li><li><p><span>Visit the root.</span></p></li></ul><p></p>
4
New cards

In order traversal

  • Traverse the left subtree in Inorder.

  • Visit the root.

  • Traverse the right subtree in Inorder.

<ul><li><p><span>Traverse the left subtree in Inorder.</span></p></li><li><p><span>Visit the root.</span></p></li><li><p><span>Traverse the right subtree in Inorder.</span></p></li></ul><p></p>
5
New cards

Properties of Binary Tree : give h as a height of a binary tree

What is number of maximun node in a full binary tree ?

The maximum number of nodes in a binary tree of height h is 2^(h+1) - 1.

6
New cards

Properties of Binary Tree : give h as a height of a binary tree

What is number of maximun node in a complete binary tree ?

Its range from 2^h → 2^(h+1) -1

7
New cards

Properties of Binary Tree : give h as a height of a binary tree

What is number of leaf node in a full binary tree

2^h

8
New cards

Properties of Binary Tree : give h as a height of a binary tree

What is number of NULL links (wasted pointers ) in a complete binary tree of n nodes

n+1

9
New cards

Basic Operations of full binary tree

  • insert element into a tree

  • delete element from a tree

  • searching an element from tree

  • traversing tree

10
New cards

Auxilliary Operations of Binary Tree

  • find size of tree

  • find height of tree

  • find level which has maximun sum

  • find LCA

11
New cards

Application of Binary Tree

  • Expression trees are used in compilers.

  • Huffman coding trees that are used in data compression algorithms.

  • Binary Search Tree (BST), which supports search, insertion and deletion on a

    collection of items in O(logn) (average).

  • Priority Queue (PQ), which supports search and deletion of minimum (or maximum)

    on a collection of items in logarithmic time (in worst case).

12
New cards

Tree Traversal Ways

  1. DLR ( Preorder)

  2. LDR (Inorder)

  3. LRD (post order)

  4. Level Order Traveral (go through each level)

13
New cards

Level Order Traversal

  • Visit the root.

  • While traversing level (, keep all the elements at level ( + 1 in queue.

  • Go to the next level and visit all the nodes at that level.

  • Repeat this until all levels are completed.

14
New cards
<p>Given a tree , return value In order traversal</p>

Given a tree , return value In order traversal