Giter Club home page Giter Club logo

cs3012's Introduction

CS3012

Lowest Common Ancestor Part 1

The first part of this module consists of providing a solution to the Lowest Common Ancestor problem, assuming the Graph is structured as a "binary tree". I wrote the solution in Python. As it is my first attempt using Python, the approach taken is inspired from the geeksforgeeks implementation. However, the corresponding unit tests consist of code written fully by myself.

Lowest Common Ancestor Part 2

For the second part of the project, we were asked to create a new branch, in my case "DAG-implementation" and to change the code so that it works for directed acyclic graphs as well. For this I tried two approaches.

First I aimed to change the initial code as little as possible and to still compute the path from root to each node and then check for the lowest common ancestor. In this case the nodes would have a list of children as opposed to right/left node. This work for any type of Tree. However it does not work for any type of directed acyclic graph, especially when there's a node with two parents.

Second approach was instead of storing the children of each node, to store the parents and then compute a list of all ancestors of each node. Afterwards the lowest common ancestor would be the closest to the node. This approach proved successful and passed all the test cases the previous approach didn't.

cs3012's People

Contributors

retecata 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.