Questions tagged [linear-search]
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.
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 ...
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.
...
In this code for linear search, after line 8 is executed it jumps to line 13 without executing the for loop.
Output:
Enter the size of array
5
Enter the elements
Enter the element to be searched
...
I wrote a program for linear search in python but it doesn's work correctly.
I tried double checking the program but I couldn't find the mistake.
def LinearSearch(arr, n):
for i in arr:
...
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 ...
The problem is there is an array of 10000 that is already filled for me. The range of numbers that will fill the array will be between 0 and 2500. The array is unsorted. My goal is to find the ...
I have a drop down box that has one item in the list. When I click on it is sorts the ngx datatable by that item. Once that item is selected I then need the search box to narrow the results by what ...
I am trying to benchmark linear and binary search as a part of an assignment. I have written the necessary search and randomizer functions. But when I try to benchmark them I get 0 delay even for ...
I have an array where the user can fill it up with objects. Objects are different sodas.
There is a function in this simulator where the user has the option to find a specific soda. I don't want it to ...
My linear search has to output the index of all of one character present. So if the sentence is Hello, it would print L is in index 2 and 3.
I'm not sure how to do this.
def linear_search(intList,...
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 ...
I'm new to Java programming and was given a task to implement. The program was written in pseudocode. Here is what i have been able to develop so far but i keep getting an error message. Kindly help ...
With the current coded i've realised it is mandatory to have separate text files instead of one text file for my computer science coursework. Searching and reading fields from one text file is simple ...
I am trying to implement linear search using arrays. It's supposed to search for a person's name, returning the respective number if the name exists and returning -1 if it doesn't.
I have junit tests ...
I am trying to implement Linear Search Recursively using Javascript.
Given Array A = [1,2,3,4,5,6]
Function signature - something like this :
LinearSearchRecursively(ArrayGiven, x, startingValue)
...
I have just recently started using python and I am extremely new to python and coding in general and I'm in a class where we have been given the assignment to find a function in Python that takes two ...
I'm trying to do a linear search on 2 .txt files. One is a story, the other is words from the story in a dictionary. What I'm trying to do, is search each file, then compare each word to one another, ...
So I have this code
//in the Search class
public bool LinearSearchEx (int target, int[] array, out int number)
{
number = 0;
for (int i = 0; i < array.Length; i++)
{
if (...
So I am a newbie in C++, I do code in JS, for some reason I can't figure out the mistake here, please help me out. thanks!
#include <iostream>
using namespace std;
int search(char input, ...
asked Nov 21 '18 at 16:48
I need some help with my python code.
I have made two function below , one for sequential ( linear ) search and other for binary search.
I want to do these 3 things for each size value in the given ...
I am trying to connect my app to an API and search using the API. If the search is successful and found the name, it will return Success and if not, will return Failed, but it doesn't return anything.
...
asked Oct 30 '18 at 21:23
So, I want my function to return the index (the first if it appears multiple times in the list) of a given value. It appears to work only for an empty list or if the given element has the index 0. ...
asked Sep 26 '18 at 13:22
In the pursuit of learning I have written a multi-threaded linear search, designed to operate on an int[] array. I believe the search works as intended, however after completing it I tested it ...
asked Aug 17 '18 at 9:46
Levenal
3,22022 gold badges1919 silver badges2727 bronze badges
I am trying to make a program in C++ that will search for a desired value in an array of size 10 using a separate search function. Below is the code:
main.cpp
#include <iostream>
#include ...
This is my linear search code but I am getting an error with the array. I know what the error is and I have fixed it, but it still shows the same error:
Runtime Error: Runtime ErrorException in ...
asked Aug 12 '18 at 10:54
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int lsearch(char a[], char element, int num)
{
int i;
for (i = 0; i < num; i++)
{
...
I have a list of elements to be searched in a dataset of variable lengths. I have tried binary search and I found it is not always efficient when the objective is to search a list of elements.
I did ...
asked Aug 2 '18 at 8:37
Raghu
6711 silver badge55 bronze badges
This is my code
#include <bits/stdc++.h>
using namespace std;
int srch(vector<int> arr, int ln, int fn)
{
for (int i = 1; i <= ln; i++)
{
if (arr[i] == fn)
return i;
}
...
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 ...
I do not understand what is wrong with this code of Linear search. It compiles but on execution exits without output.
turns - no. of test cases.
size - size of array.
x - element to be searched.
...
I have coded for linear search in Python3 but i am not getting required output.Below is the Problem:
You have been given an array of size N consisting of integers. In addition you have been given ...
asked Jun 22 '18 at 12:12
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}...
I'm trying to write a simple multiprocess program to found a value in an array.
#include <mpi.h>
#include <stdio.h>
int* create_array(int num_items) {
int* tmp = new int[num_items];
...
asked May 27 '18 at 11:09
My linear search is always returning -1 and I don't know why. I tried figuring it out but without success. The search function goes everytime to the "else" branch and the "then" is never executed.
#...
I am new to python and have trouble with my homework. I want to read a file from a location and look for how many times a number appears in that file. I have done where you read the file and get the ...
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 ...
asked Apr 14 '18 at 10:57
I'm wondering - is it possible to improve the linear search algorithm(on arrays, not lists), so that it'll do about half of the calculations?
for instance, this is the basic linear search algorithm:
...
I executed the following code:
import java.util.Scanner;
public class Linear_Search {
public static void main(String[] args) {
int arr[] = new int[20];
for(int i = 0; i < arr....
asked Mar 22 '18 at 13:29
I have implemented a simple linear search and shown the results on the graph with StdDraw library. I have ran the search for a randomly generated number on tables of sizes from 1000 to 100000 elements,...
asked Mar 10 '18 at 16:25
I'm currently writing a method that will search through an already sorted array more efficiently than a simple linear search. The Idea is that the user will input a "Target" value they are locating, ...
What if a computer is superfast and has unlimited memory which searching operation is best to use or can we use any of our choice? (between linear & Binary search)
I am writing a simple linear search program. But it does not return any index that I search for even though I have specified it to print the index when the user searches for an item in the list:
list ...
So i recently started learning C# and I have an assignment from my teacher.
I have been stuck on the last part of the code and would like to know from people with more knowledge what I am doing wrong ...
asked Jan 25 '18 at 15:38
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 ...
asked Nov 19 '17 at 18:53
I was trying to practice a few string and algorithmic based questions and i stumbled across one which has the below wordings:
You have a string x of length N, which consists of small English letters. ...
asked Nov 14 '17 at 9:05
user1867151
2,37111 gold badge1717 silver badges3535 bronze badges
This is my code for the getMin() method. I cannot get the method to enter the while loop.
public E getMin(){
Node<E> curr = header;
Node<E> min = curr;
E temporaryMinimum = header....
asked Nov 12 '17 at 13:30
Their purpose is to return the number of comparisons between the keys and the array items.
Please let me know if there is anything that I should change, as I am new to Java and am not yet fully ...
asked Oct 24 '17 at 17:08
I am confused with the following two cases in linear search. Let me write the linear search algorithm here first.
Pseudo code for linear search
input: unsorted array A & key
output: index i ...
asked Oct 21 '17 at 20:40
Ying
1,28611 gold badge1010 silver badges1919 bronze badges
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 ...
asked Oct 8 '17 at 12:53
Can Özgen
6511 gold badge11 silver badge88 bronze badges
I have a 76800 points Point Cloud. It is organized with a width of 240 and height of 320 and was input from the Kinect.
Now I want to search for around 5000 points in the Point Cloud. Note that I ...
asked Sep 13 '17 at 13:14