This is easy.
Almost nothing matters more than clarity to the reader. The first variant I found incredibly simple and clear.
The second 'improved' version, I had to read several times and make sure all the edge conditions were right.
There is ZERO DOUBT which is better coding style (the first is much better).
Now - what is CLEAR to people may vary from ...
Programming makes you a good coder; reading can make you a good developer:
Browse API documentation to make sure you don't reinvent the wheel or use the APIs incorrectly or inefficiently.
Look up language documentation to make sure you don't continue programming in language Foo when starting to work with language Bar.
Read and understand best practices and ...
Assuming that you mean "integer" when you say "number", you can use a bitvector of size 2^n, where n is the number of elements (say your range includes integers between 1 and 256, then you can use an 256-bit, or 32 byte, bitvector). When you come across an integer in position n of your range, set the nth bit.
When you're done enumerating the collection of ...
Basically, because an index is ordered, and when searching through an ordered data set, you don't have to search every item to find the element you're looking for; there are faster ways.
Discussing database indexing in detail can become very arcane very quickly, but the simplest way to answer this is that you can use techniques such as a binary search to ...
You can use the + or - signs to add or remove weight for a search term.
However the best place to search really isn't google at all, it's StackOverflow
A few google examples anyway:
+C for articles where the letter C stands alone
+C -C++ for C articles where there are no references to C++
+"C Sharp" for articles with weight added to a grouped term
Personally I've always googled "C programming", and then whatever topic regarding the language that I'm curious about... That is...
Until I found out about stack overflow. Now I just use the already existing language tags there, and search within them. If noone has answered any question on the subject of matter (quite rare but it happens every now and then) ...
A search feature can be modelled as a separate service with separate responsibility from the two services you mention. So, the approach here could be to create a new service ('search') and have it store a copy of the data from both services in a form which is easy to index and search, possibly also denormalized in order to quickly give results in the desired ...
I think for simple loops, such as these, the standard first syntax is much clearer. Some people consider multiple returns confusing or a code smell, but for a piece of code this small, I do not believe this is a real issue.
It gets a bit more debatable for more complex loops. If the loop's contents cannot fit on your screen and has several returns in the ...
In a healthy development environment those people who are really good at searching, finding and understanding solutions to tough problems online are in high demand. Writing software is a tough and fast-changing business and there will always be dark corners or new issues where a little googling can save a lot of time.
Just avoid becoming a cargo-cult ...
(1) What all features should I extract?
First, realize that you're not classifying documents. You're classifying (document, query) pairs, so you should extract features that express how well they match.
The standard approach in learning to rank is to run the query against various search engine setups (e.g. tf-idf, BM-25, etc.) and then train a model on the ...
1. If you rarely add and remove data
What about using the same technique as the one used in RDBMS with indexes?
In other words, you'll have the unordered set containing the data, and four ordered sets containing the keys and the pointers to the items in the data set.
Of course, this may cause performance issues if you need to frequently add and remove ...
It is not that the computer knows what the result is without reading the table. It actually does quite a lot of work to find the result, but it is very fast, so it appears instantaneous to you. But yes, certainly, it does not read the entire table.
The way it works is implementation dependent, but a popular simple algorithm which serves for illustration ...
This is a usability question (for UX.SE). Ideally, you would
first produce the most relevant results (the ones with the exact phrase entered),
then the results with search keywords (and their inflections) adjacent to each other,
then the results for the AND operation on search by individual keywords/their inflections (i.e. anywhere in the document),
If you don't know the answer, what else are you supposed to do? Your choices are to look it up in some reference (physical or electronic), ask a coworker, or sit on your hands all day not getting anything done. Your first step if you are stuck should be to try to resolve it yourself, looking online and in books. If that gets you nowhere, or it's about ...
Microsoft Access was based on a database engine called Jet which offered * and ? as wildcards for LIKE. These were never a part of the SQL standard. At some point, Microsoft incorporated a SQL-92 mode which offered the standard characters.
The use of % and _ goes back a very long way. My copy of An Introduction to Database Systems by C.J. Date (4th ...
int i = 0;
while (i < array.length && array[i] != value)
return i < array.length;
[…] everything is more obvious and more in a structured-programming way.
Not quite. The variable i exists outside the while loop here and is thus part of the outer scope, while (pun intended) x of the for-loop exists only within the scope of the ...
What you are looking for is called a spatial index and the problem you are trying to solve is collision detection.
More specifically I would use a quadtree data structure, which subdivides your space into four subspaces each time you descend one level in the tree. This is in 2D, if you are trying to solve the problem in 3D the appropriate structure would be ...
I can think of at least four factors that might be underway here:
As you say - resources are improving all the time, and less searching is required to find useful information
People search at specific sites more (such as stackoverflow) rather than a broader search through Google
People are searching for solutions which use specific frameworks/libraries ...
SQL dates back to the early 1970s. It's about the same age as UNIX. UNIX-style file name matching wildcards didn't become ubiquitous until much later.
* was already a reserved character in SQL, as in SELECT * FROM Customer. Having it also be a wildcard would probably have been confusing.
And standardization -- of wildcard characters or anything else -- ...
The "index" of a book is not a great metaphor, IMO. A better metaphor is trying to look up a word in a dictionary. Imagine that you want to look up a word in the Oxford English Dictionary (OED), which is a massive dictionary that comprises multiple volumes.
The words in the OED are sorted alphabetically, of course, to make it easy to look up a word. But ...
Python has a great natural language toolkit, the NLTK. It supports word tokenisation out of the box:
>>> import nltk
>>> input = 'We have some great burritos!'
>>> tokens = nltk.word_tokenize(input)
['We', 'have', 'some', 'great', 'burritos', '!']
[('We', 'PRP'), ('have', 'VBP')...
The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).
There is no security issue while detecting duplicated files, therefore I would recommend a fast hashing code. For instance the project ccache uses MD4:
ccache uses MD4, a very fast ...
This is actually a very modest number of files for a doc management system. 5200 files x 52 weeks x 10 years is less than 3 million. Even at your own calculation, its only 1.5 TB of data over 10 years. That will easily fit on a hard drive.
For this volume of files, I would recommend keeping the files in the file system, not the database. It will give you ...
Generally speaking, some of the big website (think server and database clusters) applications that I've written, I've used a ...
For a start you will need a full text search engine like Apache Solr or Sphinx (there are more and some databases have full text features too, but I know those two and they are free and work great). If it has facet search (like Solr) this will help a lot (for certain types of queries). This will cover the largest part of indexing and performance issues.
The problem you have here in general is called the Scheduling Problem and in its general form is NP-complete. In other words, it is a well-known problem for which there exists no efficient algorithm (yet, or maybe never).
The linked page (already mentioned in a comment before) refers to one specific variant called job shop scheduling. There are many ...
Sorting the arrays will not work. By changing the order you will not be able to determine which element matches first.
The intersect solution will also not work. To use it you'd have to copy both arrays to a set class, which by definition does not preserve order.
Your answer is correct. I would consider using hashsets to reduce search time.
checking if a list is sorted defeats the purpose of the binary search (using less comparisons for a O(log n) running time instead of a O(n))
you are better of doing a linear search if you can't be sure the list is already sorted