Basically your machine stores a database of all program files installed.
When you ask for something to be installed,
apt-get first checks the local list to see if it's already installed. If not then goes out to the web to bring down a up-to-date list of files available from the repositories.
Each program has a list of what files it requires to work properly (called Prerequisites or Required) and what programs rely on it (called Dependences)
Apt-Get then checks through the local list to see if everything is there. If not it selects the prerequisites required and adds them to your install request.
Help Has Been Taken
When you install a program, its dependencies must be installed at the same time. Usually, most of the required dependencies will already be installed, but a few extras may be needed, too. So, when you install a package, don't be surprised if several other packages are installed too - these are just dependencies which are needed for your chosen package to function properly.
By default, many useful programs are already installed when you put Ubuntu onto your computer. However, you may need a particular piece of software that serves a purpose not served by the default applications. You might just want to try an alternative program to one which is already installed. In other words, you need new software.
Please check the following articles: