-3

How could you determine if a collection is implemented as an array or as a linked structure without access to the source code (assuming you can run the code)?

closed as unclear what you're asking by Arseni Mourzenko, gnat, Laiv, BobDalgleish, Jörg W Mittag Dec 13 '18 at 17:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Do you mean you have access to a public surface like IList? And wish to determine if it is something like ArrayList or instead LinkedList? – Caleth Dec 12 '18 at 22:49
  • 3
    Is this a homework question from an algorithms course? Then the intended answer probably is to use the data structure in a way that would expose differences in the O(·) behaviour, e.g. figuring out if something is O(1) vs O(n). Of course that's terribly flawed because O(·) notation only describes asymptotic behaviour and is irrelevant at small problem sizes. You cannot benchmark complexity classes! If this is the real world, just decompile or disassemble the code and see what's going on. – amon Dec 12 '18 at 22:54
2

By looking at the compiled code.

Compiled code isn't magic. It just isn't full of human friendly names. It does follow rules and behaves in predictable ways. It is readable. If it wasn't it wouldn't work when your CPU worked on it.

Viewing the executable in a hex editor is the classic way to do this. Decompilers can help by adding back some human friendliness but certainly aren't required. All they are doing is making it easier for you to remember what these codes mean.

In this particular case once you identify the code that's manipulating the data structure you can watch as it reads data by either incrementing an address, as in an array, or if it reads an address from the structure and follows that address to the next data node.

Of course in some compilation stacks you might find more obvious hints laying around such as the name of the class used to create the data structure.

These are all concepts a developer should understand but this subject might fair better on Reverse Engineering Stack Exchange. If you'd like to move this I'll delete this answer.

  • There may of course be some kind of intermediate source for ecosystems such as Java and .NET. – Robbie Dee Dec 13 '18 at 10:59
  • @RobbieDee many languages first compile to other languages. Python can be compiled into c. But there should only be one source language that you use to make changes. That's why we call it source. – candied_orange Dec 13 '18 at 11:14
  • Source, language, code - whatever. The point is you may have a number of such levels at your disposal. – Robbie Dee Dec 13 '18 at 11:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.