complexity

Get the middle of an Ix range in O(1) time in Haskell

I was playing around with this code kata in Haskell, and I came across the question in the topic. It's trivial to find the midpoint of an array whose indexes are a single numerical value, but Haskell's array indexes can be any instance of the Ix typeclass, including, for example, the tuple (Int, Word, Card) where card is an instance of ...

Why are NP problems called that way (and NP-hard and NP-complete)?

Really.. I'm having the last test for graduation this Tuesday, and that's one of the things I just never could understand. I realize that a solution for NP problem can be verfied in polynomial time. But what does determinism has to do with that? And if you could explain me where NP-complete and NP-hard got their names, that would be grea...

How to determine the complexity of an algorithm function?

How do you know if a algorithm function takes linear/constant/logarithmic time for a specific operation? does it depend on the cpu cycles? ...

3D Connected Points Labeling based on Euclidean distances

Hi guys, Currently, I am working on a project that is trying to group 3d points from a dataset by specifying connectivity as a minimum euclidean distance. My algorithm right now is simply a 3d adaptation of the naive flood fill. size_t PointSegmenter::growRegion(size_t & seed, size_t segNumber) { size_t numPointsLabeled = 0; /...

Whats the best algorithm for Non Disjoint Set Union ?

Lets say there are two (non disjoint) sets of points (cartesian space), what is the best case complexity algorithm to perform the union of the two sets ? ...

What are the consequences of saying a non-deterministic Turing Machine can solve NP in polynomial time?

Hello guys, these days I have been studying about NP problems, computational complexity and theory. I believe I have finally grasped the concepts of Turing Machine, but I have a couple of doubts. I can accept that a non-deterministic turing machine has several options of what to do for a given state and symbol being read and that it wil...

How to do graph coverage testing for a complex class that require a lot of set up ?

Ok I have a class with methods that has high McCabe Cyclomatic Complexity. I have a school assignment to do graph coverage of that beast. The real problem is that it's hard to set up the inputs. Concretely, the program is a mario platform game and the job of the class is to compute mario states. There is a procedure that move mario and ...

Shortened syntax wastes memory?

I found that a neat way to convert an array-like object (e.g. NodeList, Arguments) into a real array is to use: Array.prototype.slice.call(...); Then, I thought of a way to shorten this syntax: [].slice.call(...); Would the latter method waste time and/or memory by creating a new array each time that it is called? Should I avoid th...

Time and space complexity of vector dot-product computation

Help me! What is the time and space complexity of an algorithm, which calculates the dotproduct between to vectors with the length n. ? ...

Finding a lower bound for an algorithm using the guess/verify method

Hi everyone, I am trying to work out a few guesses on algorithm complexity, but every time I attempt to guess using an exponential time, my guess/verify method seems to fail. I am sure I am doing something absurdly wrong, I just can't find it myself. For Example, if I have the recurrence T(n) = 2T(n-1) + T(n-2) + 1 , where T(1) = 0 and ...

What's faster: inserting into a priority queue, or sorting retrospectively?

What's faster: inserting into a priority queue, or sorting retrospectively? I am generating some items that I need to be sorted at the end. I was wondering, what is faster in terms of complexity: inserting them directly in a priority_queue or a similar data structure, or using a sort algorithm at end? ...

Asymptotic Growths of Functions

How to determine if a given f(n) and g(n) is in theta, omega, big oh, little omega, or little oh? - I think one way of doing it is by plotting graphs of both functions f(n) and g(n). Even by plotting graphs how do we say when a f(n) is in theta, omega, big oh, little omega, or little oh? Am not clear on that. Can someone throw more detai...

finding time complexity of recurrence relation in algorithms

Can anyone help me finding the time complexity of T(n)=1 if n<=0 T(n)=T(n-1)+T(n-2)+n ...

Scheme Code Analysis for Space vs. Time

I'm working my way through the online MIT lectures for the classic 6.001 course: The Structure and Interpretation of Computer Programs. I'm trying to gain an understanding of analyzing code complexity in terms of memory usage vs. execution time. In the first few lectures, they present a solution in Scheme for the Fibonacci Series. ...

prove n = Big-O(1) using induction

I know that the relation n = Big-O(1) is false. But if we use induction involving Big-O it can be proved. But the fallacy is we cannot induct Big-O. But my question is how we can disprove the relation by using the constants. The false proof is here, please give me the proof of it being false using the constants. I'm getting confused wit...

NP-hard problems that are not NP-complete are harder?

From my understanding, all NP-complete problems are NP-hard but some NP-hard problems are known not to be NP-complete, and NP-hard problems are at least as hard as NP-complete problems. Is that mean NP-hard problems that are not NP-complete are harder? And how it is harder? ...

What are some tips for a high traffic, complex form in ASP.NET MVC?

We currently have a WinForms application that we want to slowly migrate to a web application. One screen is a time sheet entry system that uses DataWindow and is very slow and buggy. Anyway, the time sheet screen has five sections that are saved in real time. A finished time sheet needs 2-5 of these sections. Currently, the system run...

How to compute the algorithmic space complexity

Hi all: i am reviewing my data structures and algorithm analysis lesson,and i get a question that how to determine to the space complexity of merge sort and quick sort algorithms ? The depth of recursion is only O(lgn) for linked list merge-sort The amount of extra storage space needed for contiguous quick sort is O(n). My th...

Is time complexity for insertion/deletion in a doubly linked list of order O(n)?

To insert/delete a node with a particular value in DLL (doubly linked list) entire list need to be traversed to find the location hence these operations should be O(n). If that's the case then how come STL list (most likely implemented using DLL) is able to provide these operations in constant time? Thanks everyone for making it clear ...

Meaning of average complexity when using Big-O notation

While answering to this question a debate began in comments about complexity of QuickSort. What I remember from my university time is that QuickSort is O(n^2) in worst case, O(n log(n)) in average case and O(n log(n)) (but with tighter bound) in best case. What I need is a correct mathematical explanation of the meaning of average compl...