Giter VIP home page Giter VIP logo

binarytree's Introduction

Binary Tree

Find lowest common ancestor

Stack

  • SpringBoot
  • Maven

How to run

In console execute

mvn install
mvn test
mvn spring-boot:run

Api Reference

1. Create a binary tree (POST)

Send a Json tree and obtain a graph of this tree

http://localhost:8080/api/tree

Input Example

{
    "root": {
        "value": 67,
        "leftNode": {
            "value": 39,
            "leftNode": {
                "value": 28,
                "rightNode": {
                    "value": 29
                }
            },
            "rightNode": {
                "value": 44
            }
        },
        "rightNode": {
            "value": 76,
            "leftNode": {
                "value": 74
            },
            "rightNode": {
                "value": 85,
                "leftNode": {
                    "value": 83
                },
                "rightNode": {
                    "value": 87
                }
            }
        }
    }
}

Output example

67
├───39
│  ├───28
│  │  └───29
│  └───44
└───76
   ├───74
   └───85
      ├───83
      └───87

2. Find the lowest ancestor (POST)

Send a Json tree and two nodes and obtain a graph and the lowest common ancestor

http://localhost:8080/api/tree/lowerCommonAncestor

Input Example

{
    "tree": {
        "root": {
            "value": 67,
            "leftNode": {
                "value": 39,
                "leftNode": {
                    "value": 28,
                    "rightNode": {
                        "value": 29
                    }
                },
                "rightNode": {
                    "value": 44
                }
            },
            "rightNode": {
                "value": 76,
                "leftNode": {
                    "value": 74
                },
                "rightNode": {
                    "value": 85,
                    "leftNode": {
                        "value": 83
                    },
                    "rightNode": {
                        "value": 87
                    }
                }
            }
        }
    },
    "firstNode": 29,
    "secondNode": 44
}

Output example

{
    "graph": "67\n├───39\n│  ├───28\n│  │  └───29\n│  └───44\n└───76\n   ├───74\n   └───85\n      ├───83\n      └───87",
    "lowestCommonAncestor": 39
}

binarytree's People

Contributors

johan-lop avatar

Watchers

 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.