Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudo code for topological sort #77

Merged
8 commits merged into from Nov 26, 2019
Merged

Conversation

Ddiog-dev
Copy link
Contributor

@Ddiog-dev Ddiog-dev commented Nov 23, 2019

i used the pseudo code of the khan's algorithm found on wikipedia and i added below the pseudo code a detailled example on how it works.
(https://en.wikipedia.org/wiki/Topological_sorting)
This PR concerns the issue #18

@welcome
Copy link

welcome bot commented Nov 23, 2019

Thanks for opening this pull request! Please check out our contributing guidelines.

@ghost
Copy link

ghost commented Nov 23, 2019

Although the pseudocode is correct, it does not go into the details of how to implement the above algorithm efficiently. (For example, it talks about deleting an edge which takes linear time, and hence the overall algorithm can jump upto O(n^2).) However, in Kahn's Topological Sort, we don't need to delete the edge each time. The workaround for this is to delete a vertex virtually (effectively reducing the indegree). See this implementation for more details. (Line Number 67-99)

Please make the required changes to the pseudocode. Also, do not place it inside the Sorting folder. Place it inside Pseudocode/Graphs/Topological Sorting.

Please do not include binary files (such as images) in your initial pull request. This is because they remain in the history even when you delete it (say, after the code review). This takes up the Repo space. If you want to attach binary files, include them only after the review is over.

Let me know if you need any more clarifications

@Ddiog-dev
Copy link
Contributor Author

Alright, no problems thank you for the feed back, i'm correctiong it right now !

@ghost
Copy link

ghost commented Nov 23, 2019

Also, there's a typo in the name of the image. It's Kahn's

@Ddiog-dev
Copy link
Contributor Author

So i moved the code in the right repositories, i deleted the images in the folder and i modified the pseudo code to match the edge handling in the code you gave me and i also clarified how to initialise the S set with inDegree

@ghost
Copy link

ghost commented Nov 24, 2019

Here are a couple of suggestions to get you acquainted with our coding style

  1. Don't use camelCase in LaTeX. (It looks weird with the rendering). Use underscore_names.

  2. Enclose everything in a function. (See the new file for details on how to do this).

  3. It's ok to leave a blank line in between the algorithm for clarity. Use \Statex for this purpose. See the new file to see it in usage.

  4. As of now, your code describes what to do in plain English. However, the goal of this repo is to write compact pseudocodes. Hence, feel free to use concise statements to express the idea. Use comments to explain non-trivial parts. If you catch yourself writing long comments, explain it after the algorithm instead. (See the Pseudocode for Median in a Stream of Integers for an example. In a nutshell, the pseudocode should be written in such a way that it can easily be converted to code in any language while at the same time acting as a language-independent explanation of the algorithm. See the pseudocodes of CLRS for motivation.

  5. If you need to use a lot of spaces within math-mode, consider using the \textit environment instead.

  6. If you wish, you can use the Ensure and Require field to specify constraints on the input. (See the Gist).

  7. Avoid using ++ as the rendering is not good. (The plus becomes too big).

  8. Include occasional comments using \Comment.

  9. Use Macros such as not empty, is, etc.

  10. I personally prefer For each instead of For all

  11. I've used the hyperref package for coloured links.

@ghost
Copy link

ghost commented Nov 24, 2019

  1. Please go through the above reviews and make sure that you understand each point.

  2. I might have missed a lot of things. You can look out for the others in the new file. Link. Please go through each line and understand the changes made.

  3. After you've gone through the file and understood the changes, overwrite your TEX file with the new file.

  4. Generate a PDF (of the new file) using Overleaf. Name it Topological Sorting.pdf. Place it inside the same folder as SourceCode.tex

  5. Inside the folder where you've placed the source code, create a new folder called Images (notice the capitalization). Upload all your images there.

  6. I've also mentioned some reviews. Read them and click on resolve conversation.

  7. Ping me when you are done.

Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
Pseudocode/Graphs/Topological Sort/SourceCode.tex Outdated Show resolved Hide resolved
@Ddiog-dev
Copy link
Contributor Author

I did the modifications and i added the pdf , tell me when i can push the pictures for the example !

@ghost
Copy link

ghost commented Nov 24, 2019

There are a lot of small details still missing (like Insertion in queue using .push rather than plain English, for each rather than for all , use of adjacency list instead of vaguely talking about edges, .use of underscores rather than camelCase, initialization of indegree array, syntax highlighting of is not empty, typo in the last if, etc.

Since I've already dragged this too much, I'd request you to overwrite your TEX file with my version. You can find it here. And by overwriting, I don't mean Modify your code, just copy paste my code and replace it. I think there was a confusion last time. (I usually provide the full review in the code itself, but since I'm a bit occupied, I decided to create a new version so that you can see the differences yourself)

When you are done, let me know so that I can allow you to upload the final pdf and images.

@Ddiog-dev
Copy link
Contributor Author

Changes done

@ghost
Copy link

ghost commented Nov 25, 2019

Looks good. You can upload the images now. (Create another folder Images inside the directory where sourceCode.tex is placed and place all the images there)

@Ddiog-dev
Copy link
Contributor Author

Done

@ghost
Copy link

ghost commented Nov 26, 2019

Great! Thank you for your contribution to this repository. I hope you got to learn something new from this experience.

@ghost ghost merged commit 103a688 into Just-A-Visitor:master Nov 26, 2019
@welcome
Copy link

welcome bot commented Nov 26, 2019

Congrats on merging your first pull request! We here at behaviorbot are proud of you!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant