ATAR Notes: Forum
VCE Stuff => VCE Technology => VCE Mathematics/Science/Technology => VCE Subjects + Help => VCE Algorithmics => Topic started by: Seamus Wong on January 17, 2019, 01:34:20 pm
-
Hey Guys,
I'm new to Algorithmics and I was just wondering if someone could let me know if the algorithm I've created has been constructed correctly.
The algorithm is designed to create a tree for finding permutations for a given number of letters.
The algorithm I've create uses an iterative approach (I think...).
Here it is:
Algorithm Permute (Letters)
Repeat
for i from 1 to Len(Letters)
create node U with Label (Letters)
create node V with Label (Letters - i)
create edge U-V with label i
Letters:=Letters - i
end do
Until Len(Node.Label) = 1
I'm not really sure as to whether this make any sense to anyone reading it, so please let me know.
Thanks
-
Hi Seamus, in your algorithm you need to make it clear what "Letters" represents and how. Is it an array? list?
Is it an array of Letters? For example "DOG" can be put into a 3 element array/matrix Letters[1]="D", Letters[2]="O", Letters[3]="G".
Or Letters can be a list structure for example Letters={"D","O","G"}
The for loop make sense for array and list structures, I don't think the outer repeat loop will work in all cases, it is assuming something about the nature of Letters that there will be a node with "1".
Permute in Edgy using Letters as an array may look like the attached. The Graph nodes colour is being used to keep track of the leaf nodes and it is assumed that the Letters to permute don't have any repeated letters.
-
Edgy can be found at the url http://snapapps.github.io/edgy/app/edgy.html
-
Hello Calliope,
Thank you for the help. Yes, Letters was intended to be a list of letters inputed by the user. Could you please show me how to make this clear in my algorithm? would I just write:
Algorithm Permute(InputList: Letters) ?
The node with "1" is referring to the length of the label of the node, in that once the final leaf node has been created, containing the final letter, the label of that final node will only contain one letter, and thus the Algorithm would stop.
-
Yes that will work as it informs the reader what the structure of Letters is. There are many styles of pseudocode.
Here's a oseudocode example from https://www.geeksforgeeks.org/difference-between-algorithm-pseudocode-and-program/ where the name of the input is descriptive.
FUNCTION linearSearch(list, searchTerm):
FOR index FROM 0 -> length(list):
IF list[index] == searchTerm THEN
RETURN index
ENDIF
ENDLOOP
RETURN -1
END FUNCTION
-
Thank you for the clarification, I appreciate the help.