I recently started in-depth learning Data Structures and Algorithms (DSA) and all I can say is it is tough, but I am actually getting the hang of different concepts. Going through different concepts of DSA reminded me of a conversation I had with a friend on why I thought this was nerve-wracking.
The conversation started off with a use case question on DSA based on a tray of eggs that needed to be taken from point a to point b. My answer was to take the tray of eggs from point a to point b. Clearly, my answer was ignorant of all factors involved in taking the eggs to point b from point a.
What I did not do, was ask questions like:
-
Was the tray empty?
-
What number of eggs were in the tray?
-What if on moving the tray, I tripped and a few of the eggs fell and broke?
- How long I would take to carry the eggs to point b?
If I asked the right questions I would be able to account for different situations.
What I learned from the conversation was that DSA is about asking the right questions and accounting for different use cases, especially edge cases.
Edge cases are situations where the inputs or outputs are out of what was originally planned. To exemplify, if you write an algorithm that removes duplicates from a list but does not account for null values then your code will break whenever there are null values present.