Questions tagged [search]
This tag is for questions about search algorithms, tools, and technologies.
392 questions
3
votes
4
answers
8k
views
Determining if a target string is found in an array of strings
I wrote this simple function in CoffeeScript to see if elements are found in an array:
...
4
votes
1
answer
200
views
Checking for an existing word in a file
This piece of code basically just asks for a word and sees if it exists in a file. If not, the user is asked if it should be added to the file.
I am new to C programming and I want to know what you ...
5
votes
1
answer
2k
views
Java alphabeta search
Is this code correct?
This code was adapted from this alphabeta pseudocode. AlphaBeta search is often mentioned but getting the code 100% correct is tricky.
IGame...
3
votes
0
answers
1k
views
Moving from Solr (Sunspot) to ElasticSearch (Tire), Review needed
I would like a review regarding the following code in which I index and search the City model. Currently both solr (with sunspot gem) and elaticsearch (with the tire gem) are show. I am migrating from ...
4
votes
2
answers
805
views
ElasticSearch, Tire - refactor autocomplete method for multiple resources
I am using ElasticSearch and Tire for search in my app across all models.
I would like to refactor autocomplete method because it looks to complex for me.
Am I using a good pattern for searching ...
1
vote
3
answers
6k
views
Searching for an element in a 2D array
For example, given a 2D array (a matrix):
{{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}}
What are the solutions to find a number, such as 6?
Here's the code I ...
3
votes
3
answers
2k
views
Search form sample pattern
I've just started to practice coding in OOP and just wanted to ask if my code's pattern is correct. I need your comments or suggestions so I can improve it.
sample_class.php:
...
3
votes
4
answers
460
views
Array-search algorithm for identical sequences and character distances
Here is Python code written to perform the following operations:
Find each occurrence of a three-letter sequence in a character array (e.g. a sequence such as ...
6
votes
1
answer
208
views
Randomizing and mutating algo class - functionality
See Randomizing and mutating algo class - style
I'm looking for a review of the functionality of this code, answers to the above question which also describes the code use focus on style instead.
...
2
votes
2
answers
11k
views
Tree node filtering with List<TreeNode>
I had a question about filtering tree view and returning just first match.
I've tried to create list<treenode> and change the code. Is it possible improve ...
2
votes
1
answer
2k
views
Iterative implementation of alpha beta tree search
This is an iterative implementation of alpha beta tree search in C#. Please help me confirm the correctness of my code. search() is called when the search begins.
<...
5
votes
2
answers
319
views
Randomizing and mutating algo class - style
I've updated this question to be about code style only, as all of it's answered focused on this aspect. For the codes function, see Randomizing and mutating algo class - functionality
...
5
votes
2
answers
1k
views
Golang solution to Project Euler #81 (min path through a matrix)
Project Euler problem 81 asks:
In the 5 by 5 matrix below,
...
17
votes
7
answers
143k
views
Finding repeating numbers in an array
I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to ...
2
votes
1
answer
167
views
Shifting Paths problem (Code Jam)
I was trying, just for fun, to solve http://code.google.com/codejam/contest/dashboard?c=2075486#s=p4
I can easily solve the small set, but I struggle to solve the big one (my implementation would ...
1
vote
1
answer
157
views
Kindly review this class [closed]
What I can think of improving is:
Show stack on screen to fail gracefully i.e. improved catch part of try..catch
Make the try part shorter to improve readability
Make imports with * to improve ...
3
votes
2
answers
871
views
UVA 10474 - "Where is the marble?" time limit
I have a problem from UVA online judge here. I have read it tons of times, and as they said, I have to get the answer really fast.
I have used a binary search and ...
6
votes
1
answer
6k
views
Java 2d array nested loops
Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both ...
2
votes
4
answers
5k
views
Multi column search
I have 4 text columns, a mix of Varchar and Text. I need to find rows in a table where all words searched for are present across the 4 columns.
The 4 columns are:
name
type
keywords
description
So ...
4
votes
1
answer
116
views
Improve search keyword
I've been given the following PHP code:
...
1
vote
1
answer
71
views
Regex Refinement
I'm trying to parse addresses out of blocks of text, and have the following expression to do so:
/\d+\s(?:[sewnSEWN]\.?\s)?[\d\w]+\s(?:(?:[\d\w]+\s){0,3})?\w+\.?/
...
3
votes
3
answers
3k
views
Finding the highest values a and b from an array
I struggled a short while to make this work, so I'm wondering if there are any smarter ways for finding the highest of two values per array element? Uh, hard to explain by words, but by code its easy:
...
2
votes
1
answer
906
views
need help improving mysql and php filter code
I only recently started coding so I know my code is not very good, but i would really appreciate any help on improving my code.
my database table looks like this
game_id |title |developer |...
8
votes
2
answers
12k
views
Implementation of Kosaraju's algorithm for strongly connected components
To learn and practice coding in C++, I wrote an implementation of Kosaraju's two-pass algorithm for computing the strongly connected components in a directed graph, using depth-first search.
This was ...
3
votes
1
answer
197
views
Word lookup code optimization
I have a Java class which accepts some data and reads it in as a raster of characters x by y. The class is used then to look for occurrences of a certain word in any direction of the raster and store ...
2
votes
1
answer
1k
views
Refactoring binary search algorithm in Ruby
I wrote the binary search algorithm with Ruby, the code is below. The question is if there's any way to make it look cleaner?
...
4
votes
3
answers
179
views
Is there a better, more object oriented way to write this Finder method?
I have several lists of objects which are stored in different locations, based on what they are and who needs them - the system, or the user, for example. There are times where I am only given an ID ...
4
votes
1
answer
226
views
Searching an object tree structure
I have this recursive function that searches an object tree structure:
...
7
votes
4
answers
24k
views
Searching for a value from one CSV file in another CSV file
I am writing a script that takes one CSV file searches for a value in another CSV file then writes an output depending on the result it finds.
I have been using Python's CSV Distreader and writer. I ...
4
votes
4
answers
368
views
Search module methods
Constructive criticism is required for the 2 methods below. I'm trying to develop better OO skills.
...
2
votes
2
answers
2k
views
Searching for a string in a web page
I have written the below code to search for a string in a web page. This is working fine but I need suggestions on improving this code to start using this. This is written to work under IE.
...
6
votes
2
answers
489
views
Sorted grep in Haskell
This program implements a sorted grep, that is, a specialized version of grep for sorted files. It uses binary search for the lines of a file that begin with a ...
5
votes
7
answers
12k
views
Efficient Binary Search
My implementation:
...
7
votes
1
answer
1k
views
Optimizing a search for list of artists in iTunes library
I'm trying to get a list of all artists on an iPhone / iPod touch music library. The best way I've found has been to group by artists (the convenience constructor on MPMediaQuery) and to iterate over ...
6
votes
1
answer
1k
views
Determine if an element exists in a sorted NxN matrix
The point of this algorithm is to see if an element exists in a NxN matrix that has its rows and columns sorted.
What would you change? What did I do well? Both perspectives help so I am not left ...
6
votes
5
answers
469
views
Search for products based on criteria
The method must search Products found by criteria and store them in @products.
The criteria are as follows:
If the user enters ...
3
votes
1
answer
2k
views
Review Request: Python code that searches query words in a given text
I have this code which looks for query words in a given text. I preprocess the give text and store it in an inverted-index (dictionary with word as key and position in text as value). Searching for a ...
5
votes
2
answers
6k
views
Is this a reasonable Trie implementation?
http://en.wikipedia.org/wiki/Trie
The basic idea is to support fast searches via prefix matching. In my implementation, I allow each node to store all of the words that match its given prefix, and ...
39
votes
5
answers
7k
views
JavaScript binary search
I wrote an implementation of binary search in JavaScript earlier for kicks, but I noticed my version was significantly different than those found on Google. Here is an example of binary search I found ...
4
votes
2
answers
374
views
SQL paged search results
I'm trying to figure out a way to simplify implementing paged searching in sql server.
My restrictions are:
has to be in a proc.
can't use dynamic sql.
Here's my sample query:
...
14
votes
4
answers
462
views
Finding subtuple in larger collection?
I've got a flat array of < 1000 items and I need to find the indices of a smaller tuple/array within the array. The tuple to find can be a varying length (generally between 2 and 5 items, order is ...
156
votes
20
answers
32k
views
Searching an element in a sorted array
I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...