Solved

Need to form the following array of array.

Posted on 2013-01-25
7
173 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:
Suggested Courses

734 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