This problem can be mapped to the Topological sorting of vertices in a graph assuming each component as the vertice in the graph and edge as the dependency indicator.For more details see the link below.
http://en.wikipedia.org/wiki/Topological_sorting
Unix have tsort program for doing the same.
For a DAG(directed acyclic graph) tsort produces a listing of the vertices so that for all edges 'a->b', 'a' comes before 'b' in the listing. This is used in MakeFile for identifying the build order of the components in a way to fulfill dependencies. This will not work when the graph have cycles. (Cyclic dependencies are not taken care).
http://en.wikipedia.org/wiki/Tsort_%28Unix%29
Categories
FollowersBlog Archive
Jobs
Find more freelance jobs
|
Tuesday, October 18, 2011Saturday, August 20, 2011Saturday, August 6, 2011Monday, January 24, 2011Very good resource for algorithms
If you are planning to learn all algorithms in a systematic way, you can visit this site.
http://www.allisons.org/ll/AlgDS/Glossary/ Good thing about this site is it outlines fundamental concept of data structure or algo with example and gives some practical use cases also. Sunday, December 19, 2010My new blog for android users
Hi Friends,
I recently started writing my experiments with android. You can find the link below. http://indiandroidism.blogspot.com/ Sunday, November 21, 2010100 coins dividing into equal heads groups.
Question:
You have 100 coins, 37 of them are heads, rest are tails. Your task is to divide this 100 coins into two groups in which there will be the same number of heads. You are blindfolded and you can flip any number of coins. Solution: Pick any 37 coins and flip all of them. Explanation: Lets take a simple case where 5 coins with 3 heads and 2 tails. HTHHT Lets take 3 coins randomly. Say first,fouth and fifth lets call it S1. Let remaining coins be S2. So we have 2 groups now S1(H,H,T) and S2(T,H) When we flip the selected set S1 it turns into S1F(T,T,H). We have only one head in both the sets. How to select k sample nodes from a unknown sized linked list.?
http://en.wikipedia.org/wiki/Reservoir_sampling can be applied here. Is there any better solution for this problem?
Map reduce implementation of reservoir sampling is discussed in this blog post. http://had00b.blogspot.in/2013/07/random-subset-in-mapreduce.html Sunday, March 28, 2010Finding number of on bits (1 bits) given an unsigned integer?
Sol 1:
Simple Iterative solution.(Very slow) int countbits (unsigned int number) { int count = 0; while (number) { count += number & 0x1u; number >>= 1; } return count; } Sol 2: Faster Solution for 32 bit machines. compute 16bits then add then to return full number of ones in 32 bit number. static char ones_in_16bit_num [0x1u << 16] ; int countbits (unsigned int number) { return ones_in_16bit_num [number & 0xffffu] + ones_in_16bit_num [(number >> 16) & 0xffffu] ; }
Subscribe to:
Posts (Atom)
|
Popular Posts
|