Programming contest approach [closed] - algorithm

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
This is broad question, but would like to know views of experts.
I came across one document Suffix arrays – a contest approach, also found some comments that participant should be ready with such data structures already in hand. now a days lot of online programming puzzles are coming with time bound. So I would like to know what are the other data-structures/algorithms should one be ready with.

I have been competing for about 10 years now and have created a not-so-bad library myself. Most of the really good competitors have their blogs for instance the legend Petr Mitrichev and there they explain ideas they got on some competitive problems. Reading these can help you - if you see a nice idea implement it and have it stored.
I add algorithms to my library when I see a problem that involves them. That way I can verify that my implementation is correct- I only add an algorithm if I have passed at least one problem with its implementation.
Here is a list with some of the algorithms I have:
I have a huge geometrial library with classes representing points, lines, polygons, segments, circles and some operations with them(for instance intersection, convex hull of set of points etc)
Tarjan's algorithm for strongly connected components
Dinitz flow algorithm
Bipartite matching implementation
Min cost max flow implementation
Aho-Corasic string searching algorithm
Knuth-morris-pratt string searching algorithm
Rabin-Karp string searching algorithm
Linear time suffix tree using ukonnen's algorithm
Fast exponentiation
Polynom implementation
Big integer implementation
Fractional numbers implementation
Matrix class implementation
Prime factorization
Eratosthenes Sieve
Segment Tree
Hungarian algorithm
2-Sat algorithm. For this I use Tarjan's algorithm mentioned above.
You will notice that some of the most basic algorithms(like BFS,DFS, Dijkstra) are not mentioned above and that is because I don't have them implemented. These algorithms can not be easily generalized in a way that you will simply copy and paste them and everything will work. Also it takes me less then 5 minutes to write them - I usually put in my library only algorithms that are either hard to implement or are easy to make an error when implementing them.

Check out these featured articles # TopCoder. They are really cool.
While you are at it, I suggest taking part in the programming contests at TopCoder. Because the best way to improve is to practice & keep taking part in such contests.
Also Project Euler too is really addictive.

Also, take a look at the Programming Challenges book, it's a great reference on the subject - it presents the topics necessary for succeeding in a programming contest, backed by an online judge.

Related

Dynamic Programming vs Greedy Approach? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I see people biased towards DP approach over the greedy approach because it can solve optimization problems. What you guys think which one of them is preferable? I need to collect arguments in favor of preferable technique to argue with my mates. LOL. Ok, DP is used to solve the problems that have optimal substructure and principle of optimality applies on them. But is it enough for DP to be better than greedy approach?
Your question is meaningless without knowing what problem you are trying to solve.
Dynamic Programming is a tool. It is useful for solving a certain class of problems.
Greedy Algorithms are another tools. They are useful in other situations.
It's like asking "Which is better - a hammer or a saw"?
The answer will be very different depending on what you are trying to do.
Let's take the Coin change example. If you take the Greedy approach you might not get to the correct result most of the times but if you take the DP approach you will always get the right result. In fact, it's the only way to solve the problem which is by using DP.
To answer your question, forget about optimality but using Greedy you might not get a correct solution in the first place for certain kind of problems.

Random Mutation Hill Climber & Simulated Annealing - Which is Fastest? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have used a random mutation hill climbing algorithm as part of a project that I am working on, but was wondering whether it would be better to use simulated annealing to minimise the chance of getting stuck in any local optima.
The question I have is which one tends to be generally faster from your experience? Obviously there is a huge wealth of applications for both algorithms; this is more of a generalised pondering, if you like.
Thank you.
There's no way to tell in advance (unless your project is a 100% match to a well studied academic problem like a pure TSP - and even then ...). It depends on your project's constraints and your project's size (and if you implement the algorithms correctly).
So, to be sure, you have to implement both algorithms (and many others, like Tabu Search, ...) and use a Benchmarker like this one to compare them.
That being said, I 'd put my money on Simulated Annealing over Random Mutation Hill Climbing any day :)
Note: Simulated Annealing is a short but difficult algorithm: I only got it right in my 3th implementation and I 've seen see plenty of wrong implementations (that still output a pretty ok solution) in blogs, etc. It's easier just to reuse optimization algorithms.

