Git Product home page Git Product logo

suffix-tree-implementation's Introduction

Suffix Tree Implementation

Overview

This C++ project implements a compact Suffix Tree data structure, with an efficient Search() operation for any substring. The suffix tree is constructed with a time complexity of O(n^2) and a space complexity of O(n), where n is the length of the input string. The search operation has a time complexity of O(m+occ), where m is the length of the searched pattern, and occ is the number of occurrences of the pattern inside the string.

Features

  • Compact Suffix Tree: Each node in the tree contains a linked list of children nodes, the starting index of the characters on the edge going to this node (substringStartIndex), and the starting index of the suffix ending at this node (used for leaf nodes only, otherwise it is -1).

  • Search Operation: The tree supports a search operation with a time complexity of O(m+occ), making it efficient for finding occurrences of substrings within the original string.

Code Structure

The project is organized into several classes:

  • SuffixTreeNode: Represents a node in the suffix tree, containing information about the substring it represents and its children nodes.

  • Node: Represents a node in the linked list used to store children nodes in each SuffixTreeNode.

  • LinkedList: Represents a linked list of SuffixTreeNodes.

  • SuffixTree: The main class encapsulating the suffix tree construction and search functionalities.

Usage

To use the Suffix Tree implementation, create an instance of the SuffixTree class by providing the input string. After construction, you can perform searches by calling the Search method with the desired pattern.

// Example Usage
SuffixTree suffixTree("example$");
suffixTree.Search("ple");   // Prints: 4
suffixTree.Search("exam");  // Prints: 0
suffixTree.Search("ing");   // Prints: NOT FOUND

Examples

The project includes several test cases in the main function, demonstrating the usage of the suffix tree for different input strings and search patterns.

Installation

Clone the repository to your local machine and compile the C++ code using a compatible compiler. No additional dependencies are required.

Contributors

suffix-tree-implementation's People

Contributors

yusufbadr avatar mansour266 avatar abwael avatar basmalahgad avatar mayazayn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.