Skip to main content
deleted 277 characters in body
Source Link
D.W.
  • 165.6k
  • 21
  • 230
  • 490

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it: Is $\mathcal{O}(n)$ the time complexity of this algorithm?

enter image description herealgorithm

My thoughts:

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm.

Are my thoughts correct and is $\mathcal{O}(n)$ the time complexity?

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm.

Are my thoughts correct and is $\mathcal{O}(n)$ the time complexity?

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. Is $\mathcal{O}(n)$ the time complexity of this algorithm?

algorithm

My thoughts:

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm.

deleted 8 characters in body
Source Link
Lereu
  • 111
  • 3

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm. I really struggle determining

Are my thoughts correct and is $\mathcal{O}(n)$ the time complexity, so I would appreciate any feedback!?

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm. I really struggle determining complexity, so I would appreciate any feedback!

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm.

Are my thoughts correct and is $\mathcal{O}(n)$ the time complexity?

added 118 characters in body
Source Link
Lereu
  • 111
  • 3

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm. I really struggle determining complexity, so I would appreciate any feedback!

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

I really struggle determining complexity, so I would appreciate any feedback!

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

So since $\mathcal{O}(n)$ is the dominating term here, I suppose that this is the time complexity of this algorithm. I really struggle determining complexity, so I would appreciate any feedback!

Source Link
Lereu
  • 111
  • 3
Loading