I was faced with a little riddle (kinda like some of those UVa questions) – Can I design an algorithm that can take an excel sheet like this:
And create a tree structure that a computer program can understand? I can’t assume that the number of rows and columns will be fixed. The algorithm should cater for tree with large number of branches and leaves (row count), of a practically limitless depth (column count).
I should not assume also that the first cell will be the root of the tree. Should I not be able to set any cell that is a parent as a root?
Here’s the pseudocode:
What kind of pseudocode is this you ask? I don’t know myself. I didn’t use any reference to write it; just thought it looked very clear what the algorithm should be doing having written this way.
TestComplete script (JScript):
Here’s the output from TestComplete:
Download the excel file I use to test it (*.xlsx): TableToTree