panic city
May. 17th, 2004 07:54 am*stares at java*
Fuck. Fuck fuck fuck fuck fuck.
I don't remember any of this at all. Anybody out there who knows Java and wants to help me out so I can actually get this last thing out of the way?
Here's what I have to do (all of the assignment unless otherwise noted):
assignment 5--stuck on C and D here.
assignment 6
assignment 7
assignment 8
assignment 9
I'm doomed. It's these five assigments that stand between me and the posting of the degree (actually earning it), and I have to get these done in the next few days. So any and all help (up to and including code) will be appreciated. Just so I can get the hang of it.
Fuck. Fuck fuck fuck fuck fuck.
I don't remember any of this at all. Anybody out there who knows Java and wants to help me out so I can actually get this last thing out of the way?
Here's what I have to do (all of the assignment unless otherwise noted):
assignment 5--stuck on C and D here.
assignment 6
assignment 7
assignment 8
assignment 9
I'm doomed. It's these five assigments that stand between me and the posting of the degree (actually earning it), and I have to get these done in the next few days. So any and all help (up to and including code) will be appreciated. Just so I can get the hang of it.
no subject
Date: 2004-05-17 11:15 am (UTC)Deep breaths!
no subject
Date: 2004-05-17 01:49 pm (UTC)5 C:
1 a) I assume you already have this one or can get it from the book.
1 b) The big differences between a tree and a general graph are
I: in a tree, each node can be reached from exactly one other node. in a general graph, you might be able to get to a node through several other nodes
a
/ \
b c
\ /
d
II: in a tree, you don't have any cycles. in a general graph, you might be able to at some node, follow a path, and end up back where you started
a---
^ |
| |
---
(a goes back to a)
So the question is, what does the code do in each of these cases? Again, if you already know this but aren't sure how to answer these, don't take it as an insult. let me know where you stand and I'll try to offer better help.
1 c) Whee! breadth-first searches! Here's I would do one by hand:
I: check the root to see if it's the one I'm interested in
II: do the same for both children (*just* the root of each child)
III: do the same for all of their children (again, *just* the root of each of their children)
IV: repeat
For example, if you have
a
/ \
/ \
/ \
/ \
b c
/ \ / \
/ \ / \
/ \ / \
d e f g
/ \ /| |\ / \
h i j k l m n o
first check a
then check b & c
then check d,e,f,&g
then check h,i,j,k,l,m,n,&o
There are good ways to write this and there are bad ways to write this. The way I would think of by hand would be to break the tree up into levels (a, then b&c, then d-g, then h-o) and look at each level. How would that translate to a computer? I would think the easiest way would involve some sort of queue. First a would be in the queue. Then the children of a would be in the queue. Then the children of everything in the queue would be in the queue, and so on.
A queue actually makes this pretty easy.
I: start with a in the queue
II: a isn't what we want, so we toss it and add the children
III: b & c are in the queue
IV: b isn't what we want, so toss it and add its children to the end of the queue
V: c, d, & e are in the queue
VI: c isn't what we want, so we toss it and add its children to the end of the queue
VII: d, e, f, & g are in the queue
Since you always add children to the end of the queue, you'll never run into them before you've finished with the current level.
You might also try stealing some of the code from the FullTree.java file.
2) my browser won't show the FullTree.java code, but I assume that the children are stored in a queue. Depth-first means you check the current node, then the leftmost child, then the next-to-leftmost child, and so on, all the way to the rightmost child.
I: print the current node
II: search the first tree in the queue of children
III: keep searching trees in the queue of children
I hope some of this makes sense. In my defense, the class I'm used to is much simpler.
I'll look at the other problems now.
no subject
Date: 2004-05-17 02:30 pm (UTC)You normally teach CS 3, no? Scheme made a whole lot more sense to my head than Java does, and I figure that's half the problem. ;)
Thanks for your help. :)
-kat
no subject
Date: 2004-05-17 02:38 pm (UTC)no subject
Date: 2004-05-17 02:11 pm (UTC)So for the big tree (a-o) that I had in my first comment, the TOC view would look like
a
b
d
h
i
e
j
k
c
f
l
m
g
n
o
The first part of the progressive view would only show you a. If you click on a, you'll see b & c. If you click on b, you'll see d & e.
The progressive view does things in layers. The TOC view doesn't. It prints everything under b before everything under c. Which kind of traversal goes with which kind of view?
Once you have that, you need to tweak the FullTree.java code. The TOC view shouldn't be that bad, since you only need to print one file. However, since it's all going in one file, the order in which you traverse the tree matters.
The progressive view is a little more complicated, but still not that scary. Since you are writing to multiple files, the order in which you traverse the tree doesn't matter that much. You may find one way easier to think about, but you can do it any way you want.
Again, let me know if this does or does not help.
no subject
Date: 2004-05-17 07:44 pm (UTC)Can't help you on 5, but it looks like you're getting help.
6 looks like a job for a hash. It looks like something simple to do in Perl, but I don't know if/how you manage hashes in Java. Take this suggestion with a grain of salt, as it came entirely too easily.
7i: shouldn't be too hard to figure out
7ii: eek
7iii: augh =(
8: Regexes are hard enough to understand without being pseudocode. Try /\d{,2} \a+ \d{2,4}/ and /\a+ +\d{,2}(-\d{,2})?,? +\d{2.4}/ to start off with.
9: I've only toyed around with jdbc, and all I've ever done with it is send up solo SQL commands. I didn't know you could pull down records into an existing Java object structure... Just hack through it following someone else's example code, joining two bullshit tables together and printing the result. If you don't know SQL, create table foo ( a int primary key, b int ); create table bar ( a int primary key, b int references foo(a) ); insert into foo values(1,1); select * from foo,bar where foo.a = bar.b;
no subject
Date: 2004-05-17 10:13 pm (UTC)