Linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. Linear search is the simplest search algorithm. Its worst case cost is proportional to the number of elements in the list.
Questions tagged [linear-search]
280 questions
-1
votes
3 answers
Why is my linear search always returning false, even if the item is in the array?
I'm in an Intro to C++ class, and for one of our assignments we're making an online shop. One of our problems is to make a search function for the inventory, using a linear search, then display the corresponding price, stock, and shipability for…
user12675490
-1
votes
2 answers
Combining binary search and linear search or any other algorithm
I want to ask, I'm still learning about time complexity.
I got a problem, the question asked me to calculate the time complexity of a binary search,
The time complexity of a binary search is O(log m).
After the search, they want me to calculate a…

Dio
- 1
- 2
-1
votes
1 answer
Linear search in R
I am trying to write a simple code without using any function to find an element in an array in R. I want to apply linear search algorithm
arr= c(5,8,4,6,9,2)
x=9
i=1
for (i in 1:range(arr)){
if (arr[i] == x) {
print("found")
break
…

Prabhu
- 87
- 1
- 10
-1
votes
3 answers
Is there int data type array function?
Is there actually array function in C? I actually wanted to return several integer value at one time. The code below is not valid obviously but it's just what I'm thinking about. Is there any other method to achieve this?
int marks[5] = {90, 90, 70…

Cheang Wai Bin
- 181
- 1
- 1
- 9
-1
votes
1 answer
"TypeError: object of type 'type' has no len()" - Linear Search on Python
I am kinda new on Python and today I wanted to make a linear search algorithm but I'm having problems with len(list):
def linearSearch(list, targetValue):
for i in range(0, len(list)):
if list[i] == targetValue:
return i…

Lorenzo Orlando
- 21
- 8
-1
votes
2 answers
Code for linear search in python not working and outputs wrong text
I need to write a program that does linear search on a character within a sentence. I have to do it without using any inbuilt functions except for print().
The program should output what index the character is at.
If the character isn't in the…

James
- 55
- 7
-1
votes
2 answers
No operator "==" matches these operands. operand types are: int == type_name`
At the "if (size == list[i])", marks with red on the "==", it says No operator "==" matches these operands operand types are: int == InventoryRecord. I do not see what I'm doing wrong here. Can someone explain to me why is that?
void…

Hazirah_Halim
- 87
- 2
- 16
-1
votes
1 answer
Python Spell Checker Using Linear Search
I am trying to write a spellchecker using a linear search which takes Shakespeares full works and compares it to a 10,000 word dictionary. I want the code to output all words in Shakespeares full works which aren't in the dictionary. I have attached…

Joe Bloggs
- 41
- 1
- 6
-1
votes
1 answer
Difference between linear search with and without LINQ
What is the differences between a regular search algorithm with comparison variables and one made with the lambda operators?
What are they doing differently internally and how would you describe it as simple as possible? Both versions are giving the…

David Lars
- 7
- 4
-1
votes
1 answer
Linear Search technique
I am writing a programe that read in file containing a square matrix of N rows by N columns of integers.The first line of the file contains a single value specifying the "size" of N for the rest of the grid. for example if the first line contains…

user6167014
- 17
- 5
-1
votes
1 answer
CS50 pset3 — game of fifteen
The code given below is an answer of the problem set 3 from CS50.
Please have a look at functions: init,
draw,
move,
won
and suggest some…

Shubham Bagate
- 7
- 4
-1
votes
2 answers
Linear Search Array String
I need to find a string element in my array but when I check to see, it always comes up as found, even if its not the case. I am trying to call a method.
String name = "";
boolean result = false;
if (option == 5)
{
…

Sean Mccarthy
- 1
- 1
-1
votes
3 answers
Linear Search Code Shows that my item is not present.Please help me make corrections
This is the function for linear search where i am only taking one variable x that is the to search for item variable
int lsrch(int x)
{int i;
int arr[6] = {2,4,5,76,2,1};
for(i=0;i<5;i++)
{
if(x==arr[i])
{
…

DjVasu
- 113
- 9
-1
votes
1 answer
Split lines into words task - linear search method
I've been given a task to split lines into words and then split the lines up based on spaces and newlines. I've came up with an incomplete solution as it will not print the last word. I can only use linear search hence the basic approach.
line =…
-1
votes
2 answers
Linear search through LinkedList
I'm attempting to implement a linear search function for strings in C, but it isn't currently working. Here is my code:
// Linear search for name matching input string
int listSearch(struct LinkedList* linkedList, char name)
{
struct…

Mick McCarthy
- 428
- 2
- 16