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


In reply to Re: Data structure efficiency by davido
in thread Data structure efficiency by shine22vn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.