List of Mathematics areas to learn for understanding the Algorithm Analysis books (like Introduction to Algorithms) [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Can someone give a brief list of Mathematics areas (like functions, calculus etc.,) to learn for understanding the Algorithm Analysis books (like Introduction to Algorithms)?
I would start with discrete mathematics. That would probably give you the best computational basis and intuition for what computer algorithms are about in terms of working with sets and discrete numbers in general. Also, something on data structures and algorithms would help as well. This would give you good background on things like sorting arrays, efficient searches etc. You could then move on to books on artificial intelligence (my best guess), but by this time you should definitely be ready to read some algorithms books. IMO, that is.
UPDATE
Also, calculus never hurts either if you're working with minimization/maximization/optimization problems. That might or might not bee needed depending on the specific algorithms you'd like to work with.
To start with:
number theory, especially induction.
basic set theory, sets and functions.
basic calculus, limits.
logarithms
discrete math (combinations, permutations, etc)
generating functions (adv. discrete math).
For Introduction to Algorithms the only things you really need to know are induction and some basic set theory. For the more advanced parts you also need to know some linear algebra and probability theory.

Currently known best algorithm(s) for computer chess? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
The community reviewed whether to reopen this question 7 months ago and left it closed:
Original close reason(s) were not resolved
I just wanted to learn name of algorithms.. thanks
A general strategy in game algorithms is the minimax strategy, augmented with alpha-beta pruning. The minimax algorithm finds the best move, and alpha-beta pruning prevents it from going into branches of the game tree that cannot produce a better result than previous branches already have.
However, the chess game tree is too large to be completely examined. That is why computer chess engines only examine the tree up to a certain depth, and then use various methods to evaluate the positions. Many of these methods are based on heuristics. Also, a serious chess-playing program will have a library of openings so that it can play in the beginning by just consulting that library and not having to examine the game tree. Finally, many end games are completely solved, and these are also programmed in as a library.
Minimax
If you need an in-depth knowledge about AI algorithms, I think "artificial intelligence modern approach" book is the best source.
Wikipedia is a safe bet as a starting point. Did you look there?
Rybka seems to be a contender.
Have a look at the some of the free source chess codes, for instance Crafty or even better how about Fruit? It plays pretty much almost the same strength of Rybka. But there are many new algos out there. Day will come when human chess players will have to just say I am not playing vs this engine, and this article pretty much sums it up --> http://www.mychessblog.com/man-versus-machine-when-a-computer-will-become-world-chess-champion/

Where can I learn how to combine algorithms and data structures? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
After reading an introductory book on algorithms and data structures I am now craving for examples on how to combine these for optimal efficiency.
For instance, you can combine hashmaps with specific sorting algorithms to create a simple text search program.
Is there any good book or online resource for this?
(I have already ordered Programming Pearls, which looks great, but I want to learn more about this.)
Any good algorithms book is going to have a chapter or two on the importance of choosing the right data structures. I recommend the following books:
Algorithms in a Nutshell
Introduction to Algorithms
The Algorithm Design Manual
I also recommend you check out the Stony Brook Algorithm Repository, particularly the lectures.
Go to these websites and try out the problems:
acm.uva.es
topcoder.com/tc
SPOJ
Codechef
They have problems to satisfy you for at least the next 3-4 years.
Good book (worked for me):
Data Structures and Algorithm Analysis in Java (Second Edition)
Published by Addison-Wesley, 2007
ISBN: 0-321-37013-9
You're basically asking for what a programmer does all day: Flow data through certain algorithms in such a way that you get the result you want in a timely manner. I suggest that you download Python and work through the tutorials. Python allows you to test your ideas very quickly.
To answer my own question, it seems I just have to read up on a lot of algorithms and real world use cases.
As for books, I've ordered
Programming Pearls to read about how one solves real world problems using a combination of algorithms.
The Algorithm Design Manual by Steven Skiena, which contains a catalogue of alrogithms and war stories on how real world problems were solved.
http://www.amazon.com/Structure-Interpretation-Computer-Programs-Second/dp/0070004846/ref=sr_1_1?ie=UTF8&qid=1301994609&sr=8-1
I can warmly recommend this book. It is rather abstract with examples in Scheme (a Lisp dialect) but it will really change the way you think about programs, data and algorithms.

Resources