2

I am developing a code for a robot which is supposed to make a product. The process is composed of many tasks. each task may or may not depend on other tasks. I am wondering if there is a better approach than using trees or it's the perfect data structure for it.

1
  • Sounds like a DAG, not a tree to me. Commented Jun 4, 2016 at 15:31

2 Answers 2

6

I think you need a directed acyclic graph for your use-case.

To determine the order of execution of your tasks, you could use a topological sort on the DAG.

Sign up to request clarification or add additional context in comments.

Comments

1

You can also use Adjoint set Datastructure. By using Union find you can resolve dependencies and find an ordered path. Besides that the Time complexity of Adding or removing an element from an Adjoint set is O(1) hence it will take care of the changing requirement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.