找到最小值的算法 [英] Algorithm to find the minimum

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

问题描述

好吧,我是一个初学者,所以我没有计算机科学学位.我遇到一个问题,我需要在仅出现一次的数组中找到一个元素.通过我的高中数学,我认为这实际上是在寻找模式的逆函数,对吗?有人可以给我解释一种算法,该算法在给定数据集时会以简单的外行术语找到与模式相反的算法(除非可以解释,否则请避免使用O(nLogn)术语)?

IE.给定数据集= [0,0,0,0,1,1,2,6,6,6,6,6,8,8]返回数据集= [2],其中此数学


预先感谢您的帮助和时间.

Okay am a beginner programmer and i DON''T have a computer science degree so bare with me. I run into a problem where i need to find an element in an array that appears only once. With my high school math i think this is effectively trying to search for the inverse of mode right? can anyone explain to me an algorithm that finds the opposite of mode in simple layman terms (please avoid the O(nLogn) jargon unless you can explain it) when given a data set?

I.e. given a dataset = [0, 0, 0, 0, 1, 1, 2, 6, 6, 6, 6, 8, 8 ] return the dataset = [2], wheres the math in this


Thank you in advance for your help and time

推荐答案

我不确定对此是否有正式的算法(我可能是错的),但是最简单的方法是仅用于扫描:如果当前元素与任一元素都不相同,则它是唯一的.很简单,不是吗?还是我想念什么?

哦,您要用的单词是熊-不管有没有您,我都不在办公桌前脱衣!:laugh:
I''m not sure there is a formal algorithm for this (I could be wrong), but the simplest way is just to scan through: if the current element is not the same as either of the elements to either side, it is unique. Pretty simple, isn''t it? Or am I missing something?

Oh, and the word you want is bear - I am not stripping at my desk, with or without you! :laugh:


使用内置的方法List(of )类以查找最小值或最大值,例如

Use the inbuilt methods of the List(of ) class to find the min or max values, e.g.

Dim ints() As Integer = {11, 3, 5, 2, 8, 9}
Dim intList As New List(Of Integer)(ints)

MsgBox(intList.Min)


从元素1到元素11遍历值.
如果数据集[a]<>数据集[a-1]和数据集[a]<数据集[a + 1],然后... {执行标记标记所需的操作}.

在给定的数据集中,将标记2,但可能是数据集中有多个个体"项目,它们都可能被标记.
Loop through the values, from element 1 to element 11.
Put a test in, if dataset[a] <> dataset [a-1] AND dataset [a] <> dataset[a+1] then ... {do what you need to do to flag it}.

In the dataset given, 2 would be flagged up, but it may be that there are several ''individual'' items in a dataset, they could all be flagged.


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

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