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.
Related
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.
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.
I was recently reading an article which mentioned:
For God's sake, don't try sorting a linked list during the interview.
Is there any reason why the author wrote this? The reason is not immediately clear. I am aware that merge sort works on linked lists in O(nlgn) time- what's wrong with that? Am I missing something obvious?
EDIT:
Any reason why is question is voted to close? I'm honestly curious and merely looking for some answers or interesting points.
I have no way of knowing why the author of the blog wrote what he did. If I had to guess, I'd say what was really meant was something along the lines of:
Don't assume that efficiently sorting a linked list would be as easy as sorting a data structure that provides random access to its elements. If you do end up relying on being able to sort a linked list, be prepared to explain what a suitable algorithm might be, and to discuss its complexity.
I think you'll find that, although it's possible to sort a linked list using merge sort, the code to do so efficiently is somewhat involved. It's not something you'd want to develop while standing at the white board in the middle of an interview.
The operation of getting/setting elements at specific indices is used by most sorting algorithms, and are required to be fast in order for the sorting algorithms to be fast. Normally they are O(1) for say a normal list, but for a linked list it is O(n) and this makes the sorting terribly inefficient. Perhaps this captures the reasoning behind your quote.
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.
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 12 years ago.
Christoph Koutschan has set up an interesting survey that tries to identify the most important algorithms "in the world". Since one of the criteria is that "the algorithm has to be widely used" I though that extending the survey to the huge group of users at Stack Overflow would be a natural thing to do.
So, what do you think? Which algorithms deserve a place in the Algorithm Hall of Fame?
I somewhat like this algorithm:
Write code.
Test code. If buggy, go to step 3. If not, go to step 4.
Rewrite code, then go back to step 2.
Get somebody else to test your code. If they discover any bugs, return to step 3, otherwise go to step 5.
Congratulations, your code has no obvious bugs! Now you wait for a user to stumble upon a hidden one, in which case you return to step 3 once again unless you're lucky and are no longer providing support for the code in question.
I'd say binary search since it's usually the first algorithm people learn. And the RSA encryption algorithms are pretty important.
Hashing, since it's the basis for so much in security, data structures, etc. Hashing algorithms have generated a lot of Ph.D. dissertations.
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.
I have a technical interview on Monday and they were kind enough to give me a heads-up to brush up on my basic algorithms. It's been years since I looked at that kind of stuff and I'm pretty weak on it to begin with so I generally have a bad feeling about this. What's the best way to review the basics and get some practice in before Monday?
Starting Project Euler might help you, also try picking up Algorithms in a Nutshell and working through those examples. Should be do-able in a weekend.
TopCoder Algorithm Tutorials
Get the Algorithm Design Manual and look at the reference section. It has a nice "Problem -> Algorithm" cheat sheet.
Also take a look at questions on StackOverflow that are tagged Algorithm.
They might actually turn up in the interview ;)
Best of Luck!
This SO Question would be helpful. Also, mostly you should know about
* Sorting
* Searching
* Inserting and removing from various data structures
As this are the main algorithms which are normally asked in the interviews.
*Note: This is from my personal experience and it may differ from person to person.
http://en.wikipedia.org/wiki/List_of_algorithms
Especially the Search, Item Search and Sorting sections.