Being a musician myself and a Software Engineering major, I htink I can shed some cool light here :P I've done a lot of work on the subject myself and plan on making something big based around this in the future.
When you write an algorithm, your goal is to come up with a solution- fore example, in sorting problems it's to have a sorted list. In algorithmic music composition, the solution is (usually) to have a song, or melody that is pleasing, has structure, etc.
The problem with the solution (hah) is that it is not only objective, but the solution is vastly open ended. With a sorting algorithm, you have only one way to sort a list. With music composition, you have millions of pleasing songs/whatevr your goal is.
So you will need an algorithm that is good for not finding definitive solutions, but OPTIMAL solutions. My suggestion is a genetic algorithm or similar. Genetic algorithms are great because they can create a pool of various optimal solutions.
You'd need to break the composition into parts- have a GA for melody, GA for rhythm, GA for structure, etc. And design your fitness function to fit your needs.
Of course this is only one solution to the problem; there are many and the wikipedia link listed before is a great start.
I recommend checking out:
GenJam: an improvisational jazz Genetic Algorithm designed to trade solos-
http://www.it.rit.edu/~jab/GenJam.html
And this book is very enlightening:
http://www.springer.com/computer/information+systems/book/978-1-84628-599-8
I suppose another fun way would be with neural networks....but giving them sets woud be a bit of an issue probably....it's a lot more work.
Anyways, Good luck in your ventures :P