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
n := n - 1 until swapped
second code :
begin Input: n (pos. Integer) Output: y (pos. Integer) Other: x, z (pos. Integer)
x := 2*n; y := 0; while x > 0 do
y := y + 1; z := 0; while z < 2 do
x := x – 1; z := z + 1;
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.
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.