All things are lawful, but not all things are profitable.
There are three kinds of actuaries: those who can count, and those who can't.
Alicia Perry wrote:Given the pseudocode written above, how should I call the method analyze()?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:However, none of this addresses your basic question. Give me a while to look at your code (I arrived late to this thread), and I'll get back to you.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
The method analyze is called in the search method but I don't think it is the right place.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hmmm... you make it sound easy, that is if I understand you, and I'm not sure.
Are you referring to some generic class that enables you to do a BFS?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:however, that bfs() is not a great name for a method.
Alicia Perry wrote:Now I look better how the class LinkedHashSet<E> works.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Alicia Perry wrote:Now I look better how the class LinkedHashSet<E> works.
Good idea, but just very quickly: it's a HashSet that retains elements in the order they were added, which I suspect makes it ideal for your purposes, because contains() works in O(1) time, and you can also "pop" items out with its Iterator (also in O(1) time).
Winston Gutkowski wrote:One thing I've noticed: You don't appear to have a Vertex class, which seems like a fairly major omission. (...)
There are three kinds of actuaries: those who can count, and those who can't.
Alicia Perry wrote:
Winston Gutkowski wrote:however, that bfs() is not a great name for a method.
You're absolutely right! I used that name because it's the first one that came to my mind, but of course is not the best.
@Piet
1) You're right. Is the same thing that I thought. So I didn't understand how the search method must be used.
What sense does it iterate over the nodes of the graph from a node in particular?
(I think I did a very stupid question)
2) You're right about this too. Initially I used the Graph as a parameter (that is, as the specifications require that it be done the way) but the compiler generated an error that I honestly don't know how to solve if not putting SparseGraph.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:The type parameter <V> is the Vertex. It is left completely unspecified, so whatever class V you throw at it, it should work.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Alicia Perry wrote:
3) I thought it was useful, whenever I reach a node, store as parent node the immediate parent of origin node. I don't need this thing?
Alicia Perry wrote:
4) I used parent = (V[]) new Object[graph.vertices.size()]; instead of parent = new V[graph.vertices.size()] because the compiler generates an error if I use the second statement. The error is: Error: Generic array creation.
Alicia Perry wrote:
5) Then, using LinkedHashSet<V>, instead of using a statement such as visited[v] = true should I use if(visited.contains(v))...?
Alicia Perry wrote:
I hope I have correctly understood your advice. Now I look better how the class LinkedHashSet<E> works.
There are three kinds of actuaries: those who can count, and those who can't.
Winston Gutkowski wrote:(...) Linked lists are also made up of nodes, and you define them as:
public class LinkedList<V> ...
but the 'V' there refers to the values held by its nodes, not the nodes themselves (...)
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Well, what is the importance of that? It's just an implementation aspect of the interface List.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Piet Souris wrote:
Without knowing what it is that you did, and what the error was, I can only guess what is causing this error. So, can you provide some details
what it is that you did and what error you got?
Piet Souris wrote:
Yes, it is very useful. Have you read the short description that Winston gave, especially why this data structure is very handy
in this situation?
There are three kinds of actuaries: those who can count, and those who can't.
Winston Gutkowski wrote:
Sure it is, but since most of this thread has been about implementation (...).
Winston Gutkowski wrote:Suppose, instead of trying to represent a Graph as Lists of Edges and values, we actually include the "edges" in a Vertex?
(...)
but it sure seems like a reasonable alternative to me
Winston Gutkowski wrote:, and it's ONLY possible if you have a Vertex class.
Winston Gutkowski wrote:
And if it does fly, then maybe Edge becomes redundant (although I suspect not).
Winston Gutkowski wrote:Hope I've made myself clearer.
Winston
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:It is more than a reasonable alternative, it is a very fine alternative.
What I especially like is the method
public void connect(Vertex<T> endpoint, boolean directed)
in which you can set the direction.
This aspect (direction) is what I have my doubts about...
And I do sincerely hope that I understood everything correctly!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Piet Souris wrote:What is the 'it' in your statement?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Alicia Perry wrote:Hello everyone, I changed again the search method and I have tested it.
Now it works. I must say that I'm learning a lot reading your comments. Thank you!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Alicia Perry wrote:Hello everyone, I changed again the search method and I have tested it.
Now it works. I must say that I'm learning a lot reading your comments. Thank you!
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
And, as you can infer from all the comments, we enjoyed it very much and learned a lot too!
Piet Souris wrote:you're my favorite person I'd love to 'agree to disagree', but now I'd say: let's agree to agree.
Your Vertex class would be an excellent building block for a Graph. Most of the Graph's methods could directly be forwarded to the relevant Vertex.
The really great thing about assignments like these is that it is an excellent opportunity to put your phantasy at work, and also to implement the ideas any way you like. There's no Company that sets you up with tons of "Business Requirements" and no wolfpacks of "Reviewers" that demand of you to give the 'impact' of whatever decision you made and depending on the shortcomings, stamp it as High Gap, Medium or Low
So one nice addition to class 'Vertex' would be the 'state' of a Vertex.
I like Alicia's implementation for its simplicity. I like yours for the fine 'Vertex' class, and now I'm wondering what I would have done. Well, I'm not gonna tell, for otherwise people could instantly tell I'm just an old guy who hasn't got a clue what he's talking about. (I'm a lot older than you, 58).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:You could, I suppose, expand it to include "incoming" links in a separate List (which would obviate the need for the optional Map), but it adds complexity without much benefit that I can see, beyond being able to determine if a Vertex is "isolated".
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Chan Ag wrote:Me too. I have loved reading every post in this thread. There was something to be learned from every post. Your last post too, Piet.
Thank you.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
hi Alicia,
love to hear this. Well done! Can you let us know what the professor thinks of it?
Alicia Perry wrote:@Winston Is absolutely true what is written in WhatNotHow. I hope I can improve from this point of view [...] professors assign homework shall be carried out in a short time, what happens is that you want to get the solution up and running quickly, without thinking of how it works and if it's powerful and elegant.
However, I'm realizing how important it is to think before you write the code: you will save much time and the generated code is more elegant and clean.
So, thank you very much for your help.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |