Everything2
Near Matches
Ignore Exact
Full Text
Everything2

linear search

created by klash

(thing) by klash (3.2 mon) (print)   ?   (I like it!) Fri Dec 01 2000 at 1:40:10

An extremely simple algorithm for searching for a particular value in a list. It consists of comparing each element of the list with the key, until the key is found, or the search reaches the end of the list. Nor surprisingly, it runs in linear time. Sample code in C:1

int linear_search(some_type list[], int n, some_type key)
{
	int i = 0;
	
	while(i < n) {
		if(list[i] == key)
			return i;
		i++;
	}

	return NOT_FOUND;
}

1 I contemplated whether it would be better to give sample code in Python, since the syntax is generally thought to be so simple and clear. On the other hand, everyone knows C. If you have thoughts on this, please /msg me.


printable version
chaos

interpolation search binary search linear Trie
/msg Python search Linear time and real time
John Hick simple Daikatana Ozma
algorithm
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Look at this mess the Death Borg made!
Indian Recipes
How to deliver a baby in a taxicab
boolean search
one-dimensional cellular automaton
Sylvia Plath
theoretical physics
gas discharge surge protector
Gardening in October
Frank Zappa
Getting the most out of public transportation
crossover
That kinda Star Trek emergency power/battle stations lighting sorta thing
Vigenère Square
New Writeups
anndandridge
Dorothy Dandridge(person)
PaulM
ignominity(idea)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
stainedglass
1(fiction)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
This affordable entertainment brought to you by The Everything Development Company