Shortest Path Algorithm with Python: Suggestions to improve the learning experience

Scientific Computing with Python

Learn Algorithm Design by Building a Shortest Path Algorithm

REPORT WITH SUGGESTIONS TO IMPROVE THE LEARNING EXPERIENCE:

In many steps of this fifth course using Python, when the task is assigned, it is assumed that we already know about things that have in fact not been presented yet. I made a summary of my impressions regarding this. I have also written suggestions that may help you deal with these gaps, if you are willing to improve the course. I hope this may help you to offer future students a better learning experience.

Introduction. Given the complexity of the algorithm and the fact that there are in the literature a number of different shortest-path algorithms, I suggest that you present in the introduction the flowchart of the shortest-path algorithm that is used in this course. I sketched it and this is the link:

	The algorithm represented by the diagram does not include the operations corresponding to the nested "if" and "else" conditions of the code (Steps 40-42). I've tested and seen that the code works well when we erase the nested "if" and "else" statements and replace them by the statement paths[node] = paths[current][:] alone. In fact, the operation performed by the nested "if" clause has the same algorithmic effect as the operation performed by the nested "else" clause. I assume that the nested conditions are only useful for computer-operational reasons, like saving memory.

Step 31. This step uses two previously introduced functionalities combined in one syntatic formation. The first functionality is the one introduced in Step 8, by which a key’s value can be changed. The other is the .append() method, which here is used to change the key’s value. This can be performed because the value type is, in this case, a list.

name_of_dictionary[key_to_the_value-list].append(item_to_be_appended)

It would be interesting to point out that the value (i.e., the list) that is to be changed (i.e., appended to) does not appear in the syntax. Instead, it is addressed by the key to which it is related.

I would suggest that this step be divided into two, so that the use of each functionality is more clearly presented and tasks can be performed without students getting stuck.

Step 33. The only overall description of the algorithm that is given, is given in this step. It’s very brief and probably not sufficient for the most part of beginners in programming. I have suggested the flowchart in the Introduction.

Step 34. This step assumes we know how to create a loop that runs while there are items in a list. We could find the solution if we knew that a list will, when prompted, return the True boolean value, except when it is empty, in which case it returns False.

Steps 35-36. These steps bring five new concepts, and just two of them are introduced:

1. The min() function is introduced in Step 35;
2. A key function can be inserted in the argument of another function;
3. The min() function can take a key parameter;
4. The .get() method is introduced in Step 36;
5. Sometimes, the empty parenthesis () can be omitted, allowing for an abbreviated syntax.

I suggest that Step 36 be divided into two steps, so that the key function/parameter functionality inside the argument of the min() function can be introduced and explained in one step, and the .get() method, with its abbreviated syntax, in the next.

Steps 40-42. As highlighted above, in the comment on the Introduction, I suggest that the nested “if” statements built along these steps be implemented further down in the development of the code. Here, what needs to be placed is just the paths[node] = paths[current] statement, without the nested conditions.

Step 44. The .remove() method must be used to perform the task, but is not introduced or explained. I suggest that it be.

Step 45. The “and” operator must be used to perform the task, but is not introduced or explained. I suggest that it be. I would also like to comment that, like in Step 34, the boolean value for a list is used to perform the task.

Step 47. The slicing functionality and its abbreviated form [:] must be used to perform the task, but are not introduced or explained. I suggest that they be.

1 Like

https://drive.google.com/file/d/1jOADhOxzhxO97Akl4EOaBGIiIGA0KZc9/view?usp=drive_link

HI @72fahrenheit !

Thank you for your feedback.

Can you open up an issue here with your feedback?

That way, the python team will be able to look at it and triage it from there.

Thanks!

1 Like

There is a new version of the Shortest Path coming out soon, maybe you can take a look at the new version? You can see it if you build freeCodeCamp locally from the GitHub repository, or it will be made live in the next few days.

1 Like

@jwilkins.oboe Hi Jessica, I am back to this code camp after six months away because of other projects. Thank you very much for your suggestion. It motivated me to create a profile in GitHub, learn the basics and start collaborating. I have reviewed and updated my report on this Python Challenge, and created an issue. I also used the Markdown “task list” functionality so that the work can be divided and distributed to collaborators. I think the shortest-path challenge is a really special one. It shows the power of an ingenious algorithm and the construction of a very effective code. It has therefore a great didactic potential and I hope to help improve the Challenge in that direction. Best regards!!

1 Like