Welcome, Guest. Please login or register.

October 19, 2019, 05:26:36 am

Author Topic: Algorithm help  (Read 258 times)

0 Members and 1 Guest are viewing this topic.

Seamus Wong

  • Trendsetter
  • **
  • Posts: 112
  • Respect: +11
Algorithm help
« on: January 17, 2019, 01:34:20 pm »
0
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
« Last Edit: January 20, 2019, 05:29:30 pm by Seamus Wong »

calliope

  • Trailblazer
  • *
  • Posts: 33
  • Respect: 0
Re: Algorithm helpp
« Reply #1 on: January 20, 2019, 01:44:52 pm »
+2
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.
   

calliope

  • Trailblazer
  • *
  • Posts: 33
  • Respect: 0
Re: Algorithm helpp
« Reply #2 on: January 20, 2019, 01:50:48 pm »
0
Edgy can be found at the url http://snapapps.github.io/edgy/app/edgy.html

Seamus Wong

  • Trendsetter
  • **
  • Posts: 112
  • Respect: +11
Re: Algorithm helpp
« Reply #3 on: January 20, 2019, 05:29:12 pm »
0
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.





calliope

  • Trailblazer
  • *
  • Posts: 33
  • Respect: 0
Re: Algorithm help
« Reply #4 on: January 20, 2019, 08:31:07 pm »
+1
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

Seamus Wong

  • Trendsetter
  • **
  • Posts: 112
  • Respect: +11
Re: Algorithm help
« Reply #5 on: January 20, 2019, 09:27:04 pm »
0
Thank you for the clarification, I appreciate the help.