wood burning stoves 2.0*
The moose likes Java in General and the fly likes explain me this small code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "explain me this small code" Watch "explain me this small code" New topic
Author

explain me this small code

karim hofeer
Greenhorn

Joined: Jul 11, 2011
Posts: 2
Hi to Everyone.

i am a new student, studing Computer science and engi..
and we'ar learning Algorithms in java..

but i dont understand two questions that our proffesor did
The question is :

what is the complexity time or time complexity in the following code?

procedure bubbleSort( A : Lista e elementeve per sortim ): n := Length( A ) - 1 repeat
swaped := false for each i in 0 to n repeat:
if A[ i ] > A[ i + 1 ] then swap( A[ i ], A[ i + 1 ] ) swapped := true
endeif endfor
n := n - 1 until swapped
prozedur ende


second code :

begin Input: n (pos. Integer) Output: y (pos. Integer) Other: x, z (pos. Integer)
end
x := 2*n; y := 0; while x > 0 do
y := y + 1; z := 0; while z < 2 do
x := x – 1; z := z + 1;


Waiting for one answer & solution

Thanks!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11355
    
  16

you're probably going to wait a long time. We don't hand out homework answers/solutions here.

Instead we will help you work through the problem yourself.

So, what do you know about "time complexity"?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
That doesn't look like Java to me. Is it some type of pseudo code? Is the assignment to translate that pseudo code into Java code?
karim hofeer
Greenhorn

Joined: Jul 11, 2011
Posts: 2
fred rosenberger wrote:you're probably going to wait a long time. We don't hand out homework answers/solutions here.

Instead we will help you work through the problem yourself.

So, what do you know about "time complexity"?



i know about time complexity but I do not understand the programming language that he wrote this code beacuse we have learned ONLY JAVA!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

If I'm not mistaken, that example is what is called "pseudocode". In other words it isn't a real programming language, it's something which looks like a programming language but is really a formalized sort of English. (Or a mixture of Albanian and English in your example.)

So you don't have "I don't understand that programming language" as an excuse. Look at it and read it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

karim hofeer wrote:
i know about time complexity but I do not understand the programming language that he wrote this code beacuse we have learned ONLY JAVA!


You instructor probably got the example from somewhere else -- or he has an ugly way to write pseudo code (and am betting the later). Regardless, it should not be hard to figure it out -- take a shot at it.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
GeeCON Prague 2014
 
subject: explain me this small code