Primarily check wikipedia on pseudocode. Either:
- use a Pascal style (for instance), or
- use a Math style
First a bug on first glance:
If minsource > source[i]
minsource = source[i]
Else if maxsource < source[i]
maxsource = source[i]
Endif
Should be
If minsource > source[i]
minsource = source[i]
Endif
If maxsource < source[i]
maxsource = source[i]
Endif
The case should be consistent (minsource/Minsource).
You might introduce
Function {int min, int max} array_min_max(int[] array)
min = Integer.MAX_VALUE;
max = Integer.MIN_VALUE;
For value in array
min = Math.min(min, value);
max = Math.max(min, value);
Endfor
Endfunction
Declaring at first use can be better readable.
Declare int minsource, maxsource
For (int i = 0; i < source.length; i++)
If i == 0
minsource = source[i]
maxsource = source[i]
Else
If minsource > source[i]
minsource = source[i]
EndIf
If maxsource < source[i]
maxsource = source[i]
Endif
Endif
Endfor
For (int i = 0; i < m; i++)
Declare int mintarget, maxtarget
{mintarget, maxtarget} = array_min_max(target[i]);
If minsource == mintarget && maxsource == maxtarget
Print true
STOP
Else if maxtarget > maxsource
Print false
STOP
Endif
Endfor
Print false
STOP
On the pseudo-language itself: the "Basic" above with its recognisable C I find a bit irritating. Also I would go for min_target or minTarget instead of mintarget.
There are so many languages. In Computer Science there is a long non-tradition. The high level expression language Algol68 was used often, as it even has a bold type face for types and keywords. It would indeed be nice if you could use richt text.
Pascal like pseudo code, maybe borrowed from Modula with IF THEN ELSE END.
Personally I do not like camel case and would prefer all lower case.
Answer from Joop Eggen on Stack OverflowConvert code to pseudocode automatically
algorithm - Translating C programming into pseudocode - Stack Overflow
Is it malpractice to use Chat-Gpt to convert actual code into pseudocode?
Is it malpractice to use Chat-Gpt to convert actual code into ...
Videos
Hello
Is there any app that takes input a code and translates to pseudocode?
Thank you
Primarily check wikipedia on pseudocode. Either:
- use a Pascal style (for instance), or
- use a Math style
First a bug on first glance:
If minsource > source[i]
minsource = source[i]
Else if maxsource < source[i]
maxsource = source[i]
Endif
Should be
If minsource > source[i]
minsource = source[i]
Endif
If maxsource < source[i]
maxsource = source[i]
Endif
The case should be consistent (minsource/Minsource).
You might introduce
Function {int min, int max} array_min_max(int[] array)
min = Integer.MAX_VALUE;
max = Integer.MIN_VALUE;
For value in array
min = Math.min(min, value);
max = Math.max(min, value);
Endfor
Endfunction
Declaring at first use can be better readable.
Declare int minsource, maxsource
For (int i = 0; i < source.length; i++)
If i == 0
minsource = source[i]
maxsource = source[i]
Else
If minsource > source[i]
minsource = source[i]
EndIf
If maxsource < source[i]
maxsource = source[i]
Endif
Endif
Endfor
For (int i = 0; i < m; i++)
Declare int mintarget, maxtarget
{mintarget, maxtarget} = array_min_max(target[i]);
If minsource == mintarget && maxsource == maxtarget
Print true
STOP
Else if maxtarget > maxsource
Print false
STOP
Endif
Endfor
Print false
STOP
On the pseudo-language itself: the "Basic" above with its recognisable C I find a bit irritating. Also I would go for min_target or minTarget instead of mintarget.
There are so many languages. In Computer Science there is a long non-tradition. The high level expression language Algol68 was used often, as it even has a bold type face for types and keywords. It would indeed be nice if you could use richt text.
Pascal like pseudo code, maybe borrowed from Modula with IF THEN ELSE END.
Personally I do not like camel case and would prefer all lower case.
If I understand you well, you do not want the pseudo-code to look much like a program code so that someone using different progarmming language can use it and solve the same task. I have some tips that could help you achieve that. The main idea is that you should avoid using syntactic elements of the programming language. Think in terms of the problem beign solved, not the programming language. Write your pseudo-code in simple language that any one can read and understand. It should be simple that someone with out coding skills can follow it and solve thesame task. Here is an example of simple pseudo-code of a function that finds the second maximum element in an array.
The function takes two inputs:
arr - array of integers
length - lenght of the array
It returns:
secMax - Second maximum element
Then the steps (should be in a simple language)
Define and set the maximum and second maximum as the minimum possible value
Repeat for each element of the array
{
If the current element is greater than the current maximu
{
then make current maximum as second maximum
Make the maximum as current array element
(Now you have new maximum and second maximum)
}
else if the current array element is less than maximum but is greater than second
maximum
{
then make it second maximum
}
}
return second maximum
As you can see I just explained the steps without using syntactic elements of any programming language. So now anyone can implement my steps using his/her comfortable language to solve the same task.
Let's say I want to implement this using C, my code will be something like this:
//Defining the function according to the information above
//It takes to inputs and returns an integer
int findSecondMaximum(int arr[], int length)
{
//Define and Set the maximum and second maximum as the minimum possible value
int max, secondMax;
max = secondMax = INT_MIN;
for (int i = 0; i < length; i++) //Repeat for each element of the array
{
//If the current element is greater than the current maximum
if (vect[i] > max)
{
//then make the current maximum as second maximum
secondMax = max;
//Make the maximum as the current array element
max = vect[i];
}
/*else if the current array element is less than maximum but is greater than
second maximum*/
else if (vect[i] > secondMax && vect[i] < max)
{
//make it second maximum
secondMax = vect[i];
}
}
//return second maximum
return secondMax;
}
I hope this would help.
So if i write out the complete code for a relatively minor program and then copy and paste that into chat-gpt asking it to convert it into readable pseudocode for an assessment, how likely is that to be considered mal-practice?
This is assuming my variables and logic remain consistant in the chat-gpt output. The reason I am asking is because, fair enough getting chat-gpt to write code is not your own work but using chat-gpt to convert my already written work into something else is no different to say using a pdf-converter no?
I understand that if the code works, its already pseudocode - but I would like to make it more readable also. Chances are I wont use it anyway just to be safe, but I was wondering what the ethics would be like.