Class LinearSearch
Implements linear search, time complexity is O(N)
Inheritance
System.Object
LinearSearch
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: AlgorithmsAndDataStructures.Algorithms.Search
Assembly: AlgorithmsAndDataStructures.dll
Syntax
public class LinearSearch
Methods
| Improve this Doc View SourceSearch<T>(List<T>, T, Int32, Int32)
Searches for a given value in a list.
Declaration
[Algorithm(AlgorithmType.Search, "LinearSearch")]
[SpaceComplexity("O(1)", false, InPlace = true)]
[TimeComplexity(Case.Best, "O(1)")]
[TimeComplexity(Case.Worst, "O(n)")]
[TimeComplexity(Case.Average, "O(n)")]
public static int Search<T>(List<T> list, T key, int startIndex, int endIndex)
where T : IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | A list of any comparable type. |
T | key | The value the method is searching for. |
System.Int32 | startIndex | The lowest (left-most) index of the list - inclusive. |
System.Int32 | endIndex | The highest (right-most) index of the list - inclusive. |
Returns
Type | Description |
---|---|
System.Int32 |
Type Parameters
Name | Description |
---|---|
T |