Skip to content

SwapnilGite/Splay-Trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Splay Trees - DSA Project

This project implements Splay Trees, a type of self-adjusting binary search tree. Splay trees bring recently accessed elements to the root, optimizing access patterns with locality of reference.

Features

  • Splay tree implementation with insert, delete, search, and traversal operations.
  • Performance analysis and comparison with other tree structures.
  • Example usage and test cases.

Getting Started

Prerequisites

  • Node.js (for JavaScript/TypeScript implementations)
  • Or a C++/Java compiler (if codebase is in C++/Java)

Installation

Clone the repository:

git clone https://github.com/yourusername/DSA-project.git
cd Splay-Trees

Install dependencies (if applicable):

npm install

Running the Code

To run the main program:

# For JavaScript/TypeScript
npm start

# For C++
g++ main.cpp -o splay
./splay

# For Java
javac Main.java
java Main

Usage

The code supports the following operations:

  • Insert: Add a new node to the splay tree.
  • Delete: Remove a node from the splay tree.
  • Search: Find a node and splay it to the root.
  • Traversal: In-order, pre-order, and post-order traversals.

Example (pseudocode):

// Insert elements
tree.insert(10)
tree.insert(20)
tree.insert(5)

// Search for an element
tree.search(20)

// Delete an element
tree.delete(10)

Analysis

The analysis.doc file provides a detailed comparison of splay trees with other binary search trees:

  • Time Complexity:
    • Amortized O(log n) for insert, delete, and search.
    • Worst-case O(n) for a single operation, but sequences of operations are efficient.
  • Advantages:
    • Good for access patterns with locality.
    • No need to store balance information.
  • Disadvantages:
    • Not always optimal for uniformly random access.
    • Can be slower than AVL/Red-Black trees for some workloads.

References

For more details, see analysis.doc and the source code files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors