Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I basically need to have a very fast search for huge numbers (in the 2^128 range). Is there anything out there that gves better performance than binary search, ie. better than O(log n) ?
[edit] The data is sorted and pretty much evenly distributed.
Binary Search works only when the data is sorted. A marginal improvement over binary search is interpolation search. However, the efficiency of Interpolation Search over Binary Search depends on the distribution of your data. If the data set is pretty uniformly distributed, then interpolation search can be favored.
This link may help,
http://blog.imaginea.com/interpolation-search-a-search-algorithm-better-than-binary-search/
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
In Data Structures and Algorithms in Java, the advantages of ordered arrays are stated. One of the advantages, I wish I had some kind of real example for. This is not for homework, but just self-clarification. What are some real cases for when insertion/deletion is not frequent, but searches are frequent? Anything would help even if you can point me in the direction of some github repository. Thank you.
An example would be a dictionary. After it is built, it can be looked up millions of time. Like your paper dictionary, the words in it better be sorted.
While I like leeyuiwah's answer, a more common domain which you can see in commercial context is a data base of some entity, for example the customers or employees, for which normally you create a view. That's why we index them (make the retrieval faster). Indeed, after inserting some records most of the operations will be retrieval which includes a search (based on complicated conditions or a simple identifier).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I was asked this in interview. I thought the question was too generic to specify a particular data structure.
However, still if we channelize the question to following criterion what would be the best data structure to use:
If insertion speed should be fastest?
If search of particular data is to be the fastest?
The HashSet provides both O(1) insertion and O(1) search, which is hard to top from a theoretical point of view.
In practice, for a size of 10.000 references, a sorted ArrayList might still outperform HashSet, although insertion is O(n) and search is O(log(n)). Why? Because it stores the data (the references at least) in a contiguous memory range and therefore can take advantage of hardware memory caching.
The issue with big-O notation is that it completely ignores the time required for a single operation. That's fine for asymptotic considerations and very huge data sets, but for a size of 10.000 it might be misleading.
Haven't tried it, though. And I bet your Interviewer hasn't either :).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm having trouble understanding the concept of using FFT to calculate frequency changes. I've been scavenging through a ton of articles on this concept but it's still confusing me. I found a Stack Overflow article about the steps to take to calculate the frequency, but I'm still a little bit confused on exactly what to do in Java.
Sounds like you need to start way back with some general concepts. An FFT is just a fast DFT. A DFT uses Fourier decomposition on a set of sampled data. So first you need to understand what a waveform is, what a sinusoid is, what a frequency is (and is not the same as a musical pitch), and how Fourier's theorem works to relate the two. Then how to compute a DFT on a window of a sampled waveform, and how to interpret the complex result vector. Then how to do it fast in Java.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been aksed to write a program that finds the largest area of equal neighbour elements in a rectangular matrix and prints its size. I tried to construct a 2d array with some numbers but I think that I should switch to using a tree or something in order to solve this problem. Chould somebody suggest a possible way of solving it?
For example:
"Hint: use the algorithm Depth-first search or Breadth-first search."
Sounds like a standard maze search problem. I suggest you use recursion to find all the elements which you haven't been to before which have the same number as the one you have found. You can either update the matrix as you go or create a copy to keep track of the cells you have visited. So you don't need a tree or even an additional complex data structure.
use the algorithm Depth-first search or Breadth-first search
These are two types of recursive searches. I suspect you could implement both of these to see how they behave.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to store a list of (Object, int) in a data structure such that the int field can be easily sorted (ascending or descending).
I'm looking at Hashtables and TreeMaps but i'm unsure which, if either, of these are good for this purpose.
The priority is the sort speed. Any suggestions?
Given what you've told us, it's hard to say what'd be best.
If you're concerned with sorting performance alone, a HashTable or TreeMap (actually a red-black binary tree) have great sorting performance, but they're slower than some other data structures when adding (and in TreeMap's case, deleting) items.
You should probably provide more details regarding what you're doing with the data.