寻找最大值数组 [英] Finding Maximum Value in an array

查看:131
本文介绍了寻找最大值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一千(1000)个元素被输入到一个阵列(无存储器约束)。我们知道,虽然进入的元素,我们可以通过当我们输入一个值检查更新的最大输出输入的值。

One thousand(1000) elements are entered into an array (no memory constraints). As we know, while entering the elements we can update the max out of entered values by a check whenever we enter a value.

但想象一下,如果最大值的位置是某处大约900

But imagine if the position of max value is somewhere around 900

如果我删除位置200元800〜1000, 没有做任何更多的比较,我们应该有下一个最大值。 是否意味着在进入数据,我们应该有一个计划来组织数据以某种方式来获得最大的价值出来的剩余数据的?

If I remove 200 elements from positions 800 to 1000, without doing any more comparisons, we should have the next max value. Will that mean while entering the data we should have a plan to organize the data in some way to get the max value out of the remaining data?

删除和插入会继续发生,但我们应该在更短的时间更新最大值用更少的步骤没有。 (使用堆栈可以帮助的线索,面试官给了我)。任何人都请帮助我。

Deleting and inserting will keep on happening, but we should have max value updated in less time with less no of steps. (Using stacks might help is the clue that the interviewer gave me). Anyone please help me.

推荐答案

一个最大堆可以工作在你的案件。但是,由于1000是非常小的,你可能并不需要的东西复杂化。

A maximum heap may work in your case. But since 1000 is really small, you may don't need something complicated.

这篇关于寻找最大值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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