How to find the time complexity?

Let’s learn how to find the time complexity. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

how would i find the time and space complexity of this code?

I am having difficulty finding space and time complexity for this code that i wrote to find number of palindromes in a string. /** This program finds palindromes in a string. */ #include <stdio.h> #include <string.h> #include <stdlib.h> int checkPalin(char *str, int len) { int result = 0, loop; for ( loop = 0; loop < len/2; loop++) { if ( *(str+loop) == *(str+((len - 1) - loop)) ) result = 1; else { result = 0; break; } } return result; } int main() { char *string = ...

Answer:

Don't forget that each call to checkPalin (which you do each time through the inner loop of main) executes...

Read more

infinitloop at Stack Overflow Mark as irrelevant Undo

Other solutions

Given an array A that has elements from the index 0 to N-1 are negative and from the index N to M-1 are positive. How do you find an algorithm that finds N in O(lg n) time complexity?

Consider a Array A of size M.  A[0], A[1], A[2], ......,A[n-1],A[n],A[n+1],......,A[M-1]. Elements A[0],...........,A[N] are negative and A[n+1],..........,A[M-1] are positive .What is the  O(lg N) algorithm that find the position N. Input : A[],M Output...

Answer:

Simple. Check numbers of the form 2^k -1. On finding the 1st positive number, So a modified binary search...

Read more

Kunal Tyagi at Quora Mark as irrelevant Undo

What is time complexity for find method in a set in C++?

I am inserting N strings each of length K. Had it been integers, the complexity would be log(N). But here we are storing strings, each of size K. What will be the complexity to find a string in this scenario?

Answer:

The complexity of std::set::find() being [math]O(log(n))[/math] simply means that there will be of the...

Read more

Anmol Singh Jaggi at Quora Mark as irrelevant Undo

Answer:

Check this Site by Topcoder http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=complexity...

Read more

wiki.answers.com Mark as irrelevant Undo

Answer:

Procedure 1) Convert each number to base-3. Let's say the longest number has k digits (in base-3) 2...

Read more

Leo Polovets at Quora Mark as irrelevant Undo

Answer:

This problem has a much faster solution than the one (probably) required in the question. For a given...

Read more

Michal Forišek at Quora Mark as irrelevant Undo

Answer:

Backtracking algorithm generally follows an exhaustive search on the sample space where N, N^2, N^K...

Read more

Shiwakant Bharti at Quora Mark as irrelevant Undo

Answer:

This can be solved in nlogn using a BIT / segment tree . http://codeforces.com/contest/61... This question...

Read more

Rajat De at Quora Mark as irrelevant Undo

Answer:

Just adding an optimization to David's answer. 1) Iterate over the first array "a" and put...

Read more

Sourabh Bansod at Quora Mark as irrelevant Undo

Answer:

There can be no short answer to this question. Firstly, one needs to choose the appropriate notion of...

Read more

Hans Hyttel at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.