Solved

Need to form the following array of array.

Posted on 2013-01-25
7
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38818936
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 75

Expert Comment

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

Author Comment

by:jazzIIIlove
ID: 38819591
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 334 total points
ID: 38819723
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
ID: 38820595
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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 334 total points
ID: 38820808
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 86

Assisted Solution

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 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