# explain me this small code

karim hofeer
Greenhorn
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
Posts: 12143
30
you're probably going to wait a long time. We don't hand out homework answers/solutions here.

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

Dan Walin
Ranch Hand
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
Posts: 2
fred rosenberger wrote:you're probably going to wait a long time. We don't hand out homework answers/solutions here.

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
Sheriff
Posts: 21113
32
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
Marshal
Posts: 21189
80
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