Tag Archives: algorithms

Primes in the Key of C#

Yes, prime numbers are a go-to challenge for me that I’ve been casually playing with since my earliest programming days. I’m not alone; prime numbers are important and popular enough that there’s an entire distributed computing project dedicated to finding the highest Mersenne Prime number (primes such as 31 and 127 that are one less than a power of 2). A decent grounding in math is also important for programmers and prime number algorithms are a much better programming exercise than “Hello, World”.

That’s why, during a holiday trip to a local Barnes & Noble, I was looking through their collection of quick and shallow knowledge books (“100 Factoids That Will Make You Sound Knowledgeable  …” ) and found one called Math Squared: 100 Concepts You Should Know. I wasn’t expecting a degree out of this small, 256-page book but it’s been awhile since math class, I thought it might give me some good ideas for programming exercises and I like the feel and smell of new books.
Continue reading

What is Recursive Programming?

When writing programs, it’s often necessary to perform repeating operations on collections of items such as customer orders or invoices.  Often, you can just iterate through the collection or count the items to determine how many times to perform the operation.  When working with a hierarchy of items such as a directory structure where you have an unknown and varying number of levels under each branch, it’s a different story.  For this, the typical method is to use recursive programming, often just called recursion. This is a method in which one routine is designed to analyze the items on one level of the hierarchy, look for any sublevels and then call itself to analyze each sublevel.  Each time the routine calls itself, it creates another instance of itself that works independently until it’s finished and then returns to the instance that called it.

Continue reading