Most of the time when a programming puzzle is given most of the students try to Brute force for the solution.Although this is also a technique to find the solution to the problem,don't resort to it always.Resort to Brute force when you have no other way to solve the problem.And if you are going to brute force you are assured of a solution but the time taken to execute is very large for very big inputs.
There are various algorithm design techniques like Divide and Conquer,Dynamic Programming,Greedy algorithms,Branch and Bound,Linear Programming,Backtracking etc.It's very important to know what each design technique means and try to analyze and compare the various design techniques.To be more confident on these design techniques try to solve the programming problems at www.topcoder.com .
I will give you a simple problem in probability.Try to solve this.I am writing this problem because it cannot be solved using brute force method.Think very smart and different to find the solution.
A redundant storage system can survive a certain number of hard drive failures without losing any data. You are doing some analysis to determine the risk of various numbers of drives failing during one week. Your task is complicated by the fact that the drives in this system have different failure rates. You will be given a double[] containing n elements that describe the probability of each drive failing during a week. Return a double[] containing n + 1 elements, where element i is the probability that exactly i drives will fail during a week. Assume that drive failures are independent events.
Examples | |||||||
0) | |||||||
|
| ||||||
1) | |||||||
|
| ||||||
2) | |||||||
|
|