Algorithms
  • Introduction
  • Algorithms
    • Insertion Sort
    • Shell Sort
    • Selection Sort
    • Heap Sort
    • Merge Sort
    • Quick Sort
    • Dual Pivot QuickSort
    • Radix Exchange Sort
  • Data Structures
    • Basic Datastructures
      • Table or Array
      • List
      • Linked List
      • Stack
      • Queue
      • Deque
      • Dictionary
      • HashTables
    • Trees
      • Tree
      • Binary Search Tree
      • Heap
      • Red-Black Trees
      • Splay Trees
      • Randomized Search Trees
    • Dynamic Programming
      • Fibonacci
      • Knapsack
      • Optimal Binary Search Trees
      • Longest Common Sub sequence
    • External Data Structures
      • B-Trees
      • Variants
    • Multi-dimensional Data Structures
      • Point-Region Quadtree
      • Point-Quadtrees
    • Priority Queues
      • Binomial Queues
  • Graphs
    • Basics
    • Depth First Search
    • Applications of Depth First Search
    • Breadth First Search
    • Shortest Paths
    • Transitive Closure
    • Flow Networks
    • Matching
  • Strings
    • Data Structures for Strings
      • Tries
        • Binary Tries
        • Multiway Trie
        • Patricia Tries
      • Variable Length-code
        • Elias Code
        • Gamma Code
        • Fibonacci Code
      • Huffmancode
      • Ternary Search Tree
    • Searching in Strings
      • Prefix Function
      • Knuth-Morris-Pratt
      • Boyer-Moore
      • Monte-Carlo Algorithms
      • Karp-Rabin
      • Automatons
      • Shift-AND
    • Indexing Text
      • Suffix Trees
      • Suffix Arrays
      • Search Engines & Inverted Files
  • P and NP
    • Introduction
    • SAT and 3-SAT
    • Graph Problems
    • Problems with Collections
    • Networks
    • Data storage
  • Metaheuristics
    • Trajectory Methods
      • Local Search
      • Simulated Annealing
      • Tabu Search
    • Population Based
      • Ant Colony
      • Evolutionary Computation
  • Sources
Powered by GitBook
On this page
  • Treap
  • Operations
  • Example

Was this helpful?

  1. Data Structures
  2. Trees

Randomized Search Trees

Randomized search trees use a random generator to neutralise the effect that the order of operations has. The trees stay random, even after every operation.

A common example is the treap

Treap

A treap is a combination of a heap and a tree, every node in this tree gets a priority and a key. These keys are sorted by the heap condition rule which says that the priority of the child should be <= priority of the parent.

The performance of a Treap is O(log(n)) but its worse than the previous trees (red-black, splay, ...) but easier to implement.

Example:

Operations

  • Search: Is identical to the BST searching

  • Insert: Make a new node with a random priority p and add it as you would in a BST. Now fix the heap property.

    • If the parent p > node p --> rotate to make the node parent

    • Repeat this until the heap condition is applied

  • Remove:

    • Remove as in a BST

      • 0 children: remove

      • 1 child: swap with child and remove

      • 2 children: swap with inorder successor (right subtree most left child) and repeat

    • Sometimes a swap can nvalidate the heap property, that's why we have to perform extra rotations sometimes

Example

PreviousSplay TreesNextDynamic Programming

Last updated 6 years ago

Was this helpful?