Just-A-Visitor / Algorithmic-Pseudocode

This repository contains the pseudocode(pdf) of various algorithms and data structures necessary for Interview Preparation and Competitive Coding
GNU General Public License v3.0
762 stars 167 forks source link

Pseudo code for topological sort #77

Closed Ddiog-dev closed 4 years ago

Ddiog-dev commented 4 years ago

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[bot] commented 4 years ago

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

ghost commented 4 years ago

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 commented 4 years ago

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

ghost commented 4 years ago

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

Ddiog-dev commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.

6) Ping me when you are done.

Ddiog-dev commented 4 years ago

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

ghost commented 4 years ago

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 commented 4 years ago

Changes done

ghost commented 4 years ago

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 commented 4 years ago

Done

ghost commented 4 years ago

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

welcome[bot] commented 4 years ago

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