title: Best Data Structure representing Package Installation and System Dependencies
body: <p>I'm trying to create a program (I choose Java but can be C/C++ or GoLang) based on an interview process to represent/simulate a Package Installation and System Dependencies like existent in Linux/Unix environments.
  Basically, I'll do following requirements:</p>
  
  <p>1) Maintain a record of installed packages and their dependencies.<br/>
  2) Support explicitly installing a package in response to a command (unless it is already installed).<br/>
  3) Support implicitly installing a package if it is needed to install another package.<br/>
  4) Support explicitly removing a package in response to a command (if it is not needed to support other packages).<br/>
  5) Support implicitly removing a package if it is no longer needed to support another component.<br/></p>
  
  <p>Before installing a package, automatically install all the packages it requires.
  Before removing a package, confirm that no other packages require it. Dependent packages must be removed manually before the package can be removed.</p>
  
  <p>I'd like tips of the best data structure (and the link that I can check) that I can use to do that. I tried using a List of queues as a way to store the dependencies and a Queue to store the packages installed but I'm not sure if this is the best approach like:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>...
  ArrayList&lt;Queue&lt;String&gt;&gt; dependencies = new ArrayList&lt;&gt;(capacity);
  Queue&lt;String&gt; pkgInstalled = new LinkedList&lt;String&gt;();
  ...</code></pre>
  </div>
  </div>
  </p>
  
  <p>The process will capture the entry data from the user until an END command.
  The command syntaxes are:</p>
  
  <p>DEPEND item1 item2 item(n): Package item1 depends on package item2 (and item3 or any;</p>
  
  <p>INSTALL item1: Installs item1 and any other packages required by item1.</p>
  
  <p>REMOVE item1: Removes item1 and, if possible, packages required by item1.</p>
  
  <p>LIST: Lists the names of all currently installed packages.</p>
  
  <p>END: Marks the end of input, when used in a line by itself.</p>
  
  <p>1) Follow each echoed INSTALL or REMOVE line with the actions taken in response, making certain that the actions are given in the proper order.<br/>
  2) For the LIST command, display the names of the components currently installed.<br/>
  3) For the DEPEND and END commands, no output, except the echo, is produced.<br/>
  4) For the DEPEND command, there will only be one dependency list per item.<br/></p>