Solved

Need to form the following array of array.

Posted on 2013-01-25
7
168 Views
Last Modified: 2013-01-27
Hi there;

sketch1
I try to form the following structure as array. But I am lost in dimensions.
Can someone aid me for C# of the attached image? (Java is also appreciated for learning purpose).

My code is  as follows which is obviously false..

  int[] flower = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[,] []arr = {{ flower, flower}};

Open in new window


This is for educational purpose.

Regards.
0
Comment
Question by:jazzIIIlove
  • 3
  • 2
  • 2
7 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Why a multi-dimensional array?...

You're implementing a tree with many elements and an unspecified depth.  I would recommend you actually use an object oriented approach with a List() contained within a Node Class.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
I would suggest a Dictionary of Dictionary of Dictionary...  to mimic a tree.
0
 
LVL 12

Author Comment

by:jazzIIIlove
Comment Utility
ok Dictionary seems an optimum solution.
So, suppose the depth is 3. What would be the Dictionary initialization for this?

I couldn't visualize this..Can you help me?

Regards.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 334 total points
Comment Utility
The more I think about it, this could get messy as the number of levels increase. I think I was too focused on your graphic to think smarter at the time  : \

Nevertheless, here is the answer to your recent question:

var tree = new Dictionary<int, Dictionary<int, List<int>>>();

for (int level1 = 1; level1 < 10; level1++)
{
    tree.Add(level1, new Dictionary<int, List<int>>());

    for (int level2 = 1; level2 < 10; level2++)
    {
        tree[level1].Add(level2, new List<int>());
    }
}

tree[1][1].Add(4);

Open in new window


You might want to instead search for a tree implementation that is specific to your scenario. There are many different kinds of trees, so it would be difficult to suggest an implementation without knowing what was to be accomplished.
0
 
LVL 12

Author Comment

by:jazzIIIlove
Comment Utility
Actually, I am trying to form a some kind of  tree idea in a way that I can do a search.
The image above is for a pattern search.
Set of values will be set in this tree such as:
35671 (numbers inc. level 5),  
3567 (numbers; 3 (level 1), 5(level 2), and 6 (level 3), 7 (level 4)) etc.

Then the input value is searched against the above values,
e.g. 356743
which will fail in 35671 but a success in 3567 since,
3567 in 356743 input matches 3567 in above list whereas,  that input doesn't match 35671 above since 1 kills it.

I think such an algorithm formation above and searching in those per level is a good solution. What do you think?

I thought it would be easier in an array formation that I can search upon*. Btw, your code works as i debug in VS but since you created dictionariy and lists on the fly, I cannot reach the lists directly. Hmm...

Thanks.

Regards.

*since the array of arrays seemed aligned to me and easy to retrieve corresponding value.
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 334 total points
Comment Utility
but since you created dictionariy and lists on the fly, I cannot reach the lists directly.
You can. You just have to index the appropriate levels.

e.g.

List<int> theList = tree[1][1];

...would correspond to:

Screenshot
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 166 total points
Comment Utility
Gotcha...so you're implementing a sort of DAWG structure but with numbers?
http://www.wutka.com/dawg.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now