473,473 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to store these data in appropriate mannar?

14 New Member
Hello Friends
I am having a problem in finding the solution for this Question. Please help me.

I am having a number say "n". In this case let us consider n=3.

What i have to do is find first "n" multiples of "n".
Store the answers somewhere.

Find again the first "n" multiples of the answers.
Store the another answers(N1) generated.

Find again the first "n" multiples of the answers(N1) .
Store the answers generated.

Repeat the process "n" times.

So the tree will be formed like this for "n"=3.

---------------1--------------------------------- 2 ----------------------------------------3
1 ------------2----------3----//-----2----------4--------------6----///----3-----------6--------------9
123-------2 4 6----3 6 9-///-2 4 6------4 8 12---- 6 12 18-//-3 6 9----6 12 18-----9 18 27

The "----" and "////" are just show insted of spaces.

Each variable should be stored in such a way. So that I can locate easily from which nodes it was generated.

I dont want the program but just the logic of how to do that.
Oct 8 '08 #1
4 1145
Nepomuk
3,112 Recognized Expert Specialist
Hm, sounds to me like you could do with a storage class. Something like
Expand|Select|Wrap|Line Numbers
  1. class Storage {
  2.       int value;
  3.       Collection<Storage> furtherValues;
  4.       ...
  5. }
Now, that is incomplete and you'd have to choose some type of collection and write setters and getters and so on, but the idea is, that you have a list (or other type of collection) of these Storage classes for the first line and each of them has a further collection with all values related to itself. I'll try to make a graphic:
Expand|Select|Wrap|Line Numbers
  1. 1--------------------2--------------------3
  2. |                    |                    |
  3. 1------2------3      2------4------6      3------6------9
  4. |      |      |      |      |      |      |      |      |
  5. 1-2-3  2-4-6  3-6-9...
I hope, you get the idea.

Greetings,
Nepomuk
Oct 8 '08 #2
JosAH
11,448 Recognized Expert MVP
I don't think you have to store anything at all: if a node number equals 'i' then
you immediately know its children: 1*i, 2*i ... n*i for your chosen value of 'n'.

Finding the parents isn't much more difficult either: let p_1 p_2 ... p_m be the
prime divisors of i. The procuct of them all needs to be divisable by either 2, 3,
... n otherwise 'i' can't be a node in the tree. Neither can there be a prime divisor
p_i > n. If the condition is met then any value of [i-n, i] that can be evenly divided
by n results in a possible parent for node i.

kind regards,

Jos

edit: changed the clumsy text in the last paragraph.
Oct 9 '08 #3
Nepomuk
3,112 Recognized Expert Specialist
I don't think you have to store anything at all: ...
Well, I guess it's some kind of homework and they should store the data - but of course, you're right, it's easy to calculate it again and again and again.

Which way is the right one, only the OP can decide.

Greetings,
Nepomuk
Oct 10 '08 #4
chaarmann
785 Recognized Expert Contributor
You can store your data in a tree structure that is already inside the java API (no need to make your own class and methods to handle the data).
just use:

javax.swing.tree.DefaultMutableTreeNode

Although it's swing library, you don't need to know anything about swing or do anything with swing to use it. Just use it as internal structure for your data, and experience the power of the methods "pathFromAncestorEnumeration()" or "postorderEnumeration()" or "isNodeAnchestor(anotherNode)" without writing a single line of code!
Oct 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
1
by: Patrick | last post by:
I'm trying to create a link from Access 2003 to an Exchange 2000 Public Folder called "WMContacts" I choose File => Get External Data=> Link Tables. I choose Exchange() and the wizard give me the...
4
by: iwdu15 | last post by:
quick question for anyone who can help...im trying to mak a program that will take an entered username and store a list of teams they chose from a list and save that, to be called later. does...
1
by: James T. | last post by:
Hello! I am developing a travel agency web site. Now I am bit stuck and need some advice. I created a 4 step wizard page to add new vacation package to the database. On the 3rd step there is...
4
by: Ranginald | last post by:
Hi, I am generally new to OOP and in learning and writing code I have developed many of my own reusable methods. A. What is the best way to store these methods for easy reuse later? I was...
5
by: rAinDeEr | last post by:
Hi, Can any one show me a sample create table structure for storing .BMP's and .GIF images. togther with its description. Thanks in advance, rAinDeEr
4
by: Dave | last post by:
I have some data values that will will rarely change over the life of the program. I don't think it is wise to save it in a database. Is it ok to save them in Properties.Settings if I have many...
3
blackstormdragon
by: blackstormdragon | last post by:
Here were our instructions: "My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
0
by: Matimus | last post by:
On May 1, 4:37 am, Lance Gamet <la...@gamet.comwrote: sqlite is a wonderful option, if the user doesn't need to directly edit it. Alternatively, you might consider just using python code....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.