Why would you use Top Down Dynamic Programming over Bottom Up? - dynamic-programming

I'm a bit confused about Top down style Dynamic Programming. Why would you ever implement it in practice? Wouldn't using a Bottom Up program always be faster as the Top Down involves recursion (so more overhead) while Bottom Up involves loops? Thanks guys.

CLRS seemed to provide a good answer to my question.
Benefits of Top-Down are that you only need to solve subproblems that are definitely required, so if some subproblems are in the subproblem space and do not need to be solved, you'd be wasting computational resources solving them with bottom up.
Would be interested in other answers/reasons though. Thanks!

Related

Sequence of Smaller Sub-Problems is Known to be Which Design Approach?

To solve a problem, it is broken in to a sequence of smaller sub-problems, till a stage that the sub-problem can be easily solved. What is this design approach called?
Is It a,
Top-Down approach,
Bottom-up approach,
Procedural Programming,
Dynamic programming,
Divide & Conquer
i'm Confused as the Question is asking for "Breaking into Sequence of Smaller Sub-Problems"
Procedural programming break down a programming task into Modules.
Dynamic Programming breaks problem into subproblems.
Divide & Conquer also means the same.
Top down approach is also a stepwise approach.
What would be the Exact Answer for this ?
this design paradigm is called divide and conquer
If the term sequence is to be taken seriously, then I would include pipeline processing in the description of the design approach.

Global Minima and Dynamic Programming

I understand that dynamic programming is a divide and conquer algorithm and use recursive to solve a problem, but I am having difficulty with dynamic programming can achieve to escape local minima?
In dynamic programming approaches, you evaluate all possible cases just like a brute force algorithm but only reuse solutions to sub problems that have already been computed. Thats why you always achieve the global solution to your problem.
The way DP works is that you build a bigger optimal solution from the optimal solutions to smaller problems. You don't really have local minima that way, so you can't talk about escaping them. You're always at the optimal point of whatever (sub)problem you're at - any time you get a solution to some (sub)problem, it will be optimal. That's completely different from having a complete (but possibly non-optimal) solution that you're trying to successively improve until you reach optimality.

What is the difference between dynamic programming and branch and bound?

I only know that by branch and bound, one can REDUCE the procedure to obtain a solution, but that only helps for problems which have a solution space tree.
Dynamic Programming
Dynamic programming (usually referred to as DP ) is a very powerful technique to solve a particular class of problems. It demands very elegant formulation of the approach and simple thinking and the coding part is very easy. The idea is very simple, If you have solved a problem with the given input, then save the result for future reference, so as to avoid solving the same problem again. Shortly 'Remember your Past' .
If the given problem can be broken up in to smaller sub-problems and these smaller subproblems are in turn divided in to still-smaller ones, and in this process, if you observe some over-lappping subproblems, then its a big hint for DP. Also, the optimal solutions to the subproblems contribute to the optimal solution of the given problem ( referred to as the Optimal Substructure Property ).
There are two ways of doing this.
1.) Top-Down : Start solving the given problem by breaking it down. If you see that the problem has been solved already, then just return the saved answer. If it has not been solved, solve it and save the answer. This is usually easy to think of and very intuitive. This is referred to as Memoization.
2.) Bottom-Up : Analyze the problem and see the order in which the sub-problems are solved and start solving from the trivial subproblem, up towards the given problem. In this process, it is guaranteed that the subproblems are solved before solving the problem. This is referred to as Dynamic Programming.
Branch And Bound
A branch-and-bound algorithm consists of a systematic enumeration of candidate solutions by means of state space search: the set of candidate solutions is thought of as forming a rooted tree with the full set at the root.
The algorithm explores branches of this tree, which represent subsets of the solution set. Before enumerating the candidate solutions of a branch, the branch is checked against upper and lower estimated bounds on the optimal solution, and is discarded if it cannot produce a better solution than the best one found so far by the algorithm.
For more Information About Branch and Bound Please refer this link :
http://www.cs.umsl.edu/~sanjiv/classes/cs5130/lectures/bb.pdf
Dynamic programming requires a recursive structure (a.k.a., optimal substructure in CRLS). That is, at a given state, one can characterize the optimal decision based on partial solutions.
Branch and bound is a more general and is used to solve more difficul problems via implicit enumerations of the solution space.

Suffix tries vs dynamic programming for string algorithms

It seems that many difficult string algorithms can be solved both using suffix tries(trees) and Dynamic Programming.
But I am not sure which approach is best to use and when.
Additionally which approach is better to master on the specific area of algorithms and have it in your arsenal in the area of job interviews? I assume it would be the one that would be used more frequently by a programmer in any task or something like that?
This is more of which algorithmic technique is more useful to master as most frequent to use in your job than simply comparing asymptotic notations
Think of a problem requiring the Lexicographically nth substring of a given string : A suffix array is just what you need...and it is easy to learn the bare essentials for solving most problems involving suffix arrays..
On the other hand DP is an algorithmic technique..MASTER IT and you will be able to solve a HUGE number of problems..not only strings.
For an interview though i will take DP anyday...for interviewers, a DP problem lets them make it knotty that is almost impossible to solve without DP (within given constraints) but the solution would mean that you give them a basic recursion and how DP helps you solve it.If it were a suffix-array-only-problem that would mean that they are assessing you over a single data structure( easy once learned) rather than an more general technique which requires mastery.
PS: I had put off learning DP until recently when i got fed up trying to solve problems (that require DP ) using any advanced data structures and would invariably fail ( Case in point : UVA 1394 -- simple problem now that i know how to solve it using DP but instead went on to study segment trees and achieved a O(nlgn) whereas DP gave me O(n). So final advice : if one hasn't studied DP drop everything else and go for it.
honestly, for job interview, no suffix tree is needed. that's too difficult and beyond the scope. however, DP is widely used in interviews for some famous companies like google and facebook.
suffix tree has limitation for solving problems compared with DP. usually it is used to solve string related problems. but DP can solve many different areas.

Can basic Geometry ever come useful to a Beginner to Intermediate skilled Java coder?

Just Curious. I'm currently foraying into the world of Java coding, and, was wondering weather Geometry can come useful in the kind of programming a Beginner to Intermediate Skill level Java coder has.
Depends on what you will code. Java is just a language laden with tons of useful apis. But knowing a bit of geometry can never hurt. If you are gonna code a lot of layouts you might find knowledge of shapes and forms can come pretty handy.
Even without real application needs, some exercises on geometry or other forms of maths can only help you design/code better.
It can be useful if the problems you need to solve require an application of geometry to do so. Other than that, I think that the only benefit geometry would provide would be the added benefit of thinking critically.
Depends what you mean by "basic". In these days of graphical user interfaces, nearly everyone needs Pythagoras sooner or later...
You can learn Java without knowing a single point of geometry.
That being said, I can't think of many situations where knowing geometry would be a bad thing.

Resources