

Standard Algorithms
#1
Posted 26 May 2006 - 11:20 AM
Cheers,
Mike
#2
Posted 26 May 2006 - 12:11 PM
Counting occurrences:
Pseudocode:
Set the current position in the array to 0
Set the current number of occurrences to 0
While the current position is less than the number of array elements
Check if the current element equals the value we are looking for
If it is, increment occurrences by 1
End while
Number of occurrences is left in the occurrences variable

C example:
int CountOccurrences(int * array, int ElementCount, int NumberToFind)
{
int position = 0, occurrences = 0;
for(;position<ElementCount;position++)
{
if(array[position]==NumberToFind)
occurrences++;
}
return occurrences;
}
Find max:
Set the current maximum to the value of the first element
Starting at the 2nd element, loop through all elements and check
on each iteration for the current element being larger in value than the current maximum, and if it is, set the current maximum to that value
int FindMax(int * array, int ElementCount)
{
int CurrentMax, position = 1;
if(ElementCount > 1)
CurrentMax = *array;
else
return 0;
for(;position<ElementCount;position++)
{
if(array[position] > CurrentMax)
CurrentMax = array[position];
}
return CurrentMax;
}
Find min:
Same as find max, except you compare values to find if the current element is smaller...
Hrm, I'm not sure about my Find Max/Min algos. Certainly that's how I'd code it, and it works, but I can't remember what the "official" answer is.
<@X-Factor> Wouldnt you be breaking the first 2 rules?

#3
Posted 26 May 2006 - 12:13 PM
Finding min
Set first to lowest in list
repeat
if next in list<min
make min = next in list
found_at=counter
until end of list
write minimum
Finding Max
same as above but change min to max, and < into>
Counting Occurences
target = 'random'
counter = 0
repeat
if next in value = targer
then counter = counter + 1
until end of list
if counter = 0 write'not found' (<<<<<<<<<<<<<<<<<<<linear search up to here)
write counter
I think thats what you wanted

EDIT: just typed that for nothing, lol
#4
Posted 26 May 2006 - 02:07 PM
public class repeat {
public static void main(String[] args) {
String target = "one";
int i =0;
String [] data = {"one", "two", "three"}; //declares an array as a type string with 3 elements in it
for(i=0; i<data.length; i++){ // iterates over the following code
if(data[i].equals(target)){
System.out.println("Target found " + data[i]);
i = data.length;
}
else{ System.out.println("Target not found");
}
}
}
}
Obviously usually the target is specified by the user. I have omitted it for simplicity here as reading input in Java requires exception handling to read input from a user. The linear search can be adapted to any situation and in the examination you will be expected to write the algorithm in pseudocode. An array was used in the above example but a linked list would probably more common if there is no way of knowing how much data was needed to search through.
#5
Posted 26 May 2006 - 02:08 PM

#6
Posted 27 May 2006 - 12:47 PM
Anyway here it is in Pseudocode(My Pseudocode skills aren't great btw)
1. Set Search Value to X and Found to False
2. Set Loop Size to Array Size
3. Compare Array(Loop) to Search Value
4. If Array(loop) = Search Value Goto Line 7
5. Else Increment Loop by 1
6. Goto Line 3
7. Set Found = True, and Display message
I would also recommend sticking to Pseudocode, as the examiner maynot know Java, C, C++, or whatever language you may want to use.
#7
Posted 27 May 2006 - 12:54 PM
#9
Posted 27 May 2006 - 01:10 PM
If i am not here i am somewhere else
#10
Posted 27 May 2006 - 01:16 PM
#11
Posted 27 May 2006 - 01:19 PM
Description and exemplification of the following standard algorithms in pseudocode and an appropriate high level language:
linear search
counting occurrences
finding min/max
If i am not here i am somewhere else
#12
Posted 27 May 2006 - 01:25 PM
It just changed this year, its basically the same though. They probably have just taken a few things out rather than add anything new.
It changed lat year, but was a dual running.
i tihnk the new course was to add content in rather than take it out. This is from the arrangements document
Description and exemplification of the following standard algorithms in pseudocode and an appropriate high level language:
linear search
counting occurrences
finding min/max
They have added and removed things.
Some of the Programming unit is now in the AH and Software Dev unit, and alot has been added to the Networking unit.
#13
Posted 27 May 2006 - 01:36 PM

Does anyone have a list of the programming languages and features of each I should know about for higher?
#14
Posted 27 May 2006 - 01:40 PM
Visual Basic - event driven,
Java, C#,J# - object orientated
Prolog - declaritive, AI
php, VB script, javascript - scripting language
If i am not here i am somewhere else
#15
Posted 27 May 2006 - 02:36 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users