Book Review: Algorithms in C

Written by Robert Sedgewick, a computer science professor at Princeton University, Algorithms in C (link to Amazon) is a collection of two books (though there are more to come) covering the fundamental topics on computer science. Right now it’s divided into five parts: Fundamentals Data Structures Sorting Searching Graphs I just went through the first […]

Solution to Project Euler 4

Here’s the description for Problem 4 on Project Euler: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product of two 3-digit numbers. As usual the brute force approach was my first guess, […]

Knapsack Problem Dynamic Programming Algorithm

The Knapsack problem is probably one of the most interesting and most popular in computer science, especially when we talk about dynamic programming. Here’s the description: Given a set of items, each with a weight and a value, determine which items you should pick to maximize the value while keeping the overall weight smaller than […]

Solution to Project Euler 3

Problem 3 on Project Euler is another easy one. Here’s the description: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? A simple brute force approach, testing all factors of the number to see if they are prime and storing the largest […]

Solution to Project Euler 2

Time for another solution of the Project Euler. Problem 2 is not that difficult either, but it will require more computing power. Here’s the description: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, […]

The Sieve of Eratosthenes (Implemented in C)

If you like programming puzzles and challenges you’ll notice that many of them involve prime numbers in one way or another. As such it becomes handy to have a large table of prime numbers ready to go. One of the easiest yet efficient methods to generate a list of prime numbers if the Sieve of […]

Solution to Project Euler 1

My plan is to post a solution to all the ProjectEuler.net problems I have managed to solve. But don’t worry I won’t spoil your fun throwing out the answer right away. Instead I’ll describe my reasoning and paste my code, so that you can work on your own solution. Problem 1 has the following description: […]

Online Algorithm Directories and Repositories

Whenever I trying to understand some new algorithm to solve a particular problem my first call is Cormen’s Introduction to Algorithms. However, not all problems are covered there, and not all covered ones come with actual implementations (or at least with pseudo-code) so that you can get a hint even on the details. To solve […]

Poker Hand Evaluator in C

Problem 54 on ProjectEuler.net was an interesting one. Instead of the usual math puzzle it had a more practical topic: Poker. You basically need to evaluate the hands of two players for 1000 rounds, and then determine how many rounds rounds player one wins. The hand evaluator I built was quite naive and used a […]