shine22vn has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data structure efficiency
by davido (Cardinal) on Dec 05, 2006 at 07:47 UTC | |
Just give us your professor's email address so we can send our answers directly to him. Why should you have to be involved in the process at all if someone else can do it for you? Your last post seemed a lot like homework too. A coincidence maybe, but although the questions you've posted above seem like homework type questions, it's hard to believe any teacher would be asking them without providing better context and clarification. Here's why: Efficiency can take on many forms; computational efficiency, coding/programming efficiency, maintenance efficiency, memory efficiency, just to name a few. And even computational efficiency (speed) is difficult to define without knowing the application you're trying to implement. So question 1 is so vague that it could be answered many different ways, and could be interpreted a lot of ways. It needs to refine its criteria before an intelligent and meaningful answer can be given. That's one of the things that used to really frustrate me when I was in college; professors who posed test questions that could reasonably be interpreted several ways. Occasionally they sought a specific answer based on an interpretation that they failed to clarify. Question 2 is still too vague, and at the same time too inclusive. You want to know all the cases where an array is more efficient? You want to know all the cases where a hash is more efficient? Assuming we actually know what type of efficiency you're requesting, we still will be here all month enumerating the situations. And that's assuming you can tell us what type of efficiency you're in need of, and how you're applying the use of these datastructures. Question three is just goofy. I can only assume that you're talking about turning key/value pairs into co-elements of anonymous arrays indexed by a parent array. You want to know all the situations where that will fail? It will fail in any situation where a hash is the right tool for the job, and an array is not. Do you need an enumeration of all those situations? We'll be here awhile. Let me recommend a good source of information on efficiency, on hashes, and that sort of thing: The O'Reilly & Associates book Mastering Algorithms with Perl. I found that to be an excellent book. It goes into just the right amount of detail explaining how hashes work, and where they might be useful. And its discussion of efficiency (including an introduction to Big-O notation) was also well written. Dave | [reply] |
| |
|
Re: Data structure efficiency
by Melly (Chaplain) on Dec 05, 2006 at 11:21 UTC | |
IMHO... 1. In general, an array will be more efficient (i.e. quicker to read values from), but only if you know the element number that you are trying to access, or if you know that you want to perform a function on each element of the array - i.e.
2. Err, see above... 3. Define failure... I can't think of any circumstances where you could fail to do this - the reverse is more problematic, since you would have to be prepared to handle cases where two or more array values have the same 'key'. I have to admit that I'm not really sure what you are asking - in general the type of data-structures that you are using will dictate whether a hash or an array is more suitable. If your keys are numeric, or if there isn't really a key, then use an array, but if the keys are anything else, then a hash would make sense. Tom Melly, pm@tomandlu.co.uk | [reply] [d/l] [select] |
|
Re: Data structure efficiency
by lin0 (Curate) on Dec 05, 2006 at 17:10 UTC | |
Hi Shine I will encourage you to start using the Super Search functionality we have at the Monastery. I do that for two reasons: Having said that, if you do a Super Search using the terms: efficient data structure, you will find some nodes that will give you a hint on the answer to your question. Some of these nodes are: The list is longer, but I just wanted to get you started. You can also check the Tutorials section, in particular the node on basic data types Finally, I also recommend you to have a look at the book: Mastering Algorithms with Perl. I hope this information helps you get started Cheers, lin0 | [reply] |
|
Re: Data structure efficiency
by talexb (Chancellor) on Dec 05, 2006 at 16:30 UTC | |
These are valid questions, but only in the context of a discussion. Monty Python quotes aside ("I'm here for an argument." "No you're not!"), you need to present your findings so far and then ask your questions. In other words, show your work. And if you haven't done any work and you're on a fishing expedition, then phooey on you. :) | [reply] |