Recursion is simply a function that calls itself. Common sense says this creates a loop, so why use it?
: It uses a hands-on approach with examples in multiple languages, including JavaScript . Specialized editions focused entirely on are also available. Visual Aids
| If you need to... | Use this... | Why common sense says so | | :--- | :--- | :--- | | (e.g., user profile) | Hash Table | You don't scan every drawer in your filing cabinet. | | Process items in order (e.g., printer jobs) | Queue | First come, first served. Fairness. | | Undo an action (e.g., Ctrl+Z) | Stack | The last thing you did is the first thing you want to undo. | | Find something in a sorted list | Binary Search | You don't read a dictionary page by page. | | Store a list that changes size constantly | Linked List | Easier to add/remove without shuffling everything. |
The relationship between the two is symbiotic. A great recipe (algorithm) is useless if your ingredients (data) are stored in a disorganized mess. Conversely, a perfectly organized pantry (data structure) won't cook the meal for you. To write good software, you need the right storage for the job, and the right recipe to use it.
Big O measures scalability . Ask yourself: If my data doubles, does my time double? Stay the same? Explode?
Code is just language. Structure is just logic. Algorithms are just recipes. And you’ve been using all three since you learned how to tie your shoes.
If you want to use binary search, you must sort first. Here are the only two sorts you need to know about as a beginner: