Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The thing is, though one of the <em>ideas</em> of OOP may be to model the real world, that doesn't mean there's a direct correspondence between how long something takes in the real world and how long it would take to simulate it with a computer.</p> <p>Imagine the actual steps required for your procedure:</p> <ol> <li>An object has to be constructed for every item in your set of data. On most modern hardware, this alone would require iteration and would therefore make your strategy O(n) at <em>best</em>.</li> <li>The effect of gravity would need to be simulated, for each object. Again, the most obvious, straightforward way to implement this would be to iterate.</li> <li>The time that each object lands on the surface of the "Earth" in your programming model would have to be captured and, via some implementation-specific mechanism, the corresponding object would need to be inserted into an ordered list as a result.</li> </ol> <p>Considering the problem further introduces additional complications. Ask yourself this: how high up do you need to position these objects to start? Obviously high enough so that the largest one actually <em>falls</em>; i.e., farther from the Earth than the radius of the largest object. But how do you know how far that is? You'd need to first determine the largest object in the collection; this, again, would (probably) require iterating. Also, one might imagine that this simulation could be multithreaded to attempt to simulate the real-time behavior of the notion of objects <em>actually</em> falling; but then you will find yourself attempting to add items to a collection (an operation which obviously takes a non-zero amount of time) potentially at the same time that new collisions are being detected. So this will create threading issues as well.</p> <p>In short, I have trouble imagining how this idea could be properly implemented simply using OOP without special hardware. That said, it really <em>is</em> a good idea. It reminds me, in fact, of <a href="http://en.wikipedia.org/wiki/Bead_sort" rel="noreferrer">Bead Sort</a>--an algorithm which, though not the same as your idea, is also a sorting solution that takes advantage of the very physical concept of gravity and, not surprisingly, requires specialized hardware.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload