complexity-theory

Way to store a large dictionary with low memory footprint + fast lookups (on Android)

强颜欢笑 提交于 2019-12-02 16:19:26
I'm developing an android word game app that needs a large (~250,000 word dictionary) available. I need: reasonably fast look ups e.g. constant time preferable, need to do maybe 200 lookups a second on occasion to solve a word puzzle and maybe 20 lookups within 0.2 second more often to check words the user just spelled. EDIT: Lookups are typically asking "Is in the dictionary?". I'd like to support up to two wildcards in the word as well, but this is easy enough by just generating all possible letters the wildcards could have been and checking the generated words (i.e. 26 * 26 lookups for a

What is the time complexity of indexing, inserting and removing from common data structures?

跟風遠走 提交于 2019-12-02 15:44:29
There is no summary available of the big O notation for operations on the most common data structures including arrays, linked lists, hash tables etc. Information on this topic is now available on Wikipedia at: Search data structure +----------------------+----------+------------+----------+--------------+ | | Insert | Delete | Search | Space Usage | +----------------------+----------+------------+----------+--------------+ | Unsorted array | O(1) | O(1) | O(n) | O(n) | | Value-indexed array | O(1) | O(1) | O(1) | O(n) | | Sorted array | O(n) | O(n) | O(log n) | O(n) | | Unsorted linked list |

B-Tree vs Hash Table

限于喜欢 提交于 2019-12-02 15:43:15
In MySQL, an index type is a b-tree, and access an element in a b-tree is in logarithmic amortized time O(log(n)) . On the other hand, accessing an element in a hash table is in O(1) . Why is a hash table not used instead of a b-tree in order to access data inside a database? The Surrican You can only access elements by their primary key in a hashtable. This is faster than with a tree algorithm ( O(1) instead of log(n) ), but you cannot select ranges ( everything in between x and y ). Tree algorithms support this in Log(n) whereas hash indexes can result in a full table scan O(n) . Also the

Worst case time complexity analysis pseudocode

淺唱寂寞╮ 提交于 2019-12-02 14:59:27
问题 Could someone help me out with the time complexity analysis on this pseudocode? I'm looking for the worst-case complexity here, and I can't figure out if it's O(n^4), O(n^5) or something else entirely. If you could go into detail into how you solved it exactly, it would be much appreciated. sum = 0 for i = 1 to n do for j = 1 to i*i do if j mod i == 0 then for k = 1 to j do sum = sum + 1 回答1: First loop: O(n) Second loop: i is in average n/2 , you could have an exact formula but it's O(n²)

Different decision tree algorithms with comparison of complexity or performance

二次信任 提交于 2019-12-02 14:01:48
I am doing research on data mining and more precisely, decision trees. I would like to know if there are multiple algorithms to build a decision trees (or just one?), and which is better, based on criteria such as Performance Complexity Errors in decision making and more. doug Decision Tree implementations differ primarily along these axes: the splitting criterion (i.e., how "variance" is calculated) whether it builds models for regression (continuous variables, e.g., a score) as well as classification (discrete variables, e.g., a class label) technique to eliminate/reduce over-fitting whether

Explain the proof by Vinay Deolalikar that P != NP [closed]

怎甘沉沦 提交于 2019-12-02 13:55:41
Recently there has been a paper floating around by Vinay Deolalikar at HP Labs which claims to have proved that P != NP . Could someone explain how this proof works for us less mathematically inclined people? Michael Anderson I've only scanned through the paper, but here's a rough summary of how it all hangs together. From page 86 of the paper. ... polynomial time algorithms succeed by successively “breaking up” the problem into smaller subproblems that are joined to each other through conditional independence. Consequently, polynomial time algorithms cannot solve problems in regimes where

What is the time complexity of the following algorithm? [duplicate]

放肆的年华 提交于 2019-12-02 12:49:46
This question already has an answer here: How to find time complexity of an algorithm 9 answers can someone tell me what is the time complexity of this algorithm? keep in mind: the second method (findMax) - run on the array based on the index that it gets, means that the method (findMax) doesn't run on all the array every time. I think that the time complexity of this algorithm is O(n) but maybe I'm wrong. public class Q2 { public static int[] replace(int []a) { for(int i = 0; i < a.length; i++ ){ if(i == a.length-1){ a[i] = 0; } int maxSubArry = findMax(a,i); swap (a, i, maxSubArry); } return

Complexity's and Run times

安稳与你 提交于 2019-12-02 11:36:07
I tried looking around to see if my answer could be answered but I haven't stumbled what could help me. When Dealing with Run Time Complexity's do you account for the operands? From my understanding dealing with run time you have each different operand can take x-amount of time so only counting for the loops with give you the lower bound? If this is incorrect can you please explain to me where my logic is wrong. for example: for (i=0;i<n;i++) for (j=0;j<n;j++) a[i,j]=b[i,j]+c[i,j] Would just be O(n^2) right? or would it be O(a*n^2) because of the Addition Operand?? and you use "O" for run time

Worst case time complexity analysis pseudocode

偶尔善良 提交于 2019-12-02 11:18:36
Could someone help me out with the time complexity analysis on this pseudocode? I'm looking for the worst-case complexity here, and I can't figure out if it's O(n^4), O(n^5) or something else entirely. If you could go into detail into how you solved it exactly, it would be much appreciated. sum = 0 for i = 1 to n do for j = 1 to i*i do if j mod i == 0 then for k = 1 to j do sum = sum + 1 First loop: O(n) Second loop: i is in average n/2 , you could have an exact formula but it's O(n²) Third loop happens i times inside the second loop, so an average of n/2 times. And it's O(n²) as well,

Where is the flaw in my algorithm for consolidating gold mines?

Deadly 提交于 2019-12-02 07:15:18
The setup is that, given a list of N objects like class Mine { public int Distance { get; set; } // from river public int Gold { get; set; } // in tons } where the cost of moving the gold from one mine to the other is // helper function for cost of a move Func<Tuple<Mine,Mine>, int> MoveCost = (tuple) => Math.Abs(tuple.Item1.Distance - tuple.Item2.Distance) * tuple.Item1.Gold; I want to consolidate the gold into K mines. I've written an algorithm, thought it over many times, and don't understand why it isn't working. Hopefully my comments help out. Any idea where I'm going wrong? using System;