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
1 answer
Linear Sorted Search
I have created this code which is a chart position. It should allow the user to enter a name already set in the array and the position of the artist will output whilst the input is not "end"
public static void main(String[] args) {
Scanner kybd…

C Virgo
- 1
- 2
-1
votes
1 answer
Using Linear Search to count the time each value is matched in the Array[]
So I'm writing a program where the program generates 100 random integers between 0 and 9 and stores them in an Array[ with using Linear Search to count the time each value is matched in the Array[]. Values will need to appear multiple times so…

Andrew Jones
- 13
- 1
- 6
-1
votes
2 answers
Which one is run-time efficient and storage efficient in alogarithm?
I'm confused whether linear search or binary search is more efficient in running time and storing.
detalied explaination is really appreciated

Erika Sawajiri
- 1,136
- 3
- 13
- 18
-2
votes
2 answers
Linear and Binary search in an array of objects in java
I'm creating an array of objects where the search should be by Linear method and Binary method.
The issue is how to traverse the array with the appropriate data type and compare.
public class FoodMain {
static Scanner sc = new…

raj_b
- 1
- 3
-2
votes
2 answers
searching for an element inside a linked list c
So i have a header file with a linked list implementation with a structure, the problem is when i want to find if an element is already inside the linked list if i do all the steps in the main function it works, but if i do that in a seperate…

Martim Correia
- 483
- 5
- 16
-2
votes
2 answers
java implementation of the linear search on a sorted array
I'm trying to implement a java code to test linear search on a sorted array and this is my code
public class ArrayTest {
public static void main(String [] args) {
int []x= {12,8,6,23,6,5,17,20,9};
int y =linearSearch(x,23);
}
public static…
user7288817
-2
votes
1 answer
C Binary & Linear Search
Hello i want to draw the time/array size graph for binary and linear search algorithms.(Worst, best and average case for array size = 1 000, 10 000,100 000,1 000 000). I'm using DEV C++. However, when i run the code for array size = 1 000 000, the…

Can Özgen
- 63
- 1
- 2
- 8
-2
votes
1 answer
Is it possible to show the time it took a linear search to find the key you entered to find in the program?
Is it possible to show the time it took a linear search to find the key you entered to find in the program?
This is the task our teacher gave us
Requirements: Write a C++ program that will do the following in sequence:
Linear Search
1. Ask the…
-2
votes
1 answer
Why am I getting errors saying "Unused Parameter n"?
I have been trying to solve this cs50 pset3. I wrote this linear search algorithm and when I try to run it I get error saying "Unused parameter n", "Unused parameter values". Can anyone please tell me why am I getting this error. I tried…

Jay Jay
- 29
- 7
-2
votes
4 answers
Recursive Linear Search
The code shown below works fine. It prints the position of the element found inside the if clause and exits. Whenever the element is not found, the function runs to max and returns 0 to calling function to indicate no elements has been found.…

sagar_jeevan
- 761
- 5
- 16
- 34
-2
votes
4 answers
Return statement not returning as expected
Why does the code below return -1 instead of arr.length-1? If the find() method is looking for 24, it should return 5, but now it returns -1. It should only return -1 if n is not found in arr.
public class linearArraySearch {
public static void…

user3128313
- 23
- 1
- 5
-2
votes
2 answers
Average case of Linear search
I have an array of elements A1,A2,...,An.
The probability of a user searching for each element are P1,P2,...,Pn.
If the elements are rearranged, will the average case of the algorithm change?
Edit : I have posted the question, which appeared in my…

Sudarshan Sunder
- 190
- 3
- 13
-2
votes
2 answers
Array index out of bounds error in 2d array during linear search
I'm writing a program which is suppose to acting like a ticket finder. It displays a chart of possible seating choices along with their prices and asking if the user would like to select a seat by number or by price. It works like it's suppose to…

SMoore
- 23
- 1
- 6
-3
votes
1 answer
Simple binary search doesn't work for me. I am trying to search for a word from text file
I built a program in C++ that takes words from txt file and inputs into program. Program then stores these words into array. Now, I want to search a specific word among the array using binary search.
My txt file has the following…

mohinish
- 21
- 6
-3
votes
3 answers
Python linear search not working
For some reason this python linear search will not work. Every time I run it and input a value that is in the list, it does not tell me that the item is in the list and just runs through.
It does not give any syntax error so must be something…

Thomas Read
- 619
- 2
- 6
- 14