time-complexity

Is it possible for breadth first search to have a larger operating time (O(n)) than IDDFS

I have an exam in an hour, and theres something in the lecture slides that I disagree with. Theres a nice little table saying that the time complexity of BFS is O(b^(d+1)), and the time complexity of IDDFS O(b^d), where b is a branching factor and d is the depth of the solution. I have no idea where he got the +1 for the BFS time complex...

Is it possible to use a Perl hash in a manner that has `O(log(n))` lookup and insertion?

Is it possible to use a Perl hash in a manner that has O(log(n)) lookup and insertion? By default, I assume the lookup is O(n) since it's represented by an unsorted list. I know I could create a data structure to satisfy this (ie, a tree, etc) however, it would be nicer if it was built in and could be used as a normal hash (ie, with %...

Calculating the probability of system failure in a distributed network

I am trying to build a mathematical model of the availability of a file in a distributed file-system. I posted this question at MathOverflow but this might as well be classified as a CS-question so I give it a shot here as well. The system works like this: a node stores a file (encoed using erasure codes) at r*b remotes nodes, where r ...

Polynomial time algorithms

I heard the following quote once, but forgot to whom it is attributed: While waiting for a (polynomial-time) algorithm to stop, don't forget that your lifetime is bounded by a polynomial, too. Could somebody supply a reference? Another question I have is: Polynomial-time algorithms are great, but what is an example of an algorithm...

Is partitioning easier than sorting?

This is a question that's been lingering in my mind for some time ... Suppose I have a list of items and an equivalence relation on them, and comparing two items takes constant time. I want to return a partition of the items, e.g. a list of linked lists, each containing all equivalent items. One way of doing this is to extend the equiv...

Is Enumerable.ElementAt<TSource> O(1) for HashSet?

Is the implementation in HashSet.ElementAt O(1) and if not, what is it? ...

Interview: Find shortest path to few elements

There is a museum organized as NxN room. Some rooms are locked and inaccessible. Other rooms are open and some rooms have guards. Guards can only move north, south, east and west, only through open rooms and only within the museum. For each room, find the shortest distance to a guard. What is the time complexity of your algorithm? ...

Is there a linear-time algorithm for finding the convex hull of a complex polygon?

I know there's a worst-case O(n log n) algorithm for finding the convex hull of a complex polygon and a worst-case O(n) algorithm for finding the convex hull of a simple polygon. Is there a worst-case O(n) algorithm for finding the convex hull of a complex polygon? A complex polygon is a polygon where the line segments may intersect. ...

Can we compute this in less than O(n*n) ...( nlogn or n)...

This is a question asked to me by a very very famous MNC. The question is as follows ... Input an 2D N*N array of 0's and 1's. If A(i,j) = 1, then all the values corresponding to the ith row and the jth column are going to be 1. If there is a 1 already, it remains as a 1. As an example , if we have the array 1 0 0 0 0 0 1 1 0 0...

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 ...

Integer time complexity in Haskell

Hello! I had an assignment in school last week to implement a function for calculating the n:th number in the fibonacci sequence. A 'sub-assignment' was to implement it using accumulation(Might not be a correct translation) in order to give the function O(n) time complexity. This all worked fine until I tried making the function (Int ->...

Determining the time complexities of worst case algorithms

Do the two algorithms have the same theta characterization of Θ(n^2)? int sum = 0; for (int i = 0; i < n; i++ ) for (int j = 0; j < n * n; j++ ) sum++; int sum = 0; for ( int i = 0; i < n; i++) for ( int j = 0; j < i; j++) sum++; If not then does this mean that this characterization is not Θ(n^3)? int sum = 0...

Adding two big Os

If a function A calls n^c functions B that runs in O(n^2) time, what is the time complexity of function A? Is it just polynomial (n^c) as well as c has just gotten bigger? ...

Big-O Notation Code Algorithm Analysis Homework

for(int i=N; i>0; i=i/2) irrelevant statement; I am asked to find the complexity class and I am unsure of whether I am supposed to use Big-Omega notation or Big-O? But I am assuming that it is O(N/2) and then O(N) if I drop the constants. for (int i=0; i<N; i++) for (int j = i+1; j<N; j++) irrelevant statement; ...

Can some one help solving this recurrence relation?

T(n) = 2T(n/2) + 0(1) T(n) = T(sqrt(n)) + 0(1) first one I use substitution method for n, logn, etc, all gave me wrong answers. Recurrence trees: I dont know if I can apply as the root will be a constant Can some one help? T ...

Time complexity of Euclid's Algorithm

I am having difficulty deciding what the time complexity of Euclid's great common denominator algorithm is. Sample pseudo-code is: function gcd(a, b) while b ≠ 0 t := b b := a mod b a := t return a The only decision I think of is, "It depends." It seems to depend on "a" and "b." But what would the big-O n...

How can one test time complexity "experimentally"?

Could it be done by keeping a counter to see how many iterations an algorithm goes through, or does the time duration need to be recorded? ...

Python and Figuring out (Big-O) Running time

Hey can anyone help me with my homework question to do with python and running time please? This is the question below: In each code fragment given below, determine the number of steps and describe what the code accomplishes, i.e., what value of x has been output based on the value of the integer n. Assume the value of n has already b...

Big Oh Algorithm Time Complexity

000000000000000000 ...