Questions tagged [search]

Questions about search algorithm mechanics and implementation. *NOT* for questions about using search tools within an API (e.g. Google, Bing, Facebook).

Searching is one of the most common and important tasks in Computer Science.

The most basic search algorithm is a (also called "sequential search"). Each item in a collection of data is examined in sequence until the sought item is found.

If the collection in question has already been sorted, for instance, then a more efficient is possible.

Search can become more complex when, rather than finding one instance of a specific item, we want to find all items meeting a certain set of criteria. For instance a query can specify extremely complex search criteria, and much of relational database design involves the planning of an efficient way to perform those searches.

Another more complex search scenario is graph search, in which a series of nodes and edges must be traversed. Common algorithms for this domain include and . In many cases, a heuristic search algorithm such as can achieve more efficient results by making use of additional information about the problem.


Do not use this tag for questions about specific search tools within an API. Some more relevant tags for that would be the following:

37207 questions
289
votes
14 answers

Java List.contains(Object with field value equal to x)

I want to check whether a List contains an object that has a field with a certain value. Now, I could use a loop to go through and check, but I was curious if there was anything more code efficient. Something like; if(list.contains(new…
Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
287
votes
13 answers

Find a string by searching all tables in SQL Server

Is there any way to search for a string in all tables of a database in SQL Server? I want to search for string say john. The result should show the tables and their respective row that contain john.
Ramiz Raja
  • 5,942
  • 3
  • 27
  • 39
279
votes
6 answers

Exclude folders from Eclipse search

Is there a way to exclude certain folders (and all their subfolders) from searching within Eclipse?
Dónal
  • 185,044
  • 174
  • 569
  • 824
274
votes
4 answers

How do I search within an array of hashes by hash values in ruby?

I have an array of hashes, @fathers. a_father = { "father" => "Bob", "age" => 40 } @fathers << a_father a_father = { "father" => "David", "age" => 32 } @fathers << a_father a_father = { "father" => "Batman", "age" => 50 } @fathers << a_father…
doctororange
  • 11,670
  • 12
  • 42
  • 58
265
votes
7 answers

Unable to forward search Bash history similarly as with CTRL-r

I am trying to search my bash history similarly as with CTRL-r, but to forward direction. It has been a pain for me, when I just hit once too often CTRL-r, to find the previous command again. How can you forward search your Bash history similarly as…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
263
votes
6 answers

How do I find the most recent git commit that modified a file?

I want to find the most recent commit that modified a source file. I can use git blame to see all the dates for commits by each line, but it’s difficult to see exactly which commit was the last one to touch the file. How can I find the last commit…
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
262
votes
14 answers

How do you make Vim unhighlight what you searched for?

I search for "nurple" in a file. I found it, great. But now, every occurrence of "nurple" is rendered in sick black on yellow. Forever. Forever, that is, until I search for something I know won't be found, such as "asdhfalsdflajdflakjdf" simply so…
mbac32768
  • 11,453
  • 9
  • 34
  • 40
222
votes
4 answers

Beginner's guide to ElasticSearch

There hasn't been any books about ElasticSearch (that I know of), and http://www.elasticsearch.org/guide/ seems to contain only references. Any good beginner's guide or tutorials, perhaps by examples, to recommend, especially in terms of the…
uzyn
  • 6,625
  • 5
  • 22
  • 41
220
votes
5 answers

Looking for files NOT owned by a specific user

I'm looking to recursively look through directories to find files NOT owned by a particular user and I am not sure how to write this.
mike628
  • 45,873
  • 18
  • 40
  • 57
215
votes
8 answers

Case-Insensitive List Search

I have a list testList that contains a bunch of strings. I would like to add a new string into the testList only if it doesn't already exist in the list. Therefore, I need to do a case-insensitive search of the list and make it efficient. I can't…
Brap
  • 2,647
  • 2
  • 19
  • 15
194
votes
8 answers

Check if value already exists within list of dictionaries in Python?

I've got a Python list of dictionaries as follows: a = [ {'main_color': 'red', 'second_color':'blue'}, {'main_color': 'yellow', 'second_color':'green'}, {'main_color': 'yellow', 'second_color':'blue'}, ] I'd like to check whether a…
AP257
  • 89,519
  • 86
  • 202
  • 261
189
votes
12 answers

What's the difference between the data structure Tree and Graph?

Academically speaking, what's the essential difference between the data structure Tree and Graph? And how about the tree based search and Graph based search?
user918304
  • 2,105
  • 3
  • 15
  • 9
189
votes
10 answers

Find an element in a list of tuples

I have a list 'a' a= [(1,2),(1,4),(3,5),(5,7)] I need to find all the tuples for a particular number. say for 1 it will be result = [(1,2),(1,4)] How do I do that?
Bruce
  • 33,927
  • 76
  • 174
  • 262
187
votes
6 answers

Tools to search for strings inside files without indexing

I have to change some connection strings in an incredibly old legacy application, and the programmers who made it thought it would be a great idea to plaster the entire app with connection strings all over the place. Visual Studio's "current…
kitsune
  • 11,516
  • 13
  • 57
  • 78
183
votes
15 answers

Nearest neighbors in high-dimensional data?

I have asked a question a few days back on how to find the nearest neighbors for a given vector. My vector is now 21 dimensions and before I proceed further, because I am not from the domain of Machine Learning nor Math, I am beginning to ask myself…
Legend
  • 113,822
  • 119
  • 272
  • 400