
Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
On Nov 22, 6:49 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> >Is this possible and if so, what is it called?
>
[quoted text clipped - 3 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Hello all,
The problem is this, you are given a set of weights with labels
attached to them, (example: A has a weight of 1, B has a weight of 3,
C has a weight of 4, and D has a weight of 2.) Using a bottom up
algorithm such as Huffman code and the shortest path algorithm (listed
in Cormens, we're allowed to use if we want which I did.) find the
shortest path (in weights) and list the minimum value, the full tree
data, and optimal parenthization.
I finished this program, it took a long time for me though and I did
it this way. I generated an arrayList (or List I can't remember right
now) of all possible paths then used the shortest path algorithm to
show me the shortest path in which I generated the optimal
parenthization, etc. I used an ArrayList to hold the diff node
combinations (such as 1342, 442, 172, 136, 46, 82, ....10). I wanted
to create a class that held the different values for each label such
as their previous state, stage, so that I could write my own shortest
path algorithm. But I couldn't! Lol, I tried. I didn't know how to
link the different nodes together once I made them so I went back to
the ArrayList method and referened them by their cells (such as
nodeList.get(i)) I think I struggled more with manipulating data
around with ArrayList more than anything for this assignment.
Anyway one of my brillant ideas was to make a node1, node2 node3
(children of 1342) and somehow link them with their values declared
within the constructors. It sounded good in my head but practically,
as I tried it, it didn't seem work out so I abandoned it.
My next program is to do the same problem but from a top down
approach. O.o I have an idea how to do this and right now, I'd like
to see if I can figure out how to do this without asking for help.
This is supposed to be easier :) And thankfully, the last program has
made me much more comfortable with ArrayLists and such.
For this top down approach I was going to write a recursive algorithm
to match the dynamic programming requirement (which I know is
inefficient but I've been told that to figure it out iteratively is
harder and we're not required to write efficient code.) This is only
to demonstrate the understanding of the top down design concept. I
will probably use ArrayLists to store my values like the last program.
I tried to get famliiar with the Map collections but it was a bit
overwhelming so I went the more manual but easier for me to understand
how to use ArrayList way.
Thanks for all of your input. It helps me something major in this
experience of learning.
-t