Diferente pentru blog/meet-in-the-middle intre reviziile #18 si #19

Nu exista diferente intre titluri.

Diferente intre continut:

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. Friend of a friend(inteview question)
 
bq. Given two user names in a social network find an easy way to test if they one is a friend of a friend of the other.
A trivial solution is to find first the list of friends for the first user and then the lists of friends for each of his friends. Assuming the network has an average degree of k, this approach does k + 1 requests.
A somewhat faster solution precomputes for each user a list of friend of friends. The number of requests is 1 now but space used is O(nk^2) and the size of a reply is O(k^2).
One neat idea is instead of starting the search from one node, start from both and see when the two search spaces meet. If the distance between two nodes is k and the average branching factor in the network is p then we explore O(p^(k/2)) nodes instead of O(p^k) nodes.
h2. Additional problems
 
1. (Equal partition) Given a set A of 40 real numbers, find out if there is any way to split A in two sets such that the sums of their elements are equal. (O(2^n))
2. (minimal vertex cover) Given a graph of n nodes (n <= 30), find out a set with the smallest number of vertices such that each edge in the  graph has at least one node inside the set. (O(3^n/2))
3. (Square) You're given an array L which represents the sizes of n planks. You have to answer if there's any way to form a square using the planks without breaking them of overlapping them. (complexity O(4^n/2))
4. (15 puzzle) Solve 15 puzzle in at most 40 moves.
5. (pancake puzzle) sort pancakes in optimal number of moves.
1. Friend of a friend(inteview question): Given two user names in a social network find an easy way to test if one is a friend of a friend of the other.
2. Equal partition: Given a set A of 40 real numbers, find out if there is any way to split A in two sets such that the sums of their elements are equal. (O(2^n))
3. Minimal vertex cover: Given a graph of n nodes (n <= 30), find out a set with the smallest number of vertices such that each edge in the  graph has at least one node inside the set. (O(3^n/2))
4. Square: You're given an array L which represents the sizes of n planks. You have to answer if there's any way to form a square using the planks without breaking them of overlapping them. (complexity O(4^n/2))
5. 8 puzzle: Solve 8 puzzle in at most 40 moves.
6. Pancake puzzle: sort pancakes in optimal number of moves.
Try the to solve these problems in the comment section.
http://www.cs.cornell.edu/~wdtseng/icpc/notes/bt3.pdf

Nu exista diferente intre securitate.

Topicul de forum nu a fost schimbat.