TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

# Decompress Binary Messages Using Directed Graphs : Page 3

## When you're faced with a number of possible solutions to a problem, determining the optimal one is a critical task. Follow a practical example for optimization tasks using stored procedures and graphs.

 by Alex Kozak
 Nov 16, 2006
 Page 3 of 5
Finding All Possible Combinations
The stored procedure spu_generateAllCombinations generates all possible combinations of all portions of the message (see Listing 2).

When you compile and execute this procedure, you get the following result for four portions (as illustrated on Figure 1 and Figure 2):

``````
id          forestPath
----------- --------------------
1           01-04
2           01-03,04
3           01-02,03-04
4           01-02,03,04
5           01,02-04
6           01,02-03,04
7           01,02,03-04
8           01,02,03,04
``````

The stored procedure generateAllCombinations is pretty fast. Even for 20 portions of a compressed message (524288 combinations), it will generate and show the result in less than one minute.

Decoding Decimal Paths
So far, this article has walked through splitting a compressed binary message according to certain logic, assigning decimal order numbers to each portion of the message, and finding all possible combinations of the sub-messages (portions). That approach can be applied to any similar problem, but it requires that you translate decimal combinations to corresponding expressions (in this case, to binary sub-messages). The stored procedure spu_convertCombinationsToBinary (see Listing 3) shows how that conversion can be done.

Compiling and executing the spu_convertCombinationsToBinary procedure with the same sample input used previously (10000010011110011) produces the following result:

``````
id          numPath             binPath
----------- ------------------- -------------------------
1           01-04               10000010011110011
2           01-03,04            100000100111100,11
3           01-02,03-04         100000100,11110011
4           01-02,03,04         100000100,111100,11
5           01,02-04            100000,10011110011
6           01,02-03,04         100000,100111100,11
7           01,02,03-04         100000,100,11110011
8           01,02,03,04         100000,100,111100,11
``````

However, this result cannot be considered final until a few more problems have been addressed.