281 questions
0
votes
0
answers
43
views
Linear Search performs better than HashMap+binary search to retrieve an object satisfying a condition [duplicate]
I was trying out this problem link.
So we have a list of (key,timestamp,value), where a single key can have multiple (timestamp,value) pairs , and we have to find the greatest timestamp <= a given ...
0
votes
1
answer
122
views
Why incorrect answer for the Painter's partition problem when input is very large?
I am solving GeeksforGeeks problem The Painter's Partition Problem-II
:
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of ith board is given by arr[i] ...
0
votes
1
answer
82
views
How to quickly search query in large local database looking for a "search" function just like other offline music app has?
Is there anyone give me any hint or guide me what algorithm should i use for search query function in large database (music or songs almost 1000x10) what i have tried so far is Linear search(time O(n) ...
0
votes
3
answers
233
views
avr-gcc: Binary search vs. linear search
I am searching in a few arrays of struct stored in program memory with lengths of about 30-200 with a linear search like this:
Glyph getGlyph(Font font, uint16_t code) {
for (size_t i = 0; i < ...
1
vote
1
answer
43
views
Linear search algorithm partially correct
def linsearch(list, target):
for i in range(0, len(list)):
if (list[i] == target):
return (i)
else:
return ("not in list")
list1 =...
0
votes
1
answer
113
views
Which is worse in linear search: target element not present, target element found at the end of data structure, or both?
I asked chatgpt to give me some multiple choice questions on linear search algorithms and one of the questions asked was:
What is the worst-case scenario for a linear search algorithm?
a) The target ...
0
votes
1
answer
49
views
Why curly braces for loop and if give wrong output in linear search in C?
When I used this function, it return -1 even if element of array was there.
int linear_search(int arr[], int length, int target)
{
for (int i=0; i < n; i++) {
if (arr[i] == target){
...
1
vote
0
answers
2k
views
How to calculate the FLOPS of a Python program?
I have the following python program for Linear Search algorithm:
import numpy as np
a, item = [2.6778716682529704, 8.224004328108661, 8.819020166860604, 25.04500044837642,
114.6788167136755, 147....
0
votes
1
answer
51
views
I can't understand how those functions link together
I was going through an algorithm course and it demonstrates a basic linear search algorithm and it uses a verify function to verify if the index is right or wrong but I don't understand how the verify ...
-1
votes
3
answers
404
views
One Pointer Search vs Two Pointer Search
Which algorithm is better in terms of time complexity and space complexity ?
temp_list = [2,4,1,3,7,1,4,2,9,5,6,8]
def get_item_from_list1(collection, target):
collection_length: int = len(...
1
vote
1
answer
450
views
Make a method that contains a linear search?
I'm new to programmning and I'm taking a course to learn the basics in c#.
Right now I'm doing a console application that are supposed to work as a blog. In the application the user should be able to ...
0
votes
0
answers
33
views
Linear Search Within Python List [duplicate]
I am trying to use a linear/sequential search through a list which contains data about users. I need to search for the users by first and last name and then retrieve the remaining list data to be ...
0
votes
1
answer
264
views
Linear and binary search, printing out the results
The goal of this project is to create a class search. I will need methods of binary search and linear search. For each method you are going to ask the user for a key, then search for this key in an ...
1
vote
1
answer
148
views
I'm new to programming. How do i linear search a number in array, i also have to create a function and pass the array[] and integer through that [closed]
public static int[] linearSearch(int arr[], int x) {
for (int i=0; i<arr.length; i++) {
if (arr[i]==x) {
return arr;
}
}
}
...
1
vote
1
answer
63
views
Can anyone reduce time complexity of this code
You are given three integers A, B, and C. You are allowed to perform the following operation any number of times (possibly zero).
• Choose any integer X such that X ≤ max (A,B, C), and replace A with
...