All Questions
16 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 ...
-1
votes
2
answers
177
views
Try catch for ArrayIndexOutOfBoundsException [duplicate]
I am running a test for Binary search method for a value which is not found in an object array by using the try catch block, but the error ArrayIndexOutOfBoundsException is still being thrown.
Please ...
-2
votes
2
answers
698
views
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 ...
0
votes
1
answer
122
views
Are my Java Binary and Linear Search Algorithms working correctly?
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 ...
0
votes
1
answer
938
views
Binary Search keeps returning false when the return value should be true
I am using NetBeans to program a sort of library database with reference numbers to find the books. I am using both Linear and Binary searches to determine if the reference number is in the library, ...
1
vote
2
answers
636
views
Binary search slow on smaller arrays
I wrote a program that tests speeds of linear and binary search and have found that at the beginning when the sorted array is the size of 1000 binary search uses a lot more time than later on when ...
1
vote
5
answers
589
views
Applying Linear and Binary Searches to Arrays
I have to create a program that takes a user input (a number) and then the program should have that number and apply a search to the array and output the corresponding title by matching the index and ...
1
vote
1
answer
4k
views
Random Number Array using binarySearch and Linear Search
I have created the array and a method to sort the array, but I am still stuck on how to implement the binary search method in the array. Also the binary search method needs to be called from the array ...
1
vote
1
answer
453
views
search an array for a number 10 times and calculate the time for each search
I want to create an array with 10 million numbers from 1- 10 million. I am using a loop to populate the array (increment of 1). Now I want to search the first array 10 times (create a loop to search ...
0
votes
1
answer
130
views
Linear and Binary search logical error
I'm working on a program where I have to demonstrate the working of a linear and binary search algorithm. For that, I'm acceping an array of 20 numbers and a search key from the user. The code ...
9
votes
4
answers
17k
views
Which is more efficient, Sorting and then Binary Search over a Collection or Linear Search in java
Suppose I am having a Collection of object:
List<String> myList = populateMyArrayList();
//Here I am having an ArrayList with 1000 elements
Which is the better approach:
1 : Mergesort then ...
0
votes
3
answers
895
views
Is a binary or sequential/linear search more efficient when searching a sorted linked list?
I need to write a program that searches through a previously sorted linked list and I'm not sure which search would be more efficient.
0
votes
2
answers
367
views
Use binary search if sorted otherwise use linear search
I'm given a problem where the user is given an empty recipe book and they can input and sort the recipes.
I know that a book is sorted if it is empty, has one recipe, and two recipes(ascending/...
0
votes
1
answer
230
views
Java loop through array
How do you loop through an array until you you reach the last 50 elements of your array then??
say I have this binary search code:
public class Binary
{
public static final int NOT_FOUND = -1;
...
1
vote
2
answers
702
views
Binary and Linear search
This program is suppose to detect if an integer is found or not and how long it took to find. The first one is a linear search and the second is a binary search. The problems I'm having is this. The ...