重力排序:编程这可能吗? [英] Gravity Sort : Is this possible programatically?

查看:344
本文介绍了重力排序:编程这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在思考如何使用面向对象设计的排序算法研究。但我没能找到一个合适的办法,甚至进来做这个排序算法,做在O(n)时间排序接近。

I've been thinking recently on using the Object Oriented design in the sorting algorithm. However I was not able to find a proper way to even come closer in making this sorting algorithm that does the sorting in O(n) time.

好吧,这里是我一直在思考了一个星期。我有一组输入数据。我会分配一个质量为每个输入数据(假设输入数据类型质量和类型球形如果我们假设所有物体为完全球形物体的形状成比例的它们的质量,最重的一个第一接触地面)。我将会把我所有的输入数据在空间中的所有从地球相同的距离。我会让他们自由下落。根据万有引力定律,最重的一个第一撞击地面。而为了在他们打会给我排序的数据。这是有趣的,在某种程度上,但骨子里我觉得这用我学到直到日期二OO应该是可能的。

Ok, here is what I've been thinking for a week. I have a set of input data. I will assign a mass to each of the input data (assume input data a type of Mass and a type of Sphere. If we assume all objects to be perfectly spherical objects with shapes proportional to their mass, the heaviest one touches the ground first.). I will be placing all my input data in the space all at same distance from earth. And I will make them free fall. According to gravitational law, the heaviest one hits the ground first. And the order in which they hit will give me the sorted data. This is funny in some way, but underneath I feel that this should be possible using the OO that I have learnt till date

难道真的有可能使使用引力喜欢的场景分拣技术,还是我笨/疯了吗?

Is it really possible to make a sorting technique that uses gravitational pull like scenario or am I stupid/crazy?

编辑:原来所有对象击中地面在同一时间,因此我公司推出的球形物体概念

Turns out all objects hit the ground at the same time hence I introduced the spherical object concept.

推荐答案

的事情是,虽然的的的思想OOP的的可能是模拟现实世界中,这并不意味着有一个多长时间需要的东西在现实世界中,人们往往要花多长时间用电脑模拟它的直接的对应关系。

The thing is, though one of the ideas 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.

想象一下,需要你的程序的实际步骤:

Imagine the actual steps required for your procedure:

  1. 的对象必须为你的数据集的每一个项目构成。在大多数现代化的硬件,仅此一项就需要迭代,因此将在使您的策略为O(n)的最佳
  2. 重力的影响将需要仿真,对于每个对象。此外,为了实现这一点最明显,直接的方法是将循环。
  3. ,在编程模型中的大地的表面上的每一个对象的土地将不得不被捕获,并通过一些实现特定的机制的时间,相应的对象需要被插入到一个有序列表作为结果

考虑这个问题还引入了额外的复杂性。问问你自己:有多高,你需要来定位这些对象开始?显然足够高,这样的规模最大的一次真正的属于的;即,从地球比最大对象的半径更远。但你怎么知道有多远?你需要首先确定集合中的最大的对象;这一点,再次,将(可能)需要迭代。此外,可以想象,这种模拟可以多线程试图模仿对象的概念的实时行为的实际上的下降;但你会发现自己尝试的项目可能在正在检测新的冲突,同时添加到集合(操作这显然需要时间非零量)。因此,这将创建线程的问题也是如此。

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 falls; 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 actually 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.

总之,我有麻烦想象如何使用OOP没有特殊硬件的这种想法可以正确实施简单。这就是说,它真正的的一个好主意。这让我想起珠排序 --an算法,虽然不一样,你的想法我,其实,也分拣解决方案,将重心非常物理概念的优势,不出意外,需要专门的硬件。

In short, I have trouble imagining how this idea could be properly implemented simply using OOP without special hardware. That said, it really is a good idea. It reminds me, in fact, of Bead Sort--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.

这篇关于重力排序:编程这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