complexity

Debugger usage

Do you use the debugger of the language that you work in to step through code to understand what the code is doing, or do you find it easy to look at code written by someone else to figure out what is going on? I am talking about code written in C#, but it could be any language. ...

Optimum search for k minimum values in unsorted list of integers

I was just interviewed with a question, and I'm curious what the answer ought to be. The problem was, essentially: Say you have an unsorted list of n integers. How do you find the k minimum values in this list? That is, if you have a list of [10, 11, 24, 12, 13] and are looking for the 2 minimum values, you'd get [10, 11]. I've got an ...

Algorithms for Big O Analysis

What all algorithms do you people find having amazing (tough, strange) complexity analysis in terms of both - Resulting O notation and uniqueness in way they are analyzed? ...

Is minimization of boolean expressions NP-Complete?

I know that boolean satisfiability is NP-Complete, but is the minimization/simplification of a boolean expression, by which I mean taking a given expression in symbolic form and producing an equivalent but simplified expression in symbolic form, NP-Complete? I'm not sure that there's a reduction from satisfiability to minimization, but I...

How do you fight design complexity?

I often find myself fighting overengineering -- the person in charge of designing the software comes up with an architecture that's, way, way overcomplicated. It's all fine and dandy to have all the esoteric features that users will never know about and get that sense of achievement when you're doing something that all the magazine arti...

Effective ways of finding an element in a Javascript array

I am using an array with titles. Each titles index corresponds to an id in a database which contains html for that given title. Lets say I have a string which contains one of the titles. title = "why-birds-fly"; titles[] // an array which contains all the titles To use the string "title" to get the corresponding id I could do: for (...

How do I find the time complexity T(n) and show that it is tightly bounded (Big Theta)?

I'm trying to figure out how to give a worst case time complexity. I'm not sure about my analysis. I have read nested for loops big O is n^2; is this correct for a for loop with a while loop inside? // A is an array of real numbers. // The size of A is n. i,j are of type int, key is // of type real. Procedure IS(A) for j = 2 to l...

computational complexity exercise

I'm reading "Data structures and algorithms" from Aho, Hopcroft & Ullman, and I'm confused with exercise 1.12 B: Which is the computational complexity (expressed in Big O notation) of this Pascal procedure? procedure mysterious( n: integer ); var i, j, k: integer; begin for i := 1 to n - 1 do for j ...

MYSQL: Complex Query Question

Hello all, I am working with polls: Each poll has many options and users can vote in polls once. Thus I have a 'votes' table with the following fields: id (id of the vote) option_id (id of the poll option chosen) user_id (id of the user) poll_id (id of the poll) So here is what I'm trying to do: Given an array of poll_ids, I want ...

Companion matrix complexity

Hi, I know this is more a complexity theory question than a programming question, hope I'm not doing the wrong thing writing here, apologize me if it's the wrong place but I hope someone of you have the answer. And it's even someway programmin related by being a complexity theory qestion. I'm studying Linear Recurring Sequences, and I r...

Sorting in linear time?

Given an input set of n integers in the range [0..n^3-1], provide a linear time sorting algorithm. This is a review for my test on thursday, and I have no idea how to approach this problem. ...

What is the longest possible Regex in Polynomial Time?

The question Complexity of Regex substitution nears the question, but it is not the same. According to the reply by theprise, the complexity (of a DFA engine) is: O(2^m + n) [where m is the length of the regex and n is the length of the string] The red book "Algorithm Design Manual" on page 15-16 discusses the time for different al...

Possible Combination of Knapsack problem and ???

Alright quick overview I have looked into the knapsack problem http://en.wikipedia.org/wiki/Knapsack_problem and i know it is what i need for my project, but the complicated part of my project would be that i need multiple sacks inside a main sack. The large knapsack that holds all the "bags" can only carry x amount of "bags" (lets s...

NP-Hard? Algorithmic complexity of online poker collusion detection?

What's the best way to describe the algorithmic complexity of collusion detection for a ten-million-player online poker site? Assume (I don't think these assumptions make much difference so feel free to ignore them, but just to clarify): That the site has 10,000,000 registered users. That these players have played a total of 5 billion...

Programmatically checking code complexity, possibly via c#?

Hi all. I'm interested in data mining projects, and have always wanted to create a classification algorithm that would determine which specific check-ins need code-reviews, and which may not. I've developed many heuristics for my algorithm, although I've yet to figure out the killer... How can I programmatically check the computationa...

SQL `LIKE` complexity

Does anyone know what the complexity is for the SQL LIKE operator for the most popular databases? ...

When is enough abstraction enough?

I was having a conversation with a co-worker a few days ago. When I mentioned that a new coding technology he's interested in doesn't seem like anything that couldn't already be done with existing tools rather easily, he replied a bit dismissively, "that's what they said about object-oriented programming, too. It's just procedural progr...

When is enough abstraction enough

I tried asking this and it got closed very quickly for being too long. (Which it was.) But I think it's a genuine question that needs to be discussed, so here's a much shorter version: Abstractions are supposed to simplify your code. But in my experience maintaining other people's code, I consistently find that the trade-off for making ...

Determining the worst-case complexity of an algorithm

Can someone please explain to me how one can determine the worst-case complexity of an algorithm. I know that the we need to use the equation W(n) = max{t(I)|I element of D), where D is the set of inputs of size n. Do I calculate the number of operations performed for each element I and then take its max? What easier way is there to acco...

Hash tables using VLists

Phil Bagwell, in his 2002 paper on the VList data structure, indicates that you can use a VList to implement a persistent hash table. However, his explanation of how that worked didn't include much detail, and I don't understand it. Can anybody give me a more detailed explanation, or even examples? Further, it appears to me from what I ...