• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The complexity of the algorithm

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
helloo every body

I have a problem about The complexity of the algorithm

f=1
x=2
for (int i = 1; i <= n; i*=2)
for (int j = 1; j <= i * i; j++)
if (j % i == 0)
for (int k = 1; k <= j*i; k++)
f=x*f;

can you please find out the complex of this Algorithm .

thank you
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

In order for folks to help you, you'll need to ShowSomeEffort(⇐click) (tell us what you think, and why) and TellTheDetails(⇐click) about what exactly you mean by "complexity" (there are multiple ways to define and measure it) and what specifically you're having trouble with.
 
nessreen xyz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
helloo :

Sorry, for I was not clear

but what I need is one of this Solutions which is :

O (n^2 )
O (n log n )
O (n ^3 )
O ( 3 ^n )

and why !!

thank you
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said, you'll need to ShowSomeEffort(⇐click) (tell us what you think, and why).

This site is not here to do your homework for you.

Also, as I mentioned, you need to check your private messages. This is not optional. Failure to do so may result in your account being locked.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Jeff said, we don't just hand out homework answers here - which I'm assuming that is.

So...what have you been told about how to approach these questions, and how have you tried to apply it? We might be able to explain concepts, but you're going to have to reach the answer.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nessreen xyz wrote:but what I need is one of this Solutions which is :

O (n^2 )
O (n log n )
O (n ^3 )
O ( 3 ^n )

and why !!


We know what you WANT. However, that is not what you are going to GET. If we just tell you the answer, then the next time you have a problem like this, you are no better off. If instead we help you learn how to figure it out on your own, you can do the next one without us.
 
nessreen xyz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
f=1
x=2
for (int i = 1; i <= n; i*=2)
for (int j = 1; j <= i * i; j++)
if (j % i == 0)
for (int k = 1; k <= j*i; k++)
f=x*f;


sorry but It is not a homework It is an exercises
I try but I couldn't continue , here are what I done :

First :

for (int k = 1; k <= j*i; k++)
f=x*f;

so the complex is i*j

for (int j = 1; j <= i * i; j++)
if (j % i == 0)
we have Condition when j Divisible by i
so j=l*I : l=1,2,…………….., I
so the The total number of collection is
(i^2(i-1))/2= O(i^3)

for (int i = 1; i <= n; i*=2)
the first i=1
the second i=2
the third i=4
the m is i=2^m
the last n^m=n
m=log n
here I stop i couldn't continue because I think there is a connection between the three Iterative loops

sorry if my English is not good
thank you
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nessreen xyz wrote:sorry but It is not a homework It is an exercises


Erm...and the difference is?

here I stop i couldn't continue because I think there is a connection between the three Iterative loops


There may well be, but the question for you to solve is: which is the most important?
O notation is not exact; it is a guide. So your problem is to decide either:
1. which of the loops has the deciding effect, or
2. what is the overall effect of the loops.

sorry if my English is not good
thank you


We're used to people who don't speak English as their first language, but "please do my work for me" is the same in any language.

Winston
 
nessreen xyz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
helloo

Erm...and the difference is?


homework there are marks , here i need to learn to i can solve the home work .

sorry if i upset any one
thank you
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nessreen xyz wrote:helloo

Erm...and the difference is?


homework there are marks , here i need to learn to i can solve the home work .



The grades are only part of it. Either way, you're trying to learn, and you won't learn by somebody just doing it for you.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"nessreen xyz", please check your private messages for an important administrative matter. This is not optional.
 
reply
    Bookmark Topic Watch Topic
  • New Topic