Diferente pentru blog/meet-in-the-middle intre reviziile #8 si #9

Nu exista diferente intre titluri.

Diferente intre continut:

h1. Meet in the middle
Meet in the middle (sometimes called split and merge) is a clever approach which tries to trade off space for time.
 
Let’s discuss a few applications.
Meet in the middle (sometimes called split and merge) is a clever approach which tries to trade off space for time. Let’s discuss a few applications.
h2. a + b + c = d
bq. Given an array of integers, find out if there are any four numbers such that the sum of the first five equal to the 6th (you can use the same number more than once).
bq. Given an array of integers, find out if there are any four numbers such that the sum of the first three equal to the fourth (you can use the same number more than once).
The naive algorithm is $O(N^4^)$ try all the possible combinations of 6 numbers. A less naive algorithm brute forces through all $n^3$ combinations of 5 numbers and then efficiently checks if their sum is in the original array by using a hash table.
The naive algorithm is $O(N^4^)$ try all the possible combinations of four numbers. A less naive algorithm brute forces through all $n^3$ combinations of three numbers and then efficiently checks if their sum is in the original array by using a hash table.
But by now you’ve probably started thinking how meet in the middle can be applied for this problem. The trick is to rewrite the equation as a + b = d - c. Store all the n^3 sums a + b + c in a hash set S. Then iterate through all n^3 combinations for d, e, f and check if S contains f - d - e. This algorithm has O(n^3) time and space complexity.
h2. Bidirectional search(interview question)

Nu exista diferente intre securitate.

Topicul de forum nu a fost schimbat.