<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kartik Sharma</title>
    <description>The latest articles on Forem by Kartik Sharma (@kartikdevsharma).</description>
    <link>https://forem.com/kartikdevsharma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1659942%2Fee5e61f4-a1f8-4552-ad39-b87bcf1cefb9.png</url>
      <title>Forem: Kartik Sharma</title>
      <link>https://forem.com/kartikdevsharma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kartikdevsharma"/>
    <language>en</language>
    <item>
      <title>How To prepare For DSA</title>
      <dc:creator>Kartik Sharma</dc:creator>
      <pubDate>Thu, 27 Feb 2025 11:44:36 +0000</pubDate>
      <link>https://forem.com/kartikdevsharma/how-to-prepare-for-dsa-i8f</link>
      <guid>https://forem.com/kartikdevsharma/how-to-prepare-for-dsa-i8f</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;strong&gt;Learning Methodology&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Approach 1: Structured Course-Based Learning&lt;/strong&gt; – &lt;em&gt;Follow a curriculum (like a university or MOOC course) covering DSA topics systematically, combined with active recall and spaced repetition.&lt;/em&gt; This approach involves learning fundamentals in a logical order (arrays → linked lists → trees → algorithms, etc.), taking notes, and reinforcing knowledge with flashcards and periodic review (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=2,For%20example"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;) (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Timeline &amp;amp; Milestones:&lt;/strong&gt; Typically requires ~3+ months of consistent study (10–20 hours/week) to cover core topics (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=As%20someone%20who%20has%20a,in%20per%20week%2C%20the%20better" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;) (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=learn%20them%20should%20be%20prepared,in%20per%20week%2C%20the%20better" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). Milestones can be set by module (e.g. finish array/list basics by week 2, trees/graphs by week 8, all topics by week 12).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recommended Resources:&lt;/strong&gt; University-style courses (Coursera’s &lt;em&gt;Algorithms&lt;/em&gt; by Princeton or UCSD specialization) provide structure (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,Data%20Structures%20%26%20Algorithms%2C%20Udacity"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). UC Berkeley’s CS61B (Data Structures, Java) and MIT 6.006 (Algorithms) lectures on YouTube offer rigorous content. Udacity’s free &lt;strong&gt;Data Structures &amp;amp; Algorithms&lt;/strong&gt; course and Coursera’s Stanford Algorithms series are also excellent (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,Data%20Structures%20%26%20Algorithms%2C%20Udacity"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Video lectures by professors (e.g. Tim Roughgarden’s Coursera algorithms) build theoretical understanding, while platforms like &lt;em&gt;interactivepython.org&lt;/em&gt; teach DSA in Python with hands-on examples (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=There%20are%20only%20two%20online,can%20recommend%20for%20learning%20DS%26A" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Comprehensive and systematic – ensures no major topic is missed. Deep understanding of theory and correct techniques (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=And%20while%20MOOCs%20on%20each,lack%20of%20time%20and%2For%20resources" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). Structured timeline keeps progress on track. Active recall techniques (flashcards, quizzes) can solidify long-term memory (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Slower to get hands-on; risk of “tutorial hell” if not coupled with practice. Requires discipline to follow through a lengthy curriculum. Some courses can be dense or math-heavy (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=,math%2C%20calculus%201%2C%20and%20probability" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;), which might overwhelm beginners.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal For:&lt;/strong&gt; Self-learners who prefer guided learning or those with enough time to dedicate. Great for people who want a strong foundation (e.g. understanding &lt;em&gt;why&lt;/em&gt; an algorithm works, not just how). If you learn best from lectures and reading, this approach works well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Approach 2: Problem-Driven Learning (LeetCode-first)&lt;/strong&gt; – &lt;em&gt;Learn DSA by solving problems directly, referring to theory as needed.&lt;/em&gt; In this approach, you “learn by doing” – pick a coding challenge, attempt it, and research the data structure or algorithm to fill knowledge gaps. Over time, patterns emerge (two-pointer, divide-and-conquer, etc.) and you cover topics organically (&lt;a href="https://dev.to/sakshamceo/week-wise-data-structures-and-algorithms-schedule-for-placements-part-2-1i0d#:~:text=2,can%20learn%20them%20as%20well"&gt;Week Wise Data Structures and Algorithms Schedule for Placements. (Part-2) - DEV Community&lt;/a&gt;). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Methodology:&lt;/strong&gt; Tackle problems topic-by-topic or via curated lists (e.g. the &lt;strong&gt;Blind 75&lt;/strong&gt; or &lt;em&gt;Grind 75&lt;/em&gt; questions). For example, solve array problems for a week, then linked list problems, etc., learning the underlying concepts as you go. Use LeetCode’s topic tags or sites like A2OJ (for topic-wise practice) to select problems (&lt;a href="https://dev.to/sakshamceo/week-wise-data-structures-and-algorithms-schedule-for-placements-part-2-1i0d#:~:text=practice%20questions,and%20Long%20Contests%20on%20Codechef"&gt;Week Wise Data Structures and Algorithms Schedule for Placements. (Part-2) - DEV Community&lt;/a&gt;). If stuck &amp;gt;30 minutes, read discussions or editorials to understand the solution, then retry similar problems to reinforce. Maintain notes of patterns (sliding window, BFS, DP states) and revisit them periodically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Estimated Timeline:&lt;/strong&gt; Can be flexible; one strategy is a 4–8 week intensive practice: e.g. Week 1–2 arrays &amp;amp; strings, Week 3 linked lists &amp;amp; stacks, etc., with daily problem goals. Fast-track schedules exist (even 4–6 weeks for experienced folks), but generally ~2–3 months is recommended for thorough coverage (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=match%20at%20L1250%20months%20,More" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=months%20,More" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). Milestones are number of problems solved or completion of a topic’s problem set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources:&lt;/strong&gt; &lt;em&gt;NeetCode&lt;/em&gt; (YouTube) offers step-by-step video solutions for popular problems, which is invaluable when learning patterns (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=2,you%20plan%20to%20grind%20LeetCode"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). The &lt;em&gt;Blind 75 list&lt;/em&gt; (or Grind 75 tool) gives a structured set of interview-style problems spread over ~5 weeks (75 problems) covering all key topics (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%205" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%205" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). LeetCode itself provides topic-wise question lists and company-tagged questions. Books like &lt;em&gt;Cracking the Coding Interview&lt;/em&gt; (though book-based, it’s problem-focused) can guide practice. For explanations, YouTube channels (e.g. &lt;strong&gt;take U forward&lt;/strong&gt; and &lt;strong&gt;Abdul Bari&lt;/strong&gt;) break down complex problems visually (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=1,III%20%40Google"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;) (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=3,channel%20link%3A%20Abdul%20bari"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Highly practical – you develop problem-solving skills and intuition quickly. Immediate application reinforces learning; solving a variety of problems helps retention through &lt;em&gt;active problem recall&lt;/em&gt;. Efficient for interview prep since it mimics the interview process directly (given a problem, devise an approach) (&lt;a href="https://www.designgurus.io/answers/detail/is-leetcode-competitive-coding#:~:text=,dealing%20with%20edge%20cases%20or" rel="noopener noreferrer"&gt;Is LeetCode competitive coding?&lt;/a&gt;) (&lt;a href="https://www.designgurus.io/answers/detail/is-leetcode-competitive-coding#:~:text=,titles%20in%20competitive%20coding%20events" rel="noopener noreferrer"&gt;Is LeetCode competitive coding?&lt;/a&gt;). You also get used to coding in your chosen language under constraints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Risk of patchy knowledge – you might skip or miss fundamental concepts that don’t appear in the problems you randomly choose. It can be frustrating for true beginners to dive into problems without any theoretical background (hitting a wall repeatedly). Without structure, there’s a chance of focusing only on familiar problem types and neglecting others. Requires discipline to review the theory behind solutions (to avoid just memorizing solutions).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal For:&lt;/strong&gt; Those preparing for technical interviews on a tighter timeline, or people who learn best by doing. If you already have basic programming experience, this approach keeps motivation high (little theory before seeing results). Ensure you complement it with brief study of underlying concepts when you encounter new topics to avoid shallow understanding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Approach 3: Project-Based and Practical Implementation&lt;/strong&gt; – &lt;em&gt;Build small projects or implement data structures from scratch to learn by application.&lt;/em&gt; In this approach, you create tangible outputs using DSA – e.g. building your own library of data structures, or apps like a &lt;strong&gt;task scheduler (uses heaps)&lt;/strong&gt; or a &lt;strong&gt;navigation system (uses graphs)&lt;/strong&gt; – to see how DS&amp;amp;A apply in real scenarios. This “learn by building” method cements concepts by putting them in a real-world context (&lt;a href="https://levelup.gitconnected.com/how-to-master-algorithms-and-data-structures-without-burning-your-brain-e3d21a64ff56#:~:text=Entrepreneurial%20ambition%20means%20asking%20yourself,one%20question%20every%20day" rel="noopener noreferrer"&gt;How to Master Algorithms and Data Structures without Burning Your Brain | by Pen Magnet | Level Up Coding&lt;/a&gt;) (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=Understanding%20how%20data%20structures%20and,boost%20motivation%20and%20provide%20context" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Methodology:&lt;/strong&gt; After learning a concept, implement it in a project. For example, after studying hashing, you might build a simple cache (LRU cache uses a hash map + linked list). After learning graphs, you could build a mini social network graph and implement friend suggestions (graph traversal). Writing your own versions of data structures (like coding a linked list, stack, queue, binary tree class, etc.) is a core part – this low-level implementation experience clarifies how operations and memory management work (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=,the%20underlying%20principles%20and%20patterns" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;). Projects can also be algorithmic games (e.g. writing a sudoku solver uses backtracking, a pathfinder uses A* algorithm). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeline:&lt;/strong&gt; Project-based learning can be open-ended. A structured plan might allocate 1–2 weeks per major structure or algorithm: e.g. implement and test basic DS in the first month, then algorithmic projects in the second. Milestones are project completions: &lt;em&gt;By Week 4&lt;/em&gt;, have a mini “Data Structure library” coded (with an array list, linked list, stack, queue, hash map); &lt;em&gt;By Week 6–8&lt;/em&gt;, build one or two algorithmic applications (like a sorting visualizer or a shortest-path finder). This can also be interleaved with solving practice problems to verify your implementations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Video Resources:&lt;/strong&gt; Some YouTube playlists focus on building projects with algorithms (for example, &lt;strong&gt;William Fiset’s&lt;/strong&gt; channel covers implementing Fenwick Trees, Union-Find, etc., in code). The freeCodeCamp.org channel’s &lt;em&gt;8-hour DSA course&lt;/em&gt; builds up from scratch in Python. &lt;strong&gt;MyCodeSchool&lt;/strong&gt; (YouTube) – though older – has clear videos coding out linked lists, trees, etc., step by step. Search for “[Data Structure] implementation in [language]” – e.g. &lt;em&gt;“Implement Trie Python”&lt;/em&gt; – to find tutorials. Project tutorials (like “build a search engine in Python”) also inherently teach algorithms (indexing, parsing, sorting).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Connects theory to practice – seeing how data structures operate in a larger program improves understanding and retention (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=Understanding%20how%20data%20structures%20and,boost%20motivation%20and%20provide%20context" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;). You gain debugging skills and a deeper appreciation of complexity (e.g. realizing why a naive approach is slow when your project lags). It’s motivating to have something tangible (like a working app) rather than just abstract problems. Also, writing your own implementations solidifies how data structures work behind the scenes (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=,the%20underlying%20principles%20and%20patterns" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Building projects is time-consuming; you might cover fewer algorithmic problem patterns compared to solving many LeetCode questions. Projects may not expose you to the &lt;em&gt;trickiest&lt;/em&gt; interview puzzles (which often involve edge-case problem solving more than building systems). There’s a risk of focusing more on the application domain than the algorithm (for instance, spending time on web UI or unrelated aspects). It’s less directed towards typical interview question styles (which are usually stand-alone problems, not building a system).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal For:&lt;/strong&gt; Learners who get bored with rote problem solving and need real-world context to stay engaged. Also great as a supplementary method for those who want to &lt;strong&gt;retain concepts long-term&lt;/strong&gt; – applying DS&amp;amp;A in different contexts reinforces memory. If you have more than 3–4 months and are aiming for a holistic understanding (not just interviews), this approach pays off. It’s also well-suited for those who want to see &lt;em&gt;practical use cases&lt;/em&gt; of algorithms (e.g. using BFS for solving puzzles, using heaps in scheduling).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Approach 4: Competitive Programming Practice&lt;/strong&gt; – &lt;em&gt;Train with competitive programming problems and contests (e.g. Codeforces, TopCoder) to develop strong algorithmic skills.&lt;/em&gt; This approach treats DSA learning like sport – you regularly solve timed, challenging problems which often require inventive uses of data structures and advanced algorithms under constraints (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=,hone%20their%20competitive%20programming%20skills" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;) (&lt;a href="https://www.designgurus.io/answers/detail/is-leetcode-competitive-coding#:~:text=,dealing%20with%20edge%20cases%20or" rel="noopener noreferrer"&gt;Is LeetCode competitive coding?&lt;/a&gt;). Over time, this can make interview questions feel easy by comparison.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learning Style:&lt;/strong&gt; Join online contests (Codeforces rounds, LeetCode weekly contests, etc.) or use archives of contest problems. Tackle problems that push you beyond typical interview fare – e.g. more complex graph theory (flows, bridges), advanced dynamic programming, bitmask DP, etc. After each contest or problem, thoroughly &lt;strong&gt;upsolve&lt;/strong&gt;: read top solutions, analyze what you could do better, and implement the new techniques learned (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=focused%20on%20solving%20problems%20efficiently,hone%20their%20competitive%20programming%20skills" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;) (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=If%20you%27re%20aiming%20to%20improve,constrained%20problems" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;). This approach emphasizes &lt;strong&gt;problem-solving speed and efficiency&lt;/strong&gt;: you learn to think under pressure, optimize code, and handle edge cases quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeline:&lt;/strong&gt; Competitive programming is a long-term approach. A focused plan might be: first 4–6 weeks on mastering basics (if not already known) because contests assume knowledge of standard algorithms. Then, dedicate time to 1–2 contests per week or a set of unsolved contest problems daily. Milestones could be improving contest rating or being able to solve, say, at least 2 problems from each contest within time. In ~8–12 weeks of consistent practice, one can see significant improvement in thinking and speed (though truly mastering CP for national/international contests can take much longer).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources:&lt;/strong&gt; &lt;strong&gt;Codeforces&lt;/strong&gt; and &lt;strong&gt;AtCoder&lt;/strong&gt; are top for contests – Codeforces has a problem archive sortable by difficulty, and AtCoder has high-quality tasks for all levels (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;) (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=,competing%20in%20international%20coding%20competitions" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;). For learning algorithms, competitive programming blogs (e.g. cp-algorithms.com) and YouTube channels like &lt;strong&gt;Errichto&lt;/strong&gt; and &lt;strong&gt;William Lin&lt;/strong&gt; offer tutorials on common contest topics. There are also CP-focused courses (e.g. &lt;em&gt;CodeChef’s DSA learning series&lt;/em&gt; (&lt;a href="https://dev.to/sakshamceo/week-wise-data-structures-and-algorithms-schedule-for-placements-part-2-1i0d#:~:text=Short%20contests%20on%20Codeforces%20and,Long%20Contests%20on%20Codechef"&gt;Week Wise Data Structures and Algorithms Schedule for Placements. (Part-2) - DEV Community&lt;/a&gt;)). Video editorials for contest problems (on YouTube) can help – e.g. Gaurav Sen for certain algorithms or SecondThread channel. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Develops &lt;em&gt;fast thinking&lt;/em&gt; and mastery of algorithms – after solving a Codeforces “hard”, any typical interview question will feel straightforward. You get very comfortable with edge cases, math tricks, and optimization, which can give you a unique edge in interviews. It also builds endurance for marathon problem-solving (useful if you have to do long interviews or multiple rounds in a day). Another benefit: you often learn multiple ways to solve a problem (greedy vs DP vs BFS) and pick the best – a skill useful in interviews when you need the optimal solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Many competitive programming problems go beyond what’s asked in interviews (e.g. segment trees, bitset optimizations, computational geometry). You might spend time on topics that never come up in a typical software engineering interview. There’s a danger of focusing too much on speed and code golf, whereas interviews also care about clear communication and design thinking. If interviews are near, CP could be overkill; solving extremely hard puzzles might not yield proportional benefits for a normal coding interview. It can also be intimidating for beginners due to steep learning curve.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal For:&lt;/strong&gt; Those who enjoy challenges and possibly already have a grasp of basics. If you have ample time (6+ months) or are preparing for top-tier companies that sometimes ask harder questions, this can be a great differentiator. It’s also ideal if you plan to participate in coding competitions anyway or want to strengthen your algorithmic intuition to an expert level. (Many successful interviewees use a &lt;strong&gt;mixed strategy&lt;/strong&gt;: moderate LeetCode practice plus a bit of Codeforces to push their limits.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Approach 5: Guided Bootcamps or Structured Programs&lt;/strong&gt; – &lt;em&gt;Use a structured program or schedule (bootcamp, online course with mentor, or a well-known study plan) to stay on track.&lt;/em&gt; This approach provides external structure and sometimes community support, helping those who benefit from guided progress and accountability. Examples include enrolling in a &lt;strong&gt;coding interview bootcamp&lt;/strong&gt;, following a popular GitHub guide (&lt;em&gt;Coding Interview University&lt;/em&gt;), or using an interactive course like Educative’s &lt;em&gt;Grokking the Coding Interview&lt;/em&gt; (pattern-based learning).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learning Style:&lt;/strong&gt; You adhere to a predefined schedule. For instance, a 8-week bootcamp might assign topics and problem sets each week, with instructors reviewing solutions. Some programs mix live instruction with homework, others are self-paced but structured (e.g. a daily task list). Many emphasize pattern recognition – e.g. Grokking the Coding Interview teaches 16 patterns (two-pointer, merge intervals, etc.) and gives problems for each pattern, providing a very organized way to learn problem-solving techniques. Similarly, the popular &lt;strong&gt;“Cracking the Coding Interview”&lt;/strong&gt; book can be treated as a program: e.g. read one chapter a week and solve its problem list. The key is the structure: you know what to study each day/week.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeline &amp;amp; Milestones:&lt;/strong&gt; Bootcamps often run 4 to 12 weeks. If self-guided, you can follow a schedule like the &lt;strong&gt;Tech Interview Handbook’s 3-month plan&lt;/strong&gt; which breaks down topics per week (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=match%20at%20L1250%20months%20,More" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%201,and%20practice" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (e.g. Week 1: arrays &amp;amp; linked lists, Week 2: stacks/queues &amp;amp; sorting, etc.). Weekly goals are set (cover X topics, solve Y problems). Many structured plans recommend ~3 months for comprehensive prep (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=months%20,More" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), but there are also accelerated plans (e.g. 4-6 week crash courses, though intense).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources:&lt;/strong&gt; Paid bootcamps (e.g. &lt;em&gt;AlgoExpert’s&lt;/em&gt; system or interview coaching programs) offer video lessons + curated problems. Educative.io’s &lt;em&gt;Grokking&lt;/em&gt; courses (for patterns and system design) are text-based but very structured. Free resources include the &lt;strong&gt;Github “Interview University” roadmap&lt;/strong&gt; and the &lt;strong&gt;Tech Interview Handbook&lt;/strong&gt; which provides a week-by-week guide and curated question list (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%201,and%20practice" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%205" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). For video, some YouTube channels (like &lt;em&gt;takeUforward&lt;/em&gt;) have structured playlists – e.g. a 45-video DSA series in C++ covering from basics to advanced in order. Platforms like &lt;em&gt;Masterschool&lt;/em&gt; or &lt;em&gt;Scaler&lt;/em&gt; (in some regions) provide a curriculum and mentors (usually paid). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Clear roadmap – you always know what to focus on, which prevents the paralysis of deciding what to study next. Mentorship or community (if available) can help answer questions and keep motivation high. Structured repetition is often built-in (e.g. many plans include periodic review weeks or mixed-topic mock tests). It’s efficient in that it’s designed by experienced educators to cover “what matters most” for interviews, often including behavioral prep and system design if it’s a complete program.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Less flexibility – you might feel the pace is too fast or slow in parts, but you’re following a preset plan. Quality varies: some paid programs are excellent, others just give you what you could get free. Following a script can be passive unless you stay proactive in truly understanding each topic. Also, pattern-based learning (like memorizing patterns) can backfire if you don’t also learn to &lt;strong&gt;derive&lt;/strong&gt; solutions (interviewers can tell if you’ve merely memorized solutions). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal For:&lt;/strong&gt; People who benefit from external structure – if you’ve struggled to maintain consistency on your own, a bootcamp or published plan can impose discipline. Also great if you have limited time and want to &lt;strong&gt;optimize for the highest-yield topics&lt;/strong&gt; – a well-crafted schedule can direct your energy to what’s most important for interviews. It’s also useful for those who want a blend of learning styles (videos, readings, assignments) in one package.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Long-Term Retention Techniques for DSA&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;No matter which approach you choose, employing proven learning techniques will improve retention of DSA concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spaced Repetition:&lt;/strong&gt; Don’t just cram algorithms once – revisit them over increasing intervals (days, weeks). For example, after learning binary search, review it the next day, next week, and a month later. Using flashcards (Anki or Quizlet) for formulas, definitions, or even pseudocode can be very effective. Research shows you must &lt;strong&gt;spaced-repetition&lt;/strong&gt; for knowledge to move from short-term to long-term memory (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). One strategy is to maintain an “algorithm flashcard deck” – e.g. cards for “What is the time complexity of quicksort?” or “In-order traversal recursion vs iteration”. Test yourself regularly (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=safely%20stored%20in%20your%20LTM,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Several open-source flashcard sets (e.g. &lt;em&gt;Algodeck&lt;/em&gt; (&lt;a href="https://github.com/teivah/algodeck#:~:text=teivah%2Falgodeck%3A%20An%20Open,structures%20and%20system%20design%20interviews" rel="noopener noreferrer"&gt;teivah/algodeck: An Open-Source Collection of Flash Cards ... - GitHub&lt;/a&gt;)) exist for DSA. Spaced review of problems is also key: if you solved a tricky problem, attempt it again after a few days, then again after a few weeks to ensure you still recall the approach.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Active Recall and Teach-Back:&lt;/strong&gt; Simply reading or watching solutions leads to an &lt;em&gt;illusion of competence&lt;/em&gt; (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=guarantee%20that%20you%27ll%20learn%20it"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Instead, after studying a concept, close the book and recite or write down the key points from memory (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Explain the merge sort algorithm aloud as if teaching an empty room or a friend – this “Feynman technique” exposes gaps in your understanding. Some learners maintain a notebook where they attempt to write out, from memory, important algorithms (like BFS, Dijkstra’s, DFS recursive template) or their properties (like “balanced BST conditions”). Recalling and explaining strengthens memory pathways much more than passive review (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). If you struggle to recall, that’s your cue to study that topic again. Consider writing blog posts or short summaries of what you learn each week – producing this output forces you to actively retrieve and organize knowledge, which aids retention.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deliberate Practice of Weak Areas:&lt;/strong&gt; Identify which topics or problem-types you consistently find hard (e.g. dynamic programming or tree problems) and deliberately focus practice on those until they “click”. It’s uncomfortable, but repeatedly practicing the hardest material leads to mastery (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,on%20the%20material%20you%27re%20learning"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). For instance, if DP is your weakness, spend extra days solely on classic DP questions (knapsack, Fibonacci variants, etc.) and revisit the theory behind them multiple times. Tracking your problem attempts can help – note which problems you couldn’t solve and return to them after some time. This approach combats the tendency to keep practicing only what you’re already good at.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Chunking and Concept Maps:&lt;/strong&gt; Organize knowledge into chunks and relationships (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=Increase%20your%20knowledge%20base%20%26,apply%20it%20creatively"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). For example, link related concepts: realize that BFS and DFS are similar graph &lt;em&gt;traversal&lt;/em&gt; chunks; greedy algorithms often use sorting as a sub-routine; a stack can be used to implement DFS, etc. Creating a mental or written concept map of DSA topics can help you see the big picture (how a “divide and conquer” strategy applies to both merge sort and certain DP). When you learn a new algorithm, relate it to ones you know (“Kruskal’s MST is like sorting edges + union-find, which I learned earlier”). By &lt;strong&gt;interleaving&lt;/strong&gt; different topics in practice sessions, you force your brain to recall which technique applies, strengthening your ability to choose the right approach in interviews (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=Increase%20your%20knowledge%20base%20%26,apply%20it%20creatively"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). For example, in one sitting, practice a mix of array, graph, and DP problems rather than all similar ones – this trains recall and application flexibly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Proper Rest and Lifestyle:&lt;/strong&gt; It may sound unrelated, but sleep and breaks are scientifically proven to improve memory consolidation (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,for%20the%20concept%20you%27re%20learning"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). After an intense study session, your brain solidifies that knowledge during sleep. Don’t skimp on sleep, especially before an interview – it strengthens neural pathways for what you learned (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,for%20the%20concept%20you%27re%20learning"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Short breaks during study (Pomodoro technique, etc.) prevent mental fatigue and enhance focus when you return (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=Committing%20material%20from%20your%20Short,by%20using%20the%20Pomodoro%20technique"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). Regular exercise and healthy eating likewise improve cognitive function and memory. Essentially, treat your brain like a muscle: work it out, but give it recovery time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Effective Practice Strategies for Interviews&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Mastering concepts is one side of the coin; &lt;em&gt;practicing&lt;/em&gt; applying them to interview-style questions is equally important. The following strategies blend with the approaches above to specifically hone interview readiness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Targeted Problem Sets (Topic-wise then Mixed):&lt;/strong&gt; A very effective strategy is to do &lt;strong&gt;topic-wise practice&lt;/strong&gt; initially, then switch to mixed topics. For example, after learning &lt;strong&gt;binary trees&lt;/strong&gt;, solve 5–7 tree problems in a row (covering easy to hard) to reinforce that topic. Do this for each major topic (arrays, linked lists, DP, etc.). This builds confidence in each area. Then, as the interview approaches, practice random sets of problems (like a real interview) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,with%20recursion%20%2F%20backtracking%20anyway" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). LeetCode’s &lt;em&gt;Interview Simulator&lt;/em&gt; or &lt;em&gt;random problem&lt;/em&gt; feature can simulate this. The mixed practice ensures you can &lt;em&gt;identify&lt;/em&gt; which technique a new problem requires, a critical interview skill. Many experts suggest completing a curated list of about 50-100 problems that cover all patterns (the “Blind 75” is a popular 75-question list spanning all topics) (&lt;a href="https://www.designgurus.io/blind75/#:~:text=Blind%2075%20Coding%20Questions%20,considered%20crucial%20for%20coding%20interviews" rel="noopener noreferrer"&gt;Blind 75 Coding Questions (with Answers) - Design Gurus&lt;/a&gt;). This ensures breadth. After that, doing random unseen problems improves adaptability. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quality Over Quantity (Analyze Each Problem):&lt;/strong&gt; It’s not just about solving hundreds of problems – &lt;strong&gt;how&lt;/strong&gt; you practice matters. It’s more effective to thoroughly solve and &lt;strong&gt;analyze 50 problems&lt;/strong&gt; than to rush through 150 and barely remember them (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=person%20will%20only%20manage%20to,questions%20they%20have%20practiced%20before" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). For each practice problem, after solving (or reading the solution), spend time understanding alternate solutions and why the optimal approach is better. Discuss with yourself: &lt;em&gt;Why is my solution O(n²) and the optimal O(n log n)? What patterns does this problem use? Could I apply this method to other problems?&lt;/em&gt; Taking notes on key insights (e.g. “Problem X was solved by two-pointer because array was sorted”) creates a personal cheat-sheet of patterns. This reflective approach helps you &lt;em&gt;transfer&lt;/em&gt; solutions to new problems in the future. It also aids retention – you’re less likely to forget a technique you spent time analyzing deeply.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simulate Real Interview Conditions:&lt;/strong&gt; At least 2–3 weeks before your interviews, start simulating the environment. Time yourself strictly (e.g. 30 minutes for an easy/medium, 1 hour for a hard). Practice coding by hand or on a whiteboard / Google Doc at least a few times, since many interviews require writing without an IDE. This uncovers issues like syntax slip-ups or not remembering exact library functions under pressure. You can use platforms like &lt;em&gt;Pramp&lt;/em&gt; for free mock interviews or LeetCode’s interview simulate to get a feel (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=,a%20whiteboard%20or%20shared%20document" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;). Even simply talking through a problem as you solve it alone is good practice – in an interview you must communicate your thought process. So, when practicing, get into the habit of explaining out loud: “First, I’ll sort the array, which takes O(n log n). Then I’ll…”. This builds the skill of &lt;strong&gt;thinking aloud&lt;/strong&gt; coherently. If possible, do a couple of live mock interviews (with a friend or mentor) – they teach you to handle unexpected questions and get feedback on your communication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use LeetCode and Similar Platforms Wisely:&lt;/strong&gt; &lt;strong&gt;LeetCode&lt;/strong&gt; is one of the best tools for interview prep. Leverage features like difficulty filters, company-tagged questions (to target those frequently asked by your target companies), and the &lt;strong&gt;Discuss&lt;/strong&gt; section for learning different approaches. LeetCode’s large community means you can often find multiple solution styles for a problem, which is great for learning alternatives. A recommended strategy is to &lt;strong&gt;focus on medium-level problems&lt;/strong&gt;, as they constitute the bulk of interview questions; sprinkle in a fair number of easies (for warm-ups and core concept checks) and a handful of hards (to push your limits – if you can solve some hards, mediums will feel easier) (&lt;a href="https://www.reddit.com/r/leetcode/comments/vpoiof/whats_the_difference_between_leetcode_and/#:~:text=Reddit%20www,on%20leetcode%20is%20actually" rel="noopener noreferrer"&gt;What's the difference between leetcode and competitive ... - Reddit&lt;/a&gt;) (&lt;a href="https://leetcode.com/discuss/career/690658/competitive-coding-vs-preparing-for-interviews#:~:text=Competitive%20Coding%20Vs%20Preparing%20For," rel="noopener noreferrer"&gt;Competitive Coding Vs Preparing For Interviews - LeetCode Discuss&lt;/a&gt;). &lt;strong&gt;HackerRank&lt;/strong&gt; and &lt;strong&gt;CodeSignal&lt;/strong&gt; offer more beginner-friendly UI and often more guided problems, which can be good for early practice or warm-up (&lt;a href="https://hackernoon.com/comparing-coding-platforms-leetcode-codewars-codesignal-and-hackerrank#:~:text=HackerRank%20is%20another%20platform%20where,While%20HackerRank%20processed%20C%2FC%2B%2B%20solutions" rel="noopener noreferrer"&gt;Comparing Coding Platforms: LeetCode, CodeWars, CodeSignal, and HackerRank | HackerNoon&lt;/a&gt;). CodeSignal in particular has an &lt;strong&gt;Interview Practice&lt;/strong&gt; mode with timed tests – useful to get used to coding under a clock and for the kind of challenges used in screening tests (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=Key%20Features" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;) (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=What%20It%20Does%20Well" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;). Just be mindful: practice tests on CodeSignal are random and assume you’ve covered basics (they don’t teach you new concepts) (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=user" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;) – so use them to assess yourself rather than learn new topics. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Practice Coding by Hand and Edge Cases:&lt;/strong&gt; In interviews, after writing a solution, you’ll often be asked to run through examples. Train yourself to manually step through your code with test cases. When practicing, take a completed solution and simulate it on paper for a non-trivial test case (including edge cases like empty input, single element, maximum constraints). This habit will make you proficient at dry-running your code, so you can catch bugs before the interviewer does. It also ingrains careful thinking – many interview mistakes happen by not considering edge cases. So as you solve each practice problem, explicitly list edge cases (write them down!). For example: “Edge cases: empty array, array of one element, array with negative numbers, already sorted array, etc.” and ensure your solution handles them. This approach in practice translates to an interviewer seeing that you systematically consider all scenarios – a big plus.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combining these strategies leads to efficient, well-rounded preparation: you’ll &lt;strong&gt;learn&lt;/strong&gt; the material deeply and also be able to &lt;strong&gt;apply&lt;/strong&gt; it effectively under interview conditions. Remember, consistency trumps cramming – it’s better to practice a bit each day than to binge only on weekends. By following a structured approach, employing retention techniques, and practicing deliberately, you can greatly increase your chances of acing technical interviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Comprehensive DSA Study Sheet (Roadmap &amp;amp; Topics)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Below is a structured &lt;strong&gt;DSA roadmap&lt;/strong&gt;, organized from fundamental to advanced topics. Each topic includes a brief explanation, complexity highlights, common use cases, pitfalls/optimizations, and a few practice problems (with difficulty) ideal for interview prep. The topics are roughly in the order one should learn them (earlier topics build the foundation for later ones). A study plan following this roadmap could be broken into weekly goals (an example 12-week plan is provided after the topics).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Beginner Topics (Foundations)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Complexity Analysis (Big-O Notation):&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A way to quantify an algorithm’s efficiency by describing how runtime or space grows with input size &lt;code&gt;n&lt;/code&gt;. Big-O focuses on the upper bound (worst-case) complexity class.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key Concepts:&lt;/strong&gt; Understand constant vs linear vs logarithmic vs quadratic time, etc., and notation like &lt;em&gt;O(n)&lt;/em&gt;, &lt;em&gt;O(log n)&lt;/em&gt;, &lt;em&gt;O(n²)&lt;/em&gt;. Also know Big-Omega (best case) and Big-Theta (average) definitions for completeness.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Comparing two approaches – e.g., deciding between a brute force O(n²) solution and an optimized O(n log n). Used to reason about scalability (will this approach work when n = 10⁶?).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Be careful to consider worst-case scenarios (e.g. an unsorted input for a sorting alg). Don’t confuse different complexities – e.g., &lt;em&gt;O(n)&lt;/em&gt; vs &lt;em&gt;O(n log n)&lt;/em&gt; matters a lot for large n. Also, space complexity is equally important (e.g. recursion uses call stack space).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice/Check:&lt;/strong&gt; Be able to analyze simple code snippets for complexity. Know common complexities for classic algorithms (sorting, searching) and operations on data structures (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Access%20Search%20Insertion%20Deletion%20Access,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Quicksort%20,2%29%60%20%60O%28log%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; &lt;em&gt;None&lt;/em&gt; (This is conceptual). Instead, practice by analyzing algorithms you implement. You can test yourself with questions like “What is the complexity of iterating through a matrix vs a linked list?” or use quiz-style problems on algorithm complexity.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Arrays (and Strings):&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; An array is a contiguous block of memory holding elements of the same type, accessed by index. Strings are typically arrays of characters.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Reading or writing by index is O(1) (direct address calculation) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Access%20Search%20Insertion%20Deletion%20Access,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Searching for a value or an insertion/deletion at an arbitrary position is O(n) in an array (due to linear scan or shifting elements) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Access%20Search%20Insertion%20Deletion%20Access,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Dynamic arrays (like Python’s list or C++ &lt;code&gt;vector&lt;/code&gt;) can &lt;em&gt;amortize&lt;/em&gt; insert at end to O(1).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space:&lt;/strong&gt; Arrays are of fixed size (static allocation) or dynamic (resizable). Space efficiency is high since overhead is just the contiguous block, but resizing a dynamic array may involve allocating a new block and copying (usually doubling strategy).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Common Use Cases:&lt;/strong&gt; Anytime you need fast indexing – e.g. accessing the ith element of a list, or when data is naturally a sequence (like daily temperatures). Many algorithms use arrays as primary containers (sorting, two-pointer techniques, etc.). Strings – used for text processing – benefit from array properties (e.g. random access by index for a character).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation Notes:&lt;/strong&gt; Know how arrays are implemented in your language (e.g. Python list is dynamic array under the hood; Java arrays are fixed-size). Understand zero-indexing vs one-indexing differences. Be comfortable with iterating, slicing, etc. For strings, know immutability in languages like Java/Python (concatenation creates new strings each time, which is O(n)).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls &amp;amp; Optimizations:&lt;/strong&gt; Insertion/deletion in middle is costly (O(n)); if you need lots of insertions, consider linked list or dynamic sequence like a balanced BST. Iterating out of bounds causes errors – be mindful of indices. With strings, watch out for O(n²) concatenation in loops (use &lt;code&gt;StringBuilder&lt;/code&gt; in Java or array-join technique in Python to optimize repeated concatenations). Also, when copying arrays, note that a shallow copy just copies references (if not primitive types).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Two Sum (find two numbers that add to target) – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Maximum Subarray (Kadane’s algorithm) – &lt;em&gt;Easy/Medium&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Best Time to Buy/Sell Stock (find max profit) – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), &lt;strong&gt;Contains Duplicate&lt;/strong&gt; (check if any duplicate in array) – &lt;em&gt;Easy&lt;/em&gt;, Product of Array Except Self – &lt;em&gt;Medium&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). &lt;em&gt;(These cover array traversal, accumulation, and using structures like hash sets for duplicates.)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Linked Lists:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A linked list is a linear data structure where each element (node) contains a value and a pointer/reference to the next node (and optionally to the previous node, in a doubly-linked list) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=Like%20arrays%2C%20a%20linked%20list,It%20is%20a" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=A%20linked%20list%20where%20each,null" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). Unlike arrays, nodes may not be contiguous in memory; order is given by links.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Accessing the k-th element is O(k) because you must traverse from the head node (no random indexing) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=%60O%281%29%60%20%60O%28n%29%60%20Singly,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Insertion and deletion &lt;strong&gt;at a known position&lt;/strong&gt; (given a node reference) is O(1) – just adjust pointers (&lt;a href="https://www.bigocheatsheet.com/#:~:text=%60O%281%29%60%20%60O%28n%29%60%20Singly,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Searching for a value is O(n) in the worst case.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space:&lt;/strong&gt; Requires extra space for pointers in each node. More overhead than arrays, but can grow as needed (each node allocated on heap).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Useful when you have many inserts/deletes and only sequential access is needed – e.g. implementing a queue, or maintaining an ordered list of elements where you frequently add/remove from the ends or middle (with a pointer). Also forms the basis of other structures (linked list + hash map = LRU Cache, etc. (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=match%20at%20L4087%20doubly,operation%20in%20an%20LRU%20cache" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;)).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation:&lt;/strong&gt; Key operations: prepend (insert at head), append (insert at tail), delete a given node, reverse the list, find middle (using fast/slow pointers). Know how to handle edge cases (inserting/deleting at head or tail, empty list). In interviews, you often manually manage pointers; practice pointer manipulation to avoid bugs like losing the rest of the list when reversing. For doubly-linked lists, manage both &lt;code&gt;next&lt;/code&gt; and &lt;code&gt;prev&lt;/code&gt; pointers.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Common Pitfalls:&lt;/strong&gt; Running off the end (&lt;code&gt;null&lt;/code&gt; pointer errors) – always check for &lt;code&gt;null&lt;/code&gt; before accessing next node. Modifying head/tail requires updating external references. In C/C++, forgetting to free nodes can cause memory leaks (in managed languages this is handled by GC). Also, watch out for cycles in a linked list (an accidental loop can cause infinite traversal).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Reverse a Linked List – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=LC%20206%20,of%20Binary%20TreeEasy%2030%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Detect Cycle in Linked List – &lt;em&gt;Easy&lt;/em&gt; (Floyd’s cycle-finding), Merge Two Sorted Linked Lists – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=Problem%20Difficulty%20Duration%20LC%201,Valid%20AnagramEasy%2015%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Remove Nth Node from End – &lt;em&gt;Medium&lt;/em&gt;, LRU Cache (requires doubly-linked list + hashing) – &lt;em&gt;Medium/Hard&lt;/em&gt;. &lt;em&gt;(These cover pointer manipulation, list traversal, and integration with other structures.)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Stacks and Queues:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; Both are abstract linear structures. A &lt;strong&gt;stack&lt;/strong&gt; is LIFO (last-in, first-out) – imagine a pile of plates; operations are &lt;em&gt;push&lt;/em&gt; (add item on top) and &lt;em&gt;pop&lt;/em&gt; (remove item from top). A &lt;strong&gt;queue&lt;/strong&gt; is FIFO (first-in, first-out) – like a line of people; operations are &lt;em&gt;enqueue&lt;/em&gt; (add to back) and &lt;em&gt;dequeue&lt;/em&gt; (remove from front).  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Both can be implemented with arrays or linked lists. Typical implementations allow O(1) time for push/pop (stack) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Stack%20,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;) and enqueue/dequeue (queue) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;), since they operate at one end of the structure. Access/search are not typical operations (would be O(n) if needed).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; &lt;strong&gt;Stack:&lt;/strong&gt; function call stack (controls recursion), backtracking algorithms (push choices, pop when dead-end), parsing (e.g. stack for matching parentheses), undo mechanisms. &lt;strong&gt;Queue:&lt;/strong&gt; scheduling tasks (CPU task queue), level-order traversal of trees (BFS uses a queue), buffers (producer-consumer). Variants include &lt;em&gt;deque&lt;/em&gt; (double-ended queue) that supports both ends.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation:&lt;/strong&gt; A stack is often implemented using an array or Python list (with &lt;code&gt;append&lt;/code&gt;/&lt;code&gt;pop&lt;/code&gt; at end) or LinkedList (push/pop at head). A queue can be implemented with a linked list (adding at tail, removing at head) or circular buffer array. In Python, &lt;code&gt;collections.deque&lt;/code&gt; is a ready-made double-ended queue. Be aware of your language’s standard library (e.g. &lt;code&gt;Stack&lt;/code&gt; class in Java – though using &lt;code&gt;Deque&lt;/code&gt; is recommended, queue libraries, etc.).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Stack overflow if using too much stack space (especially recursion – but that’s more algorithmic). With a fixed-size array implementation, pushing to a full stack or enqueuing to a full queue needs handling (overflow). In a linked implementation, watch for &lt;code&gt;null&lt;/code&gt; on pop/dequeue from empty structure (underflow). For queues, maintaining two indices for front and rear in array implementations can be tricky (hence circular buffer technique).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimization:&lt;/strong&gt; In certain cases, two stacks can be used to implement a queue (amortizing the cost of reversing order), which is a common interview trick (e.g. making a queue with two stack operations). Similarly, a deque can implement both stack and queue operations efficiently. Recognize when a problem’s nature is LIFO or FIFO to choose these structures for a clean solution (e.g. use a stack for DFS or reversing a list, a queue for BFS).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Valid Parentheses (use a stack to check matching brackets) – &lt;em&gt;Easy&lt;/em&gt;, Min Stack (stack that can return min in O(1)) – &lt;em&gt;Medium&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Implement Queue using Two Stacks – &lt;em&gt;Easy/Medium&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Binary Tree Level Order Traversal (uses queue for BFS) – &lt;em&gt;Medium&lt;/em&gt;, Evaluate Reverse Polish Notation (stack for expression evaluation) – &lt;em&gt;Medium&lt;/em&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Hash Tables (Hash Maps):&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A hash table stores key-value pairs and uses a hash function to compute an index (or bucket) for each key. Ideally, basic operations – insert, lookup, delete – operate in average O(1) time by indexing into an array via the hash. (In Python, a dict; in Java, &lt;code&gt;HashMap&lt;/code&gt;; in C++ &lt;code&gt;unordered_map&lt;/code&gt;.)  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Average O(1) for insert/search/delete (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Skip%20List%20,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Worst-case O(n) if many keys collide into the same bucket (degrades to a linked list or similar structure) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Skip%20List%20,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;), but a good hash function and resizing strategy make this rare. Traversing all elements is O(n).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space:&lt;/strong&gt; Requires space proportional to number of entries, plus some overhead for the table (often larger than n to reduce collisions).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Whenever fast lookup by key is needed – counting frequencies (histograms), caching computed results, implementing sets (as keys in a hash map), memoization in DP, indexing data by a unique ID, etc. Extremely common in interview solutions (e.g. use a hash set to check if an element was seen before, achieving O(n) instead of O(n²) in many problems (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;)).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation Details:&lt;/strong&gt; Know that Python dicts and Java/Cpp hash maps handle collisions via either chaining (linked lists or trees in buckets) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=match%20at%20L4451%20,are%20examined%2C%20starting%20with%20the" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) or open addressing. Understand what makes a good hash function (uniform distribution, deterministic). Many languages do this for you, but you should know basics (e.g. hashing strings by polynomial rolling, mod a prime). Be aware of resizing (rehashing) – e.g. Java’s &lt;code&gt;HashMap&lt;/code&gt; doubles size when load factor &amp;gt; ~0.75. Iteration order in a hash map is not guaranteed (unless using an OrderedDict or Java’s LinkedHashMap).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Hash collisions can cause performance dips – e.g. an adversarial set of keys could all hash to same bucket. Keys must be hashable (immutable in Python). Be careful with floating-point keys (precision issues) or using objects that don’t properly implement equality. Iterating a hash map while modifying it can cause issues (fail-fast in Java). Also, don’t assume sorted order – if you need ordering, use a different structure (like TreeMap or sort the keys). Memory overhead can be higher than other structures due to spare capacity to maintain O(1) performance.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Two Sum (using a hash map to find complements) – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Group Anagrams (use hash of character counts) – &lt;em&gt;Medium&lt;/em&gt;, Longest Consecutive Sequence (hash set usage) – &lt;em&gt;Medium&lt;/em&gt;, Subarray Sum Equals K (use hash map to store prefix sums) – &lt;em&gt;Medium&lt;/em&gt;, LRU Cache (requires hash map + linked list) – &lt;em&gt;Medium/Hard&lt;/em&gt;. &lt;em&gt;(These illustrate using hash tables for quick lookups to optimize solutions.)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Basic Searching &amp;amp; Sorting:&lt;/strong&gt; Fundamental algorithms that often serve as building blocks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Binary Search:&lt;/strong&gt; Search for a target in a sorted array by dividing the range in half each time. O(log n) time. Use cases: any time you have a sorted array (or can sort first) and need fast lookups. Variants include finding leftmost/rightmost occurrence, etc. &lt;em&gt;Pitfall:&lt;/em&gt; off-by-one errors in loop, handling the case when element not found. Ensure you practice writing binary search without bugs. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorting Algorithms:&lt;/strong&gt; Know the basics of at least one &lt;em&gt;n*log*n&lt;/em&gt; sort (mergesort or quicksort) and one &lt;em&gt;O(n²)&lt;/em&gt; sort (bubble, insertion – mainly for understanding, as these are rarely implemented due to inefficiency). Key points: &lt;strong&gt;Quicksort&lt;/strong&gt; avg O(n log n), worst O(n²) (though rare with good pivot strategy) (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Algorithm%20Time%20Complexity%20Space%20Complexity,2%29%60%20%60O%28log%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;); &lt;strong&gt;Mergesort&lt;/strong&gt; O(n log n) worst, uses O(n) extra space (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Quicksort%20,2%29%60%20%60O%28log%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;); &lt;strong&gt;Heapsort&lt;/strong&gt; O(n log n) worst, in-place but not stable (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Timsort%20,O%281" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Also know that Python’s sort (Timsort) is O(n log n) and optimized for partially sorted data (&lt;a href="https://www.bigocheatsheet.com/#:~:text=Mergesort%20,O%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). Sorting is used in many problems as a preprocessing step to then use two-pointers or binary search, etc. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Binary search – any sorted data search (e.g. find insert position, search in rotated sorted array problem). Sorting – to simplify problems (e.g. sorting intervals by start time to then merge them). Also needed for algorithms like “two-sum II” (two-pointer after sort) or meeting-room scheduling (sort by start times).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Binary Search (basic implementation) – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=LC%20125%20,Balanced%20Binary%20TreeEasy%2015%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Search in Rotated Sorted Array – &lt;em&gt;Medium&lt;/em&gt;, Merge Two Sorted Arrays (merge step of mergesort) – &lt;em&gt;Easy&lt;/em&gt;, Merge Intervals – &lt;em&gt;Medium&lt;/em&gt;, Dutch National Flag (sort colors 0,1,2) – &lt;em&gt;Medium&lt;/em&gt;. Also, practice writing out quicksort or mergesort to be comfortable with recursion and partition logic (interviewers might ask you to explain or code a sort).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;(At this stage, a learner would have covered roughly Weeks 1-4 in a study plan: big-O, basic data structures (array, list, stack, queue, hash), and fundamental algorithms. Next comes more complex data structures and algorithmic techniques.)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Intermediate Topics&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Recursion &amp;amp; Backtracking:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; Recursion is when a function calls itself to solve subproblems. Backtracking is a form of recursion for exploring decision spaces – try a move, if it leads to a valid solution continue, otherwise backtrack and try another.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Many problems are elegantly solved via recursion: tree traversals (naturally recursive), DFS on graphs, divide-and-conquer algorithms (like merge sort, quicksort, binary search are recursive by nature). Backtracking specifically is used for combinatorial search: generating permutations, combinations, solving Sudoku or N-Queens, etc., where you build a solution incrementally and undo choices (“backtrack”) on dead-ends.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Recursive solutions can sometimes have exponential time (e.g. naive backtracking through all combinations) – recognize when that is the case (and then look for pruning or DP optimizations). Use recursion carefully to avoid excessive memory use (each recursive call adds a stack frame; Python has recursion limits). Tail recursion optimization (in some languages) can optimize certain recursions.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; The two big ones – &lt;strong&gt;stack overflow&lt;/strong&gt; (too deep recursion without termination, or just deep recursion depth beyond language limit) and &lt;strong&gt;forgetting base case&lt;/strong&gt; (leading to infinite recursion). Always define clear base case(s) that do not recurse. For backtracking, be careful to undo state changes when unwinding the recursion (e.g. remove the element you added, unmark visited, etc.). This is a common bug: not cleaning up global or shared state can corrupt other recursive paths. Also, for efficiency, prune impossible paths early (e.g. if partial solution is already invalid, don’t recurse deeper).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimization:&lt;/strong&gt; Convert recursion to iteration with a stack if needed (useful if recursion depth might exceed limits). Use memoization to cache results of recursive calls (that’s how you convert certain recursion to dynamic programming, e.g. Fibonacci with memoization avoids exponential blowup).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Factorial or Fibonacci (simple recursion) – &lt;em&gt;Easy&lt;/em&gt;, DFS Traversal of a Binary Tree (recursive implementation) – &lt;em&gt;Easy&lt;/em&gt;, Permutations of an array – &lt;em&gt;Medium&lt;/em&gt;, N-Queens problem – &lt;em&gt;Hard&lt;/em&gt; (backtracking with pruning), Word Search (search a grid with backtracking) – &lt;em&gt;Medium&lt;/em&gt;. These exercises build comfort with the recursive approach and managing state.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Trees (Binary Trees &amp;amp; Binary Search Trees):&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A tree is a hierarchical data structure with nodes connected by edges, without cycles. A &lt;strong&gt;binary tree&lt;/strong&gt; is a tree where each node has up to two children (“left” and “right”). A &lt;strong&gt;binary search tree (BST)&lt;/strong&gt; is a binary tree with the property that left child values &amp;lt; parent &amp;lt; right child values, for all nodes, enabling efficient lookup.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Important Properties:&lt;/strong&gt; Tree height (max levels) – affects complexity of operations. Balanced vs unbalanced (a highly unbalanced BST becomes like a linked list, operations degenerate to O(n)). Full, complete, perfect trees (know the differences for specific use cases, e.g. heaps are complete binary trees).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; For a balanced BST, search, insert, delete are O(log n) on average (&lt;a href="https://www.bigocheatsheet.com/#:~:text=,%CE%98%28log%28n" rel="noopener noreferrer"&gt;Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell&lt;/a&gt;). For a general binary tree, there’s no ordering, so search is O(n). Traversing the whole tree (DFS or BFS) is O(n). Many tree algorithms are O(n) because they visit each node once (e.g. computing height, checking BST validity, etc.).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Common Operations:&lt;/strong&gt; &lt;strong&gt;Traversals:&lt;/strong&gt; In-order (left-root-right), Pre-order (root-left-right), Post-order (left-right-root), Level-order (BFS by level). &lt;strong&gt;BST operations:&lt;/strong&gt; insert a node, find a node, delete a node (deletion is tricky – know the 3 cases: leaf, one child, two children). &lt;strong&gt;Balanced BSTs:&lt;/strong&gt; (like AVL trees or Red-Black trees) maintain balance after insert/delete to guarantee log n operations – typically not asked to implement in interviews, but know they exist (or that languages often have TreeMap/TreeSet which are self-balancing BSTs).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Trees naturally represent hierarchical data (filesystem, org charts, XML/HTML DOM). BSTs are used for sorted data where you need efficient lookup (e.g. implement a set/map with order – languages’ TreeSet, TreeMap). Binary trees (not necessarily BST) appear in many problems – e.g. decision trees, expression trees (parse expression into tree then evaluate), Huffman coding tree, etc.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Null children – many tree algorithms need to handle when a child is missing. Tree recursion can be deep – watch out for stack overflow on very large trees (use iterative with stack if needed). For BST, if the tree is unbalanced (e.g. inserting sorted values creates a skewed tree), operations slow down; self-balancing trees or using an array-based structure (like skip lists or heaps depending on need) might be preferable. When coding tree problems, a common mistake is incorrect handling of pointers when deleting nodes or swapping values. Also, be careful with mutable global state in recursion (for example, summing values – better to accumulate via return values or helper arguments).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Binary Tree Inorder Traversal (both recursive and iterative) – &lt;em&gt;Easy&lt;/em&gt;, Maximum Depth of Binary Tree – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=LC%20704%20,Linked%20List%20CycleEasy%2020%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Validate Binary Search Tree – &lt;em&gt;Medium&lt;/em&gt;, Binary Tree Level Order (BFS) – &lt;em&gt;Medium&lt;/em&gt;, Lowest Common Ancestor in BST/Binary Tree – &lt;em&gt;Medium&lt;/em&gt;. For BST-specific ops: Insert into BST – &lt;em&gt;Easy&lt;/em&gt;, Delete from BST – &lt;em&gt;Medium&lt;/em&gt; (understand the replacement by inorder successor/predecessor). These problems solidify traversal techniques and BST properties.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Heaps/Priority Queues:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A heap is a tree-based data structure (usually a binary heap implementation) that satisfies the &lt;strong&gt;heap property&lt;/strong&gt;: for a &lt;em&gt;max-heap&lt;/em&gt;, each node’s value ≥ the values of its children (so the largest value is at the root); for a &lt;em&gt;min-heap&lt;/em&gt;, each node’s value ≤ that of its children (smallest at root). A priority queue is an abstract data type that supports retrieving the highest (or lowest) priority element quickly, often implemented via a heap.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Insertion into a binary heap is O(log n) (percolate up) and removal of max/min is O(log n) (percolate down). Peeking at the top is O(1). Building a heap from an array can be done in O(n) (Floyd’s build heap algorithm). Heaps are space-efficient, typically in-place in an array (the tree is implicit in array indices).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Anytime you need quick access to the largest or smallest element but also need to frequently insert or remove elements. Examples: scheduling tasks by priority, Dijkstra’s shortest path algorithm uses a min-heap for picking next node with smallest distance, anytime you need to sort streaming data (a heap can keep track of top-k elements in O(n log k) time). Also used in heapsort (sorting algorithm).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation:&lt;/strong&gt; Usually as an array where index 0 (or 1) is the root, and for index &lt;code&gt;i&lt;/code&gt;, children are at &lt;code&gt;2*i+1&lt;/code&gt; and &lt;code&gt;2*i+2&lt;/code&gt; (if 0-indexed). Most languages have a priority queue library (e.g. &lt;code&gt;heapq&lt;/code&gt; in Python, &lt;code&gt;PriorityQueue&lt;/code&gt; or &lt;code&gt;Heap&lt;/code&gt; in others). Be comfortable writing push and pop (sift-up and sift-down). Also know how to change priority or remove arbitrary elements if needed (usually not trivial in a basic heap, often you just push a new value with adjusted priority).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; One common mistake is misunderstanding that a heap is &lt;em&gt;not sorted&lt;/em&gt; – it only guarantees the top element. Don’t assume the whole array is in sorted order if you iterate – you must pop repeatedly to get sorted output (which is essentially heapsort). Also, be careful with min-heap vs max-heap conventions (many libraries default to min-heap; for max-heap you might invert priorities or store negative values to simulate a max-heap in a min-heap implementation). For large data, watch out for memory usage if the heap grows big. In interviews, if using a heap, clarify if the built-in is allowed; if coding manually, pay attention to 0-index/1-index math when sifting.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Merge k Sorted Lists (use a min-heap to always pick smallest head) – &lt;em&gt;Hard&lt;/em&gt;, Top K Frequent Elements (max-heap or min-heap of size k) – &lt;em&gt;Medium&lt;/em&gt;, Find Median from Data Stream (two heaps method) – &lt;em&gt;Hard&lt;/em&gt;, Kth Largest Element in an Array – &lt;em&gt;Medium&lt;/em&gt;, Task Scheduler (using max-heap for task frequencies) – &lt;em&gt;Medium&lt;/em&gt;. These illustrate using heaps for selection problems and continuous data streams.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Graphs (and Graph Algorithms):&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; A graph is a set of vertices (nodes) connected by edges. Graphs can be &lt;strong&gt;directed&lt;/strong&gt; or &lt;strong&gt;undirected&lt;/strong&gt;. They may be weighted (edges have weights) or unweighted. Graphs generalize trees (a tree is a type of graph with no cycles).  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Representations:&lt;/strong&gt; Know adjacency list vs adjacency matrix. Adjacency list (vertex -&amp;gt; list of neighbors) is memory efficient for sparse graphs and is typically used in interviews unless graph is very small or dense. Adjacency matrix (2D matrix of size VxV) is easier for some problems but uses O(V²) space. For weighted graphs, adjacency list stores (neighbor, weight) pairs.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic Traversals:&lt;/strong&gt; &lt;strong&gt;Depth-First Search (DFS)&lt;/strong&gt; and &lt;strong&gt;Breadth-First Search (BFS)&lt;/strong&gt; – fundamental for exploring graphs. DFS uses a stack (recursion or explicit stack) – goes deep, useful for connectivity, path-finding, topological sort (with DAGs), detecting cycles. BFS uses a queue – finds shortest path in an unweighted graph (fewest edges), and processes layers of neighbors (useful for nearest relationships). Both run in O(V + E) time (visiting all vertices and edges) (&lt;a href="https://algocademy.com/blog/how-to-learn-data-structures-and-algorithms-effectively-a-comprehensive-guide/#:~:text=8,and%20Competitions" rel="noopener noreferrer"&gt;How to Learn Data Structures and Algorithms Effectively: A Comprehensive Guide - AlgoCademy Blog&lt;/a&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Common Algorithms:&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shortest Path:&lt;/strong&gt; For unweighted graphs, BFS from source finds shortest path (in edge count). For weighted graphs: Dijkstra’s algorithm (greedy, use min-heap, O((V+E) log V)), or Bellman-Ford (allows negative weights, O(V*E)). For all-pairs shortest path, Floyd-Warshall (O(V³)) or repeated Dijkstra. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimum Spanning Tree (MST):&lt;/strong&gt; Finds a subset of edges connecting all vertices with minimum total weight (for weighted undirected graphs). Algorithms: Kruskal’s (greedy, sort edges + union-find, O(E log E)) and Prim’s (greedy, like Dijkstra structure, O(E log V)). (&lt;a href="https://dev.to/sakshamceo/complete-data-structures-and-algorithms-roadmap-for-placements-part-1-551b#:~:text=Graphs"&gt;Complete Data Structures and Algorithms Roadmap for Placements (Part-1) - DEV Community&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topological Sort:&lt;/strong&gt; Ordering of vertices in a DAG (directed acyclic graph) such that all edges go from earlier to later in order. Done via DFS (with stack) or BFS (Kahn’s algorithm with in-degree count). Used in task scheduling, dependency resolution. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graph Search Applications:&lt;/strong&gt; Cycle detection (detect back-edge in DFS for directed graph, or union-find for undirected), Connected components (DFS/BFS on unvisited nodes), Bipartite check (2-coloring via BFS/DFS), etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Social networks (each user a node, relationships edges), road maps (cities and highways with weights as distances), scheduling with dependencies (DAG of tasks), network routing, and countless puzzles (15-puzzle state graph, etc.). Interview problems might give you a grid which can be seen as a graph (4-neighbors moves in a matrix use BFS for shortest path).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Graph problems often require careful handling of visited nodes to avoid infinite loops. Always mark visited (or distance discovered) to prevent revisiting nodes in DFS/BFS. For directed graphs, be mindful of direction in traversals. Off-by-one errors in matrix indexing if treating a grid as a graph. For weighted algorithms, watch out for overflow if weights accumulate (use appropriate data type). Also, large graphs can be expensive – ensure your solution is efficient enough (e.g. an O(V+E) traversal is usually fine, but O(V^2) might be too slow for large sparse graphs). With union-find, path compression and union by rank are important for performance when finding cycles or components.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Breadth-First Search in a matrix (e.g. shortest path in binary matrix) – &lt;em&gt;Medium&lt;/em&gt;, Number of Islands (connected components in grid) – &lt;em&gt;Medium&lt;/em&gt;, Clone Graph (graph traversal &amp;amp; copying) – &lt;em&gt;Medium&lt;/em&gt;, Course Schedule (cycle detection in directed graph via topological sort) – &lt;em&gt;Medium&lt;/em&gt;, Word Ladder (shortest transformation sequence, BFS) – &lt;em&gt;Hard&lt;/em&gt;. For weighted: Network Delay Time (single-source shortest path, use Dijkstra’s) – &lt;em&gt;Medium&lt;/em&gt;, Minimum Spanning Tree (e.g. Kruskal’s on a small graph) – &lt;em&gt;Medium&lt;/em&gt;. These cover traversal, connectivity, and shortest path basics.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Greedy Algorithms:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; Greedy algorithms build a solution by picking the locally optimal choice at each step, hoping to reach a global optimum. The greedy strategy works for problems that have the &lt;strong&gt;greedy-choice property&lt;/strong&gt; (a globally optimal solution can be constructed from local optimal choices) and optimal substructure.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases:&lt;/strong&gt; Common greedy algorithm problems include &lt;strong&gt;interval scheduling&lt;/strong&gt; (selecting intervals or meetings – always pick the next interval that finishes first (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;)), &lt;strong&gt;activity selection&lt;/strong&gt;, &lt;strong&gt;Huffman coding&lt;/strong&gt; (greedily merge least frequent symbols), &lt;strong&gt;Dijkstra’s algorithm&lt;/strong&gt; (greedily pick closest next node), &lt;strong&gt;Prim’s MST&lt;/strong&gt;, &lt;strong&gt;Kruskal’s MST&lt;/strong&gt; (greedy picks smallest weight edge that doesn’t form a cycle), coin change for certain coin systems (greedily pick largest coin – works for e.g. US currency, but not all coin systems), scheduling and optimization problems where a heuristic seems evident.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Advantages:&lt;/strong&gt; Greedy algorithms are usually simple and fast (often O(n log n) due to sorting, or O(n) in some cases). If applicable, they give neat, efficient solutions. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; &lt;strong&gt;Validity&lt;/strong&gt; – not all problems can be solved greedily (sometimes a greedy choice now can spoil the solution; e.g. the knapSack problem requires dynamic programming because greedy fails for certain item combinations). So one must often prove or at least reason why greedy works for the given problem. Also, implementing a greedy solution often involves sorting or priority queues. Ensure your greedy choice is implemented correctly (e.g. in interval scheduling, sorting by finish time is crucial).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Interval Scheduling (Activity Selection: given start/end times, choose max non-overlapping) – &lt;em&gt;Medium&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Minimum Number of Platforms (or Meeting Rooms problem – uses a greedy and sort) – &lt;em&gt;Medium&lt;/em&gt;, Fractional Knapsack (take as much of highest value/weight first) – &lt;em&gt;Easy/Medium&lt;/em&gt;, Huffman Coding (greedy merging using min-heap) – &lt;em&gt;Medium&lt;/em&gt;, Jump Game II (min jumps to end – greedy can work by tracking furthest reach) – &lt;em&gt;Medium&lt;/em&gt;. Each of these requires making a locally optimal choice and can be solved efficiently with that strategy.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Dynamic Programming:&lt;/strong&gt; &lt;em&gt;Definition:&lt;/em&gt; DP is an optimization technique for problems with &lt;strong&gt;overlapping subproblems&lt;/strong&gt; and &lt;strong&gt;optimal substructure&lt;/strong&gt;. It involves breaking a problem into subproblems, solving each subproblem once and storing the results, typically using a table (array) to build up solutions, rather than naive recursion which might solve the same subproblem many times.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key Idea:&lt;/strong&gt; Identify a state (set of parameters that define a subproblem) and a recurrence relation that gives the solution of a state from solutions of smaller states. Use either &lt;strong&gt;top-down (memoization)&lt;/strong&gt; – recursion + caching results – or &lt;strong&gt;bottom-up (tabulation)&lt;/strong&gt; – iteratively fill a DP table.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Types of DP:&lt;/strong&gt; &lt;strong&gt;1D DP&lt;/strong&gt; for linear problems (e.g. Fibonacci, climb stairs, coin change 1D). &lt;strong&gt;2D DP&lt;/strong&gt; typically for sequences (e.g. edit distance on two strings, DP[i][j] meaning solution for first i and first j chars). &lt;strong&gt;DP on trees or graphs&lt;/strong&gt; (state might include a node and some info). &lt;strong&gt;Bitmask DP&lt;/strong&gt; for subset-related problems (state uses a bitmask to represent subset of elements).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; Often DP reduces exponential brute force to polynomial time. E.g. naive recursion on Fibonacci is 2^n, but DP is O(n). Many DP solutions are O(n) or O(n*m) for two sequences. Be aware some DP can still be expensive (bitmask DP for traveling salesman is O(n * 2^n)). Space complexity can often be optimized (e.g. using only 1-2 rows for some 2D DPs, because you may not need entire table at once).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfalls:&lt;/strong&gt; Hardest part is usually formulating the DP state and recurrence. A common pitfall is using the wrong state definition or forgetting part of the state, leading to an incorrect solution. Also, double counting or not covering all cases in the recurrence can cause errors. Off-by-one errors in table indices are frequent – be careful with indexing (e.g. DP array of size n+1 if you use 1-based indexing for convenience). For memoization, watch out for stack overflow if the recursion is too deep (sometimes bottom-up is safer in those cases). Also, DP can be slow if not pruned or if state space is large – ensure you’ve pruned impossible states (e.g. skip invalid transitions).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice Problems:&lt;/strong&gt; Fibonacci / Climbing Stairs (simple DP) – &lt;em&gt;Easy&lt;/em&gt; (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=Problem%20Difficulty%20Duration%20LC%20232,Add%20BinaryEasy%2015%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), Coin Change (min coins to make amount) – &lt;em&gt;Medium&lt;/em&gt;, Longest Increasing Subsequence – &lt;em&gt;Medium&lt;/em&gt;, 0/1 Knapsack – &lt;em&gt;Medium&lt;/em&gt;, Edit Distance (string convert) – &lt;em&gt;Hard&lt;/em&gt;, House Robber (max nonadjacent sum) – &lt;em&gt;Medium&lt;/em&gt;, Decode Ways (count ways to decode string) – &lt;em&gt;Medium&lt;/em&gt;. Also, classic grid DP like Unique Paths in a grid – &lt;em&gt;Medium&lt;/em&gt;. These problems exercise identifying subproblems and building solutions from them. Start with simpler ones and progress to the harder ones like edit distance or longest common subsequence.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Advanced Data Structures:&lt;/strong&gt; (These are more advanced topics that may or may not appear in every interview, but are good to know especially for certain companies or roles.)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trie (Prefix Tree):&lt;/strong&gt; A tree-like structure for storing strings by their prefixes. Each node represents a prefix of some of the inserted words. Commonly used for quick prefix lookup (autocomplete, spell-check, IP routing). Complexity: inserting or searching a word of length m is O(m). Space can be large if storing many words (though it can share prefixes). &lt;em&gt;Practice:&lt;/em&gt; Implement a Trie (insert/search) – &lt;em&gt;Medium&lt;/em&gt;, Word Search II (find words in a grid using a trie) – &lt;em&gt;Hard&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Union-Find (Disjoint Set Union - DSU):&lt;/strong&gt; A structure to keep track of partitions of a set, supporting union and find operations. Useful in graph problems (connected components, cycle detection, Kruskal’s MST). Almost O(1) (amortized inverse Ackermann) with union by rank and path compression. &lt;em&gt;Practice:&lt;/em&gt; Find Connected Components in an undirected graph – &lt;em&gt;Medium&lt;/em&gt;, Redundant Connection (find extra edge in tree forming a cycle) – &lt;em&gt;Medium&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bit Manipulation:&lt;/strong&gt; Techniques that use bitwise operations for efficiency. Important concepts: using bit masks to represent sets or states, shifting, bitwise AND/OR/XOR. &lt;em&gt;Practice:&lt;/em&gt; Single Number (XOR to find non-duplicate) – &lt;em&gt;Easy&lt;/em&gt;, Counting Bits (Brian Kernighan’s algorithm) – &lt;em&gt;Easy&lt;/em&gt;, Subset generation using bits – &lt;em&gt;Medium&lt;/em&gt;. Know common bit tricks (check if number is power of 2, swapping values without temp using XOR, etc.).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Segment Tree/Fenwick Tree:&lt;/strong&gt; Used for range queries and updates on arrays (e.g. sum over a range, min over a range). They provide ~O(log n) query and update. Not commonly required unless you mention competitive programming or a job needs it, but knowing at high level can help if a problem can’t be done with simpler structures. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bloom Filter, LRU Cache internals, etc.:&lt;/strong&gt; Only in specialized cases – bloom filter is a probabilistic set (not usually asked unless the job role is specific). LRU Cache can be implemented via combination of list+hash (which we covered in practice problems).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;(Having covered all topics, a learner would spend remaining weeks practicing integration of these topics and tackling comprehensive problems. The study plan below organizes these topics week-by-week for efficient learning.)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Sample 12-Week Study Plan:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This plan assumes ~10-15 hours per week. It mixes learning and practice. Adjust according to your pace (it can be stretched to 16 weeks or compressed to 8 with more hours per week). Each week, focus on learning the concepts and then solving targeted problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 1: Big-O &amp;amp; Arrays/String basics&lt;/strong&gt; – Learn Big-O notation and analyze examples. Implement simple algorithms and check their complexity. Learn array operations (traversal, insertion concepts) and string manipulation. &lt;em&gt;Practice:&lt;/em&gt; Easy array problems (Two Sum (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), merge sorted arrays, etc.) and string problems (reverse string, anagram check).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 2: Linked Lists, Stacks &amp;amp; Queues&lt;/strong&gt; – Understand pointers and implement a singly linked list from scratch. Learn stack and queue interfaces. &lt;em&gt;Practice:&lt;/em&gt; Linked list problems (reverse list, detect cycle) and stack/queue problems (valid parentheses, implement queue using stacks (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;)). Aim for 4-5 problems each structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 3: Hash Tables &amp;amp; Searching/Sorting&lt;/strong&gt; – Study hash table concept; maybe implement a simple hash map (optional). Learn binary search thoroughly. Review sorting algorithms (at least conceptually); know how to use your language’s sort. &lt;em&gt;Practice:&lt;/em&gt; Problems combining arrays &amp;amp; hashing (two-sum with hash, etc.) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;). Do binary search problems (basic binary search, search insert position, rotated array). Try an easy sorting problem (like sort colors using Dutch flag).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 4: Recursion &amp;amp; Backtracking&lt;/strong&gt; – Strengthen recursion skills. Solve a few recursion problems (e.g. subsets generation). Also use this week to review any earlier topics you found difficult (spaced repetition review). &lt;em&gt;Practice:&lt;/em&gt; Fibonacci (with and without DP), permutations of a list, simple backtracking like generating combinations of well-formed parentheses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 5: Trees (Traversals &amp;amp; BST)&lt;/strong&gt; – Learn tree traversals (do them by recursion and iteratively with stack). Understand BST properties. &lt;em&gt;Practice:&lt;/em&gt; Tree traversal outputs (inorder, preorder), BST search/insert. Problems: max depth of binary tree (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=LC%20704%20,Linked%20List%20CycleEasy%2020%20mins" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), validate BST, sorted array to BST (to practice thinking recursively). If comfortable, try a LCA (Lowest Common Ancestor) problem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 6: Priority Queues &amp;amp; Heaps&lt;/strong&gt; – Learn how heaps are implemented and used. &lt;em&gt;Practice:&lt;/em&gt; Use a min-heap for k closest points or k largest elements. Use a max-heap for rearrange string (greedy) or frequency sort. Ensure you solve at least one “merge k sorted lists” (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) using a heap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 7: Graphs (BFS/DFS)&lt;/strong&gt; – Learn graph representations and BFS/DFS algorithms. &lt;em&gt;Practice:&lt;/em&gt; Graph traversal problems: number of islands (using DFS/BFS), clone graph, course schedule (detect cycle/topological sort). Do a BFS shortest path in a grid problem for practice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 8: Graph Algorithms (Advanced)&lt;/strong&gt; – Cover Dijkstra’s algorithm for shortest path and Union-Find for connectivity. &lt;em&gt;Practice:&lt;/em&gt; Implement Dijkstra on a small weighted graph (or solve a problem like network delay time). Solve an MST problem (maybe from a competitive programming example or a known problem like connecting cities with minimum cost). If time, also attempt a union-find problem (e.g. accounts merge or similar).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 9: Greedy Algorithms&lt;/strong&gt; – Review greedy patterns. &lt;em&gt;Practice:&lt;/em&gt; Activity selection (interval scheduling) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=and%20have%20practiced%20the%20essential,questions" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;), minimum platform/meeting rooms, a coin change greedy variant. Also try a couple of problems that seem greedy and verify (e.g. check if you can jump game with greedy).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 10: Dynamic Programming (DP Basics)&lt;/strong&gt; – Start with 1D DP problems. &lt;em&gt;Practice:&lt;/em&gt; Fibonacci, climb stairs, coin change, house robber, etc. Understand how to formulate state and recurrence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 11: Dynamic Programming (DP Advanced)&lt;/strong&gt; – Tackle 2D DP or harder DP. &lt;em&gt;Practice:&lt;/em&gt; Longest Common Subsequence or Edit Distance (string DP), Knapsack (subset-sum style), and at least one harder problem like Decode Ways or Dungeon Game. This solidifies DP thinking. Also this week, review any topic you feel shaky on (it’s a good point to refresh trees or graphs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Week 12: Review and Mixed Practice&lt;/strong&gt; – Now shift to mock interviews and mixed questions. Each day, simulate an interview: pick 1-2 random problems (medium difficulty) from any topic and solve within a time limit. Review your flashcards/notes on all topics (spaced repetition). Identify any last weak spots and do a focused review. If preparing for specific companies, practice some of their commonly asked questions (many lists available). &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Throughout all weeks, keep using &lt;strong&gt;spaced repetition&lt;/strong&gt; for what you learned before. For example, in Week 6, revisit a couple of Week 1-4 problems to ensure you remember those techniques. Also, maintain a log of problems solved, noting which you found tricky – revisit those in a few weeks to see if you can solve them faster/without help.&lt;/p&gt;

&lt;p&gt;By the end of this plan, you will have covered all critical DSA topics, each reinforced with targeted problems and then randomized practice to ensure you can handle unknown questions. Adjust the timeline as needed, but ensure you cover all topics and get sufficient practice. Consistency is key – try to code almost daily, even if it’s one small problem or reviewing an algorithm. This steady exposure will make you well-prepared for technical interviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;strong&gt;Resource Compilation (Videos, Courses, Platforms)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Top Video-Based Courses &amp;amp; YouTube Channels:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Coursera / edX University Courses (Free to audit):&lt;/strong&gt; High-quality offerings include &lt;em&gt;Princeton’s Algorithms, Part I &amp;amp; II&lt;/em&gt; (Kevin Wayne, Robert Sedgewick) – Java-based, very thorough (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=,part2" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). &lt;em&gt;Stanford’s Algorithms Specialization&lt;/em&gt; (Tim Roughgarden) – excellent theoretical foundation with some programming assignments. &lt;em&gt;UC San Diego’s Data Structures and Algorithms Specialization&lt;/em&gt; – covers basic to advanced DSA in an interview-oriented way (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,Data%20Structures%20%26%20Algorithms%2C%20Udacity"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;). MIT OpenCourseWare (&lt;em&gt;6.006 Introduction to Algorithms&lt;/em&gt; and &lt;em&gt;6.046 Design and Analysis of Algorithms&lt;/em&gt;) – rigorous lectures (more mathy), but free on YouTube (&lt;a href="https://www.reddit.com/r/learnprogramming/comments/jshpob/best_youtube_playlist_to_learn_data_structures/#:~:text=William%20Fiset" rel="noopener noreferrer"&gt;Best YouTube Playlist to Learn Data Structures and Algorithms? : r/learnprogramming&lt;/a&gt;). These courses are structured and academic – great for understanding depth; you might mix them with hands-on practice since some can be intense.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;YouTube – Structured Playlists:&lt;/strong&gt; &lt;strong&gt;takeUforward (Raj Vikramaditya)&lt;/strong&gt; – an excellent free resource covering DSA topics and problem walkthroughs in C++ (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=1,III%20%40Google"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). The channel provides a structured playlist (e.g.  C++ STL, then each data structure and associated problems, and “Striver’s SDE Sheet” solutions) – highly recommended for interview prep. &lt;strong&gt;NeetCode&lt;/strong&gt; – focuses on coding interview problems; the creator explains patterns and solutions in Python very clearly (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=2,you%20plan%20to%20grind%20LeetCode"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). Great for when you’re stuck on a LeetCode problem – you can likely find it on NeetCode and understand the approach. &lt;strong&gt;Abdul Bari&lt;/strong&gt; – famous for simplifying complex algorithms (like graph algorithms, DP, etc.) with clear whiteboard explanations (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=3,channel%20link%3A%20Abdul%20bari"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). His videos on topics like BFS/DFS, dynamic programming, etc. are widely praised for clarity (though code examples might be in C/C++). &lt;strong&gt;William Fiset&lt;/strong&gt; – covers a wide range of data structures and algorithms (including advanced ones like max flow, suffix arrays) in an in-depth manner; good for deeper understanding once basics are done (&lt;a href="https://www.reddit.com/r/learnprogramming/comments/jshpob/best_youtube_playlist_to_learn_data_structures/#:~:text=%E2%80%A2" rel="noopener noreferrer"&gt;Best YouTube Playlist to Learn Data Structures and Algorithms? : r/learnprogramming&lt;/a&gt;). &lt;strong&gt;freeCodeCamp.org channel&lt;/strong&gt; – offers full-length courses: e.g. an 8-hour &lt;em&gt;DSA in Python&lt;/em&gt; video, and a 5-hour &lt;em&gt;Dynamic Programming&lt;/em&gt; course. These are great for a start-to-finish overview or focused deep dive respectively. Other notable channels: &lt;strong&gt;CS Dojo&lt;/strong&gt; (intuitive explanations of some beginner problems), &lt;strong&gt;Jenny’s Lectures (Jenny D.&lt;/strong&gt;)* – covers data structures (often in C/C++), &lt;strong&gt;MyCodeSchool&lt;/strong&gt; – classic older channel with excellent linked list and pointers series (in C++) and other basics (unfortunately incomplete but what’s there is gold). For a more formal treatment, &lt;strong&gt;Berkeley CS61B&lt;/strong&gt; lectures (on YouTube) give you the data structures course content from a top university (Java focused) (&lt;a href="https://www.reddit.com/r/learnprogramming/comments/jshpob/best_youtube_playlist_to_learn_data_structures/#:~:text=%E2%80%A2" rel="noopener noreferrer"&gt;Best YouTube Playlist to Learn Data Structures and Algorithms? : r/learnprogramming&lt;/a&gt;). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Udemy and Paid Video Courses:&lt;/strong&gt; If you prefer a single comprehensive course with coding exercises, Udemy has popular ones like &lt;em&gt;“Mastering Data Structures &amp;amp; Algorithms”&lt;/em&gt; by Abdul Bari (covers theory and implementation in C/C++), or &lt;em&gt;“JavaScript Algorithms and Data Structures”&lt;/em&gt; by Colt Steele (good for JS developers) (&lt;a href="https://www.reddit.com/r/learnprogramming/comments/jshpob/best_youtube_playlist_to_learn_data_structures/#:~:text=Yess%2C%20I%20am%20currently%20completing,that%20you%20should%20know%20JS" rel="noopener noreferrer"&gt;Best YouTube Playlist to Learn Data Structures and Algorithms? : r/learnprogramming&lt;/a&gt;). These usually cost &amp;lt;$20 on sale. They provide a structured curriculum plus assignments. However, keep in mind free resources often match or exceed these in quality (&lt;a href="https://www.placementpreparation.io/blog/best-youtube-channels-to-learn-data-structures-and-algorithms/#:~:text=Best%20YouTube%20Channels%20to%20Learn,Caleb%20Curry%20%C2%B7%205" rel="noopener noreferrer"&gt;10 Best YouTube Channels to Learn Data Structures and Algorithms&lt;/a&gt;), so paid isn’t necessary unless it fits your learning style. &lt;strong&gt;Interview Camp&lt;/strong&gt; (paid) offers a structured approach with video lessons and lots of practice problems by category, useful if you want a guided interview-focused program. &lt;strong&gt;AlgoExpert&lt;/strong&gt; (paid) provides curated interview questions with video solutions (by Clément Mihailescu) – good for targeted practice after you’ve learned concepts, though not cheap (~$100). &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Free vs Paid:&lt;/strong&gt; In general, free resources (YouTube channels, free online courses, coding websites) are sufficient for most people – they are often created by experts and cover everything. Paid resources can add value via structure, mentoring, or exclusive problem sets, but beware of expensive programs that might not deliver proportionate value. For instance, &lt;em&gt;Grokking the Coding Interview&lt;/em&gt; (Educative) is a paid text-based course focusing on patterns – many find it useful to recognize patterns in problems quickly. If self-discipline is an issue, a paid structured bootcamp might be worth it. But plenty of learners succeed via free material: as one article notes, &lt;em&gt;YouTube’s free tutorials often outshine paid courses&lt;/em&gt; (&lt;a href="https://www.analyticsinsight.net/latest-news/youtube-channels-for-mastering-data-structures-and-algorithms#:~:text=YouTube%20Channels%20For%20Mastering%20Data,Caleb%20Curry%20%E2%80%93%20Data" rel="noopener noreferrer"&gt;YouTube Channels For Mastering Data Structures And Algorithms&lt;/a&gt;). A balanced approach: use free resources to learn and practice, and if you hit a plateau or need additional guidance, consider a paid mock interview or a month subscription to a site like AlgoExpert or LeetCode Premium for focused question sets. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Language-Specific Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Python:&lt;/strong&gt; Python is excellent for interviews due to quick coding, but be mindful of its performance on very large inputs. For Python-specific learning, the textbook &lt;em&gt;“Problem Solving with Algorithms and Data Structures using Python”&lt;/em&gt; by Miller and Ranum is a great free resource (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=,using%20Python" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). It introduces DSA in Python with examples and is available as an interactive online version. There are also Python-focused courses like &lt;em&gt;Google’s Python DSA on Coursera&lt;/em&gt; (as part of Google IT Automation) which covers basic structures in Python. Websites like Programiz and GeeksforGeeks provide Python code for all standard algorithms (good for reference) (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=4,link%3A%20Programiz"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;) (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=2,like%20hard%2C%20medium%2C%20easy%2C%20specific"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). When practicing, use Python on LeetCode – it supports it and you can learn Pythonic shortcuts (but also know how to do things without always relying on library functions if asked in interview). &lt;strong&gt;NeetCode&lt;/strong&gt; and &lt;strong&gt;LeetCode Discuss&lt;/strong&gt; often show Python solutions which is helpful. One caution: Python’s recursion depth is limited (~1000), so very deep recursion problems might need an iterative approach. Also practice using Python’s collections (list, deque, heapq, dict, etc.) effectively, as they can simplify implementations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt; Many classic resources use Java. The book &lt;em&gt;“Cracking the Coding Interview”&lt;/em&gt; uses Java for code examples. If you prefer video, &lt;strong&gt;Bro Code&lt;/strong&gt; and others have Java DSA playlists. Coursera’s Princeton course uses Java and comes with the algs4.jar library for algorithms – a good way to get comfortable with Java implementations (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=,part2" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). Make sure to learn Java Collections (ArrayList, LinkedList, HashMap, HashSet, etc.) and their complexities. For practicing, LeetCode has Java support and you can use the standard library extensively (e.g. PriorityQueue for heaps). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;C++:&lt;/strong&gt; Favored in competitive programming, C++ is super efficient and has the STL (Standard Template Library) which provides ready DSA implementations (vector, list, unordered_map, map, etc.). &lt;strong&gt;takeUforward&lt;/strong&gt; and many Indian YouTubers teach DSA in C++ (e.g. Abdul Bari’s Udemy course is C/C++, Apna College channel if you understand Hindi, etc.). TopCoder tutorials and CodeChef discuss are also often in C++. If you use C++, be comfortable with pointers (for implementing things like trees, linked lists manually) and STL usage. Practicing on Codeforces in C++ can sharpen skills, but for interviews, it’s fine to use STL rather than writing from scratch (unless asked). One thing: know the syntax well (sometimes writing C++ in interviews can be slower due to verbosity). If you’re interviewing at companies known to have a preference for low-level coding, knowing C/C++ might help, but generally you can use any mainstream language.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JavaScript:&lt;/strong&gt; For front-end or full-stack roles, you might code in JS. There are fewer traditional DSA resources in JS, but they exist: &lt;em&gt;freeCodeCamp&lt;/em&gt; curriculum (interactive) teaches algorithmic thinking in JS. Frontend Masters has a good paid course on Algorithms in JavaScript (by Bianca Gandolfo) (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=I%20forgot%20to%20mention%20my,you%20can%E2%80%99t%20find%20anywhere%20else" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). The book &lt;em&gt;“Learning JavaScript Data Structures and Algorithms”&lt;/em&gt; (Loiane Groner) is a decent read as mentioned by a learner (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=I%20am%20also%20reading%20Learning,I%20get%20a%20strong%20understanding" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;). On LeetCode, you can submit in JS (using Node environment). Just ensure you know how to implement structures in JS (e.g. using objects as maps, arrays as dynamic arrays). One caveat: extremely large input handling might be slower in JS, but for most interview-sized problems it’s fine. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;(Broadly, choose the language you’re most comfortable in – all these concepts apply in any language, just the implementation details differ. Many resources now provide code in multiple languages – e.g. GeeksforGeeks shows C++, Java, and Python for most topics.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Coding Practice Platforms:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;LeetCode:&lt;/strong&gt; The most popular interview practice platform. LeetCode has a vast collection of problems categorized by difficulty and topic. It’s excellent for hands-on practice and is highly recommended (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=1,solve%20the%20problem%20related%20to"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;). &lt;strong&gt;Pros:&lt;/strong&gt; High-quality, real interview questions; active community and solutions; supports multiple languages; has company-specific question lists and contests. &lt;strong&gt;Cons:&lt;/strong&gt; Some problem statements can be brief; certain features (like seeing official solutions or company frequency) require Premium. However, even free, it’s indispensable. Use LeetCode to simulate interview coding and to track your progress (they offer “study cards” for topics as well). Many top interviewees focus heavily on LeetCode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HackerRank:&lt;/strong&gt; Good for beginners – it provides more scaffolding (function signatures, some guidance) and has discussions and tutorials for many problems. It covers not just algorithms but also SQL, Regex, etc. &lt;strong&gt;Pros:&lt;/strong&gt; Clean UI, easy ones to build confidence, and a variety of domains (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=1" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;). &lt;strong&gt;Cons:&lt;/strong&gt; Some find the problems a bit too straightforward or “hackerRank-specific” (less like tricky interview questions, more like practice drills) (&lt;a href="https://hackernoon.com/comparing-coding-platforms-leetcode-codewars-codesignal-and-hackerrank#:~:text=HackerRank%20is%20another%20platform%20where,While%20HackerRank%20processed%20C%2FC%2B%2B%20solutions" rel="noopener noreferrer"&gt;Comparing Coding Platforms: LeetCode, CodeWars, CodeSignal, and HackerRank | HackerNoon&lt;/a&gt;). Still, for someone starting out, doing HackerRank “Algorithms” track can solidify basics. It also has contests and company challenges (some companies use HackerRank for first-round). After you exhaust those, move to LeetCode for more depth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CodeSignal:&lt;/strong&gt; Known for its arcade and certified assessments. CodeSignal’s &lt;em&gt;Arcade&lt;/em&gt; has tiers of challenges that can be fun and increasingly challenging (e.g. Arcade “Intro” begins easy and gradually becomes like medium interview Qs). They also have &lt;em&gt;Interview Practice&lt;/em&gt; and &lt;em&gt;Company Bots&lt;/em&gt; sections. Companies (like Uber, Dropbox) use CodeSignal for timed coding tests, so practicing there can familiarize you with their test environment. &lt;strong&gt;Pros:&lt;/strong&gt; Nice interface, ability to take a &lt;em&gt;general coding assessment&lt;/em&gt; to get a score (some companies accept that score). It offers &lt;em&gt;timed&lt;/em&gt; practice which is great for simulating pressure (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=Key%20Features" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;) (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=What%20It%20Does%20Well" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;). &lt;strong&gt;Cons:&lt;/strong&gt; The practice tasks in the Arcade are random and not categorized by topic on the platform (though you can find lists on forums) (&lt;a href="https://algocademy.com/blog/top-leetcode-alternatives-for-coding-practice/#:~:text=user" rel="noopener noreferrer"&gt;Top LeetCode Alternatives for Coding Practice - AlgoCademy Blog&lt;/a&gt;). Also, the problems might not always match typical interview questions in style, and the community/discussion is smaller than LeetCode’s. Use CodeSignal if you want to gamify your practice or prepare for a known CodeSignal test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Codeforces &amp;amp; TopCoder:&lt;/strong&gt; These are competitive programming platforms. Codeforces has frequent contests; problems can be quite challenging and cover algorithmic tricks. Practicing here can significantly up your problem-solving skills, but it might overshoot interview needs. &lt;strong&gt;Pros:&lt;/strong&gt; If you can solve Codeforces Div2 C/D problems, most interview mediums/hards will feel easy. It teaches you to think under time limits and deal with edge cases. &lt;strong&gt;Cons:&lt;/strong&gt; Emphasizes speed and sometimes math; not all problems translate to interview scenarios (e.g. bitset optimization or combinatorics puzzle). If you enjoy it, do it – but don’t worry if it’s not your cup of tea. Some candidates do a few Codeforces rounds to break monotony of LeetCode and sharpen skills (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=,hone%20their%20competitive%20programming%20skills" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AtCoder:&lt;/strong&gt; Another competitive site, known for very clean problems (often more mathematical). Similar trade-offs to Codeforces. Mentioned here for completeness – use it if you enjoy contests or want to push your algorithmic thinking further (&lt;a href="https://www.designgurus.io/answers/detail/whats-better-than-leetcode#:~:text=,competing%20in%20international%20coding%20competitions" rel="noopener noreferrer"&gt;What's better than LeetCode?&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Others:&lt;/strong&gt; &lt;strong&gt;GeeksforGeeks&lt;/strong&gt; has a huge problem archive and articles. It’s great for learning (tutorial-style explanations) (&lt;a href="https://dev.to/naime_molla/top-10-free-resources-to-learn-data-structures-and-algorithms-in-2024-4i4j#:~:text=2,like%20hard%2C%20medium%2C%20easy%2C%20specific"&gt;Top 10 Free Resources to Learn Data Structures and Algorithms in 2024 - DEV Community&lt;/a&gt;), and their practice portal lets you code and submit solutions too. Sometimes their problems are not as polished as LeetCode, but for topic-specific practice (like “practice all BST questions”), GfG is useful. &lt;strong&gt;InterviewBit&lt;/strong&gt; (free) curates problems by topic in a guided way similar to a bootcamp – it’s quite good for structured prep and mimics an interactive workbook. &lt;strong&gt;CodeChef&lt;/strong&gt; has a DSA learning series and monthly contests – good if you like structured progression with some competitive element (&lt;a href="https://dev.to/sakshamceo/week-wise-data-structures-and-algorithms-schedule-for-placements-part-2-1i0d#:~:text=practice%20questions,and%20Long%20Contests%20on%20Codechef"&gt;Week Wise Data Structures and Algorithms Schedule for Placements. (Part-2) - DEV Community&lt;/a&gt;). &lt;strong&gt;Project Euler&lt;/strong&gt; (for math-heavy puzzles) or &lt;strong&gt;CodeWars&lt;/strong&gt; (for small algorithmic challenges) can improve your coding and math finesse but are supplementary – they don’t cover system design or large data structures much. If you need to practice writing clean code and small functions, CodeWars is fun. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, &lt;strong&gt;LeetCode&lt;/strong&gt; is the go-to for interview-alike practice (&lt;a href="https://www.designgurus.io/answers/detail/is-leetcode-competitive-coding#:~:text=,titles%20in%20competitive%20coding%20events" rel="noopener noreferrer"&gt;Is LeetCode competitive coding?&lt;/a&gt;). Supplement with &lt;strong&gt;HackerRank/CodeSignal&lt;/strong&gt; especially early on or if a target company uses them (for environment familiarity). Use &lt;strong&gt;GeeksforGeeks/InterviewBit&lt;/strong&gt; if you want guided topic-wise questions or need to read up on theory. And if time permits or you’re aiming for top competitive roles, sprinkling in some &lt;strong&gt;Codeforces&lt;/strong&gt; hard problems can boost your skills beyond the typical. Each platform has its strengths – choose what keeps you engaged while addressing your weak points.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Credible Source References:&lt;/strong&gt; The recommendations and strategies above are synthesized from numerous reputable sources: academic course content, algorithm textbooks, experienced engineers’ advice, and top competitive programmers’ insights. For instance, techniques for long-term retention are backed by learning science (as seen in Barbara Oakley’s popular course and summarized by dev.to (&lt;a href="https://dev.to/codebalance/upgrade-your-learning-an-example-study-plan-for-data-structures-and-algorithms-5he#:~:text=,no%20matter%20where%20you%20are"&gt;Upgrade your learning + an example study plan for data structures and algorithms - DEV Community&lt;/a&gt;)). The study plan draws from university curricula and proven guides like the Tech Interview Handbook (which emphasizes a 3-month plan and topic prioritization (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=months%20,More" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=%23%23%20Weeks%201,and%20practice" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;)). The problem lists per topic align with well-known interview question sets (e.g. “Blind 75” (&lt;a href="https://dwf.dev/docs/learning-resources/tech-interview-handbook#:~:text=,Maximum%20Subarray" rel="noopener noreferrer"&gt;Tech Interview Handbook | Software Engineering Handbook&lt;/a&gt;) and Grokking patterns), and each listed practice problem is a real interview or competitive problem verified on platforms like LeetCode (with difficulty tags as stated). By following this structured approach and utilizing these resources, a self-taught programmer can efficiently gain and retain DSA knowledge, and be well-equipped for technical interviews (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=And%20to%20summarize%20the%20most,will%20also%20have%20similar%20expectations" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;) (&lt;a href="https://forum.freecodecamp.org/t/what-is-your-strategy-for-learning-data-structures-and-algorithms/86995#:~:text=,Greedy%20algorithms" rel="noopener noreferrer"&gt;What is your strategy for learning data structures and algorithms? - The freeCodeCamp Forum&lt;/a&gt;).&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>algorithms</category>
      <category>java</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Day 2: Common Time Complexities</title>
      <dc:creator>Kartik Sharma</dc:creator>
      <pubDate>Sun, 08 Sep 2024 14:20:58 +0000</pubDate>
      <link>https://forem.com/kartikdevsharma/day-2-common-time-complexities-4lb2</link>
      <guid>https://forem.com/kartikdevsharma/day-2-common-time-complexities-4lb2</guid>
      <description>&lt;h4&gt;
  
  
  Deep Dive into Common Time Complexities
&lt;/h4&gt;

&lt;p&gt;Time complexity gives an idea of how an algorithm's runtime increases as the input size increases. Let’s break down the most common time complexities and analyze examples for each.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. &lt;strong&gt;O(1) – Constant Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;An algorithm with O(1) time complexity takes a constant amount of time to execute, regardless of the input size.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Accessing an element in an array by its index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// O(1)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accessing any element in an array by index is constant-time because the operation doesn't depend on the number of elements in the array.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. &lt;strong&gt;O(log n) – Logarithmic Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Logarithmic time complexity often arises in algorithms that divide the problem into smaller sub-problems at each step. One common example is &lt;strong&gt;binary search&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Binary search in a sorted array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each time we search, the array size is halved. So, the time complexity grows logarithmically with the size of the input array.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. &lt;strong&gt;O(n) – Linear Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In linear time, the runtime grows in direct proportion to the input size. If the input size doubles, the runtime doubles.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Looping through all elements in an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The algorithm goes through each element once, so the runtime increases linearly with the number of elements (&lt;code&gt;n&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. &lt;strong&gt;O(n log n) – Linearithmic Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;O(n log n) is a combination of linear and logarithmic time complexities. This complexity commonly appears in efficient sorting algorithms like &lt;strong&gt;Merge Sort&lt;/strong&gt; and &lt;strong&gt;Quick Sort&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Merge Sort (Divide and Conquer):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;leftIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rightIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rightIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
      &lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
      &lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leftIndex&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rightIndex&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The array is split in half in each recursive call (logarithmic division), and each split involves merging all elements, which is linear, resulting in O(n log n).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. &lt;strong&gt;O(n²) – Quadratic Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Quadratic time complexity occurs when there are nested loops where each iteration goes over &lt;code&gt;n&lt;/code&gt; elements. As the input size increases, the runtime grows quadratically.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Bubble Sort (Brute force sorting algorithm):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bubbleSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Swap elements&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The nested loops both iterate through &lt;code&gt;n&lt;/code&gt; elements, so the time complexity is O(n²). For larger input sizes, this becomes inefficient.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  6. &lt;strong&gt;O(2ⁿ) – Exponential Time Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Exponential time complexity occurs when the algorithm’s growth doubles with each additional element in the input data. Algorithms with this time complexity become impractical for large inputs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Solving the &lt;strong&gt;Tower of Hanoi&lt;/strong&gt; problem (recursive solution):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;towerOfHanoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;from_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;to_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;aux_rod&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Move disk 1 from rod &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;from_rod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to rod &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;to_rod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;towerOfHanoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;from_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;aux_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;to_rod&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Move disk &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; from rod &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;from_rod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to rod &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;to_rod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;towerOfHanoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;aux_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;to_rod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;from_rod&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each recursive call leads to two more recursive calls, resulting in a doubling of work at each step, leading to an exponential growth rate O(2ⁿ).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Introduction to Space Complexity
&lt;/h3&gt;

&lt;p&gt;Space complexity refers to the amount of memory an algorithm uses as it runs. Like time complexity, it helps us understand how efficiently an algorithm scales with input size.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Points:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Auxiliary space&lt;/strong&gt;: Memory used by an algorithm apart from the input size. For example, temporary variables, recursive call stack, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Input space&lt;/strong&gt;: Memory used to store the input data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Differences Between Time and Space Complexity
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Time Complexity&lt;/th&gt;
&lt;th&gt;Space Complexity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Definition&lt;/td&gt;
&lt;td&gt;Amount of time an algorithm takes to execute&lt;/td&gt;
&lt;td&gt;Amount of memory an algorithm uses&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Purpose&lt;/td&gt;
&lt;td&gt;Focuses on the runtime performance&lt;/td&gt;
&lt;td&gt;Focuses on memory usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Measured by&lt;/td&gt;
&lt;td&gt;Number of operations or steps&lt;/td&gt;
&lt;td&gt;Amount of memory used (in bytes, variables)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Example (Merge Sort)&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n) due to auxiliary arrays in merge process&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primary Use Case&lt;/td&gt;
&lt;td&gt;Evaluating performance for large inputs&lt;/td&gt;
&lt;td&gt;Checking memory efficiency for large datasets&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Example: Time vs Space Complexity in Merge Sort
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n log n) due to recursive splitting and merging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity&lt;/strong&gt;: O(n) because it needs extra memory to hold the left and right subarrays during the merge phase.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. Sorting Algorithms: Implementation and Analysis
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Bubble Sort (O(n²))&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Bubble Sort repeatedly swaps adjacent elements if they are in the wrong order. It has a time complexity of O(n²) because of its nested loops.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bubbleSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n²)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity&lt;/strong&gt;: O(1) (no extra space is needed beyond input array)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Selection Sort (O(n²))&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Selection Sort repeatedly finds the minimum element from the unsorted part and puts it at the beginning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;selectionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;minIdx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;minIdx&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;minIdx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;minIdx&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;minIdx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n²)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity&lt;/strong&gt;: O(1) (in-place sorting)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Insertion Sort (O(n²))&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Insertion Sort builds the sorted array one element at a time by comparing the current element with the already sorted part of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n²)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity&lt;/strong&gt;: O(1) (in-place sorting)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. Complete Online Quiz on Time Complexities
&lt;/h3&gt;

&lt;p&gt;To reinforce your learning, try taking online quizzes to identify time complexities for various algorithms. You can look for quizzes on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HackerRank&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LeetCode&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GeeksforGeeks&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These platforms provide real coding problems and quizzes that help you practice and solidify your understanding of time complexities.&lt;/p&gt;




&lt;h3&gt;
  
  
  Summary:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time complexities&lt;/strong&gt; range from O(1) (constant) to O(2ⁿ) (exponential), with linear and quadratic complexities being the most commonly encountered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space complexity&lt;/strong&gt; measures the memory requirements of algorithms and is crucial in applications with limited memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorting algorithms&lt;/strong&gt; like bubble, selection, and insertion sort have a quadratic time complexity (O(n²)), making them inefficient for large inputs.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Day 1: Introduction to Algorithmic Complexity</title>
      <dc:creator>Kartik Sharma</dc:creator>
      <pubDate>Sat, 07 Sep 2024 15:53:34 +0000</pubDate>
      <link>https://forem.com/kartikdevsharma/day-1-introduction-to-algorithmic-complexity-48pc</link>
      <guid>https://forem.com/kartikdevsharma/day-1-introduction-to-algorithmic-complexity-48pc</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2bw8yfeqewvbras619.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2bw8yfeqewvbras619.png" alt="Image description" width="800" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Introduction to Algorithmic Complexity
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is Algorithmic Complexity?
&lt;/h4&gt;

&lt;p&gt;Algorithmic complexity refers to how the performance of an algorithm changes with the size of its input. It's a measure of efficiency that helps us understand the resources an algorithm needs (time and space) to solve a problem. Two main resources are considered:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Time complexity&lt;/strong&gt; – how the runtime of an algorithm grows with the input size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space complexity&lt;/strong&gt; – how much memory an algorithm requires as the input size increases.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why is Algorithmic Complexity Important?
&lt;/h4&gt;

&lt;p&gt;In real-world scenarios, input sizes can be huge, so we want our programs to handle these efficiently. By analyzing an algorithm’s complexity, we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Predict performance&lt;/strong&gt; – Know how an algorithm behaves as the problem size increases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize code&lt;/strong&gt; – Find and implement the most efficient algorithms to solve a problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compare algorithms&lt;/strong&gt; – Evaluate different algorithms to choose the best one based on their performance and resources used.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, you might have two algorithms that solve the same problem, but one might take 1 second for a given input size, while another takes 10 seconds or even an hour for larger inputs. Understanding complexity helps us avoid slower algorithms in production systems.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Importance of Efficiency in Programming
&lt;/h3&gt;

&lt;p&gt;Efficiency in programming isn’t just about writing code that "works," but writing code that scales well, both in terms of time (how fast it runs) and space (how much memory it uses).&lt;/p&gt;

&lt;h4&gt;
  
  
  Why does efficiency matter?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-world performance&lt;/strong&gt;: When handling large datasets (like millions of users or large databases), inefficient algorithms can lead to slow applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Efficient code scales better as input sizes grow. An algorithm that takes 1 second for 1,000 inputs might take several hours for a billion inputs if it’s inefficient.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost&lt;/strong&gt;: Inefficient algorithms can consume more memory and processing power, increasing costs for cloud-based applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User experience&lt;/strong&gt;: Fast algorithms provide a better user experience, especially in applications like search engines, data analytics, and real-time systems.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  3. Big O Notation Basics
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is Big O Notation?
&lt;/h4&gt;

&lt;p&gt;Big O notation is a mathematical concept used to describe the worst-case time complexity of an algorithm. It expresses how the runtime or space requirements of an algorithm grow as the input size increases. It provides a high-level understanding of the efficiency of an algorithm.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Focus on growth&lt;/strong&gt;: Big O notation ignores constants and lower-order terms, focusing only on how the algorithm scales as input size grows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Common Big O Time Complexities:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;O(1) - Constant time&lt;/strong&gt;: The algorithm's runtime doesn't change regardless of the input size.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: Accessing an element in an array by index.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;O(n) - Linear time&lt;/strong&gt;: The runtime grows linearly with the input size.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: A loop that iterates through all &lt;code&gt;n&lt;/code&gt; elements of an array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;O(n²) - Quadratic time&lt;/strong&gt;: The runtime grows quadratically with the input size.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: A nested loop where each element is compared with every other element (like a basic sorting algorithm).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;O(log n) - Logarithmic time&lt;/strong&gt;: The runtime grows logarithmically as the input size increases. Common in algorithms that repeatedly halve the problem, such as binary search.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: Searching in a sorted array using binary search.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;O(n log n)&lt;/strong&gt;: Common in more efficient sorting algorithms, such as Merge Sort and Quick Sort.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why Big O?
&lt;/h4&gt;

&lt;p&gt;Big O allows us to abstract away details like the number of lines of code and focus on how an algorithm’s efficiency scales as inputs increase. It helps us make quick decisions about whether an algorithm will work for large inputs.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Best-case, Average-case, and Worst-case Scenarios
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What do these terms mean?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best-case complexity&lt;/strong&gt;: The behavior of the algorithm when it performs the minimum possible work. For example, in a sorting algorithm, the best-case might occur when the input is already sorted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Average-case complexity&lt;/strong&gt;: The expected behavior over all possible inputs. This gives a realistic idea of how the algorithm will perform most of the time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst-case complexity&lt;/strong&gt;: The behavior of the algorithm when it performs the maximum amount of work. This gives an upper bound on how the algorithm performs under the most challenging circumstances.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Examples:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Linear Search&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Best case&lt;/strong&gt;: O(1) – If the target element is the first element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Worst case&lt;/strong&gt;: O(n) – If the target element is the last or not present.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Average case&lt;/strong&gt;: O(n) – On average, the target will be found midway through the array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;QuickSort&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Best case&lt;/strong&gt;: O(n log n) – When the pivot divides the array into equal halves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Worst case&lt;/strong&gt;: O(n²) – When the pivot is always the smallest or largest element, resulting in uneven division.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why focus on worst-case?
&lt;/h4&gt;

&lt;p&gt;Worst-case analysis is important because it tells us how bad the performance of an algorithm can get. In critical systems, we often want to design for the worst possible scenario.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Simple Time Complexities: Constant and Linear
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Constant Time – O(1):
&lt;/h4&gt;

&lt;p&gt;An algorithm takes constant time if the amount of work it does does not depend on the size of the input. Regardless of whether the input has 1 element or 1 million elements, the runtime remains the same.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printFirstElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This algorithm always takes the same amount of time to print the first element, no matter how large the array is.&lt;/p&gt;

&lt;h4&gt;
  
  
  Linear Time – O(n):
&lt;/h4&gt;

&lt;p&gt;An algorithm takes linear time if its runtime grows in direct proportion to the size of the input. If the input size doubles, the runtime will also double.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printAllElements&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This algorithm’s runtime grows as the number of elements in the array increases.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. Chapter 1 of "Introduction to Algorithms" by Cormen et al.
&lt;/h3&gt;

&lt;p&gt;The first chapter of Cormen’s &lt;em&gt;Introduction to Algorithms&lt;/em&gt; is a general introduction to algorithms. It defines what an algorithm is and gives the reader an understanding of the formal way to represent and analyze algorithms.&lt;/p&gt;

&lt;p&gt;Topics Covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What is an algorithm?&lt;/strong&gt;: A sequence of steps or rules for solving a problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The role of algorithms in computing&lt;/strong&gt;: Algorithms form the foundation of all computing processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Different types of algorithms&lt;/strong&gt;: Sorting, searching, graph traversal, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Formal vs informal definitions&lt;/strong&gt;: Cormen introduces both formal and informal ways to describe algorithms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance of asymptotic analysis&lt;/strong&gt;: A more formal introduction to how we analyze algorithms in terms of time and space complexities (leading into Big O notation).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  7. Practice Problems: Complexity Analysis
&lt;/h3&gt;

&lt;p&gt;Solve the following problems to practice identifying algorithmic complexity:&lt;/p&gt;

&lt;h4&gt;
  
  
  Problem 1:
&lt;/h4&gt;

&lt;p&gt;Given an array of size &lt;code&gt;n&lt;/code&gt;, write an algorithm to find the maximum element. What is the time complexity?&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;findMax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time complexity: O(n) – You need to iterate through all elements to find the maximum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Problem 2:
&lt;/h4&gt;

&lt;p&gt;Write an algorithm to print the first 100 elements of an array. What is the time complexity?&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printFirst100&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time complexity: O(1) – Constant time, since it prints a maximum of 100 elements, regardless of the size of the input.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Problem 3:
&lt;/h4&gt;

&lt;p&gt;Write a function to check if a number exists in a sorted array using binary search. What is the time complexity?&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time complexity: O(log n) – Since binary search halves the array at each step.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Problem 4:
&lt;/h4&gt;

&lt;p&gt;Find the complexity of the following function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time complexity: O(n²) – Two nested loops iterate over &lt;code&gt;n&lt;/code&gt; elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Problem 5:
&lt;/h4&gt;

&lt;p&gt;Write an algorithm to reverse a string. What is the time complexity?&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reverseString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time complexity: O(n) – The algorithm goes through all characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;in the string.&lt;/p&gt;




&lt;p&gt;By understanding algorithmic complexity, you can improve the efficiency of your code. Big O notation provides a framework to analyze how well an algorithm will perform as the size of the input grows. Practicing with simple examples like linear search, maximum finding, and string reversal can strengthen your understanding of algorithm analysis basics.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The 12-Factor App Methodology</title>
      <dc:creator>Kartik Sharma</dc:creator>
      <pubDate>Sun, 07 Jul 2024 13:59:25 +0000</pubDate>
      <link>https://forem.com/kartikdevsharma/the-12-factor-app-methodology-32f1</link>
      <guid>https://forem.com/kartikdevsharma/the-12-factor-app-methodology-32f1</guid>
      <description>&lt;h2&gt;
  
  
  The 12-Factor App Methodology: A Blueprint for Modern Software Development
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.netsolutions.com%2Finsights%2Fwp-content%2Fuploads%2F2021%2F02%2Fwhat-is-the-12-factor-app-methodology.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.netsolutions.com%2Finsights%2Fwp-content%2Fuploads%2F2021%2F02%2Fwhat-is-the-12-factor-app-methodology.jpg" alt="12-Factor App Banner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;
The Twelve Factors

&lt;ol&gt;
&lt;li&gt;Codebase&lt;/li&gt;
&lt;li&gt;Dependencies&lt;/li&gt;
&lt;li&gt;Config&lt;/li&gt;
&lt;li&gt;Backing Services&lt;/li&gt;
&lt;li&gt;Build, Release, Run&lt;/li&gt;
&lt;li&gt;Processes&lt;/li&gt;
&lt;li&gt;Port Binding&lt;/li&gt;
&lt;li&gt;Concurrency&lt;/li&gt;
&lt;li&gt;Disposability&lt;/li&gt;
&lt;li&gt;Dev/Prod Parity&lt;/li&gt;
&lt;li&gt;Logs&lt;/li&gt;
&lt;li&gt;Admin Processes&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;Benefits of the 12-Factor App Methodology&lt;/li&gt;

&lt;/ol&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the ever-evolving landscape of software development, the 12-Factor App methodology stands as a beacon of best practices for building modern, scalable, and maintainable software-as-a-service (SaaS) applications. Conceived by the developers at Heroku, this methodology distills their experience with a multitude of SaaS applications into twelve core principles.&lt;/p&gt;

&lt;p&gt;These principles are designed to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhance portability between execution environments&lt;/li&gt;
&lt;li&gt;Facilitate continuous deployment for maximum agility&lt;/li&gt;
&lt;li&gt;Scale up without significant changes to tooling, architecture, or development practices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we delve into each factor, we'll explore how these guidelines can transform your approach to software development, making your applications more robust, flexible, and cloud-ready.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Twelve Factors
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Codebase
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;One codebase tracked in revision control, many deploys&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.prod.website-files.com%2F60c912417dc3bac5c9fa2616%2F60f5fefb1dfee7c63297975f_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.prod.website-files.com%2F60c912417dc3bac5c9fa2616%2F60f5fefb1dfee7c63297975f_image.png" alt="Codebase Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The foundation of any 12-factor app is a single codebase, tracked in a version control system like Git. This codebase is unique to each application but can be deployed to multiple environments such as development, staging, and production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a distributed version control system (e.g., Git, Mercurial)&lt;/li&gt;
&lt;li&gt;Maintain a single repository per app&lt;/li&gt;
&lt;li&gt;Utilize branches for feature development and bug fixes&lt;/li&gt;
&lt;li&gt;Implement a clear branching strategy (e.g., GitFlow, GitHub Flow)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Regularly commit changes&lt;/li&gt;
&lt;li&gt;Use meaningful commit messages&lt;/li&gt;
&lt;li&gt;Implement code reviews before merging to main branches&lt;/li&gt;
&lt;li&gt;Automate deployments from the version control system&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. Dependencies
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Explicitly declare and isolate dependencies&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a 12-factor app, dependencies are declared explicitly and in a consistent manner. This approach ensures that your application can be reliably reproduced across different environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dependency declaration manifest&lt;/li&gt;
&lt;li&gt;Dependency isolation&lt;/li&gt;
&lt;li&gt;System-wide packages avoidance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementation strategies:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use language-specific dependency management tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python: &lt;code&gt;requirements.txt&lt;/code&gt; with &lt;code&gt;pip&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;JavaScript: &lt;code&gt;package.json&lt;/code&gt; with &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Ruby: &lt;code&gt;Gemfile&lt;/code&gt; with Bundler&lt;/li&gt;
&lt;li&gt;Java: &lt;code&gt;pom.xml&lt;/code&gt; with Maven or &lt;code&gt;build.gradle&lt;/code&gt; with Gradle&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Utilize virtual environments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python: &lt;code&gt;venv&lt;/code&gt; or &lt;code&gt;virtualenv&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Node.js: &lt;code&gt;nvm&lt;/code&gt; (Node Version Manager)&lt;/li&gt;
&lt;li&gt;Ruby: &lt;code&gt;rvm&lt;/code&gt; (Ruby Version Manager)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Containerization:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker for isolating the entire application environment&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example &lt;code&gt;requirements.txt&lt;/code&gt; for a Python project:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flask==2.0.1
SQLAlchemy==1.4.23
gunicorn==20.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By explicitly declaring dependencies, you ensure that your application can be easily set up on any machine, reducing the "it works on my machine" syndrome and facilitating easier onboarding for new developers.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Config
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Store config in the environment&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Configuration that varies between deployments should be stored in the environment, not in the code. This separation of config from code is crucial for maintaining security and flexibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of config:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resource handles to backing services&lt;/li&gt;
&lt;li&gt;Credentials for external services&lt;/li&gt;
&lt;li&gt;Per-deploy values (e.g., canonical hostname)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use environment variables for config&lt;/li&gt;
&lt;li&gt;Never commit sensitive information to version control&lt;/li&gt;
&lt;li&gt;Group config variables into a single, versioned file for each environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example using environment variables in a Node.js application:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;db&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_HOST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_PASS&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tools for managing environment variables:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dotenv: For local development&lt;/li&gt;
&lt;li&gt;Kubernetes ConfigMaps and Secrets: For container orchestration&lt;/li&gt;
&lt;li&gt;AWS Parameter Store: For AWS deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By adhering to this factor, you can easily deploy your application to different environments without code changes, enhancing both security and flexibility.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Backing Services
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Treat backing services as attached resources&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A backing service is any service that the app consumes over the network as part of its normal operation. Examples include databases, message queues, caching systems, and external APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No distinction between local and third-party services&lt;/li&gt;
&lt;li&gt;Services are attached and detached via config&lt;/li&gt;
&lt;li&gt;Swapping out a backing service should require no code changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common backing services:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Databases (MySQL, PostgreSQL, MongoDB)&lt;/li&gt;
&lt;li&gt;Caching systems (Redis, Memcached)&lt;/li&gt;
&lt;li&gt;Message queues (RabbitMQ, Apache Kafka)&lt;/li&gt;
&lt;li&gt;SMTP services for email delivery&lt;/li&gt;
&lt;li&gt;External storage services (Amazon S3, Google Cloud Storage)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Switching databases in a Ruby on Rails application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Production database&lt;/span&gt;
&lt;span class="ss"&gt;production:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
  &lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DATABASE_URL'] %&amp;gt;

# Development database
development:
  adapter: sqlite3
  database: db/development.sqlite3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By treating backing services as attached resources, you gain the flexibility to easily swap services without code changes, facilitating easier scaling and maintenance.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Build, Release, Run
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Strictly separate build and run stages&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 12-factor app uses strict separation between the build, release, and run stages. This separation enables better management of the application lifecycle and facilitates continuous deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stages:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Build stage&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts code repo into an executable bundle&lt;/li&gt;
&lt;li&gt;Fetches and vendors dependencies&lt;/li&gt;
&lt;li&gt;Compiles binary assets and preprocesses scripts&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Release stage&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes the build and combines it with the deploy's current config&lt;/li&gt;
&lt;li&gt;Results in a release that's ready for immediate execution&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Run stage&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs the app in the execution environment&lt;/li&gt;
&lt;li&gt;Launches the app's processes against a selected release&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enables rollback to previous releases&lt;/li&gt;
&lt;li&gt;Clear separation of concerns&lt;/li&gt;
&lt;li&gt;Improved traceability and auditability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example workflow:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;graph LR
    A[Code] --&amp;gt; B[Build]
    B --&amp;gt; C[Release]
    D[Config] --&amp;gt; C
    C --&amp;gt; E[Run]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implementing this strict separation allows for more robust application management and easier troubleshooting when issues arise.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. Processes
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Execute the app as one or more stateless processes&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the 12-factor methodology, applications are executed as one or more stateless processes. This approach enhances scalability and simplifies the overall architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes are stateless and share-nothing&lt;/li&gt;
&lt;li&gt;Any necessary state is stored in a backing service (e.g., database)&lt;/li&gt;
&lt;li&gt;Memory or filesystem can be used as a brief, single-transaction cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Horizontal scalability&lt;/li&gt;
&lt;li&gt;Resilience to unexpected process terminations&lt;/li&gt;
&lt;li&gt;Simplified deployment and management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Stateless vs. Stateful Session Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stateful (Not 12-factor compliant):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secret_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;your_secret_key&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Session data stored&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/user&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;User ID: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Stateless (12-factor compliant):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6379&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Data stored in Redis&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/user&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;User ID: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adhering to the stateless process model, your application becomes more resilient and easier to scale horizontally.&lt;/p&gt;




&lt;h3&gt;
  
  
  7. Port Binding
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Export services via port binding&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;12-factor apps are completely self-contained and do not rely on runtime injection of a webserver into the execution environment. The web app exports HTTP as a service by binding to a port and listening to requests coming in on that port.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App is self-contained&lt;/li&gt;
&lt;li&gt;Exports HTTP as a service by binding to a port&lt;/li&gt;
&lt;li&gt;Uses a webserver library or tool as part of the app's code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Port binding in a Node.js application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, 12-Factor App!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`App listening at http://localhost:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility in deployment&lt;/li&gt;
&lt;li&gt;One app can become the backing service for another&lt;/li&gt;
&lt;li&gt;Easy local development without additional dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By implementing port binding, your application gains independence from web servers, making it more portable and easier to deploy in various environments.&lt;/p&gt;




&lt;h3&gt;
  
  
  8. Concurrency
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Scale out via the process model&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 12-factor app recommends scaling applications horizontally through the process model. This approach allows the app to handle diverse workloads efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes are first-class citizens&lt;/li&gt;
&lt;li&gt;Developer can architect their app to handle diverse workloads&lt;/li&gt;
&lt;li&gt;Never daemonize or write PID files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Concurrency models:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Process-based&lt;/strong&gt;: Multiple instances of the same application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread-based&lt;/strong&gt;: Multiple threads within a single process&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid&lt;/strong&gt;: Combination of processes and threads&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example: Process-based concurrency with Gunicorn (Python)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gunicorn &lt;span class="nt"&gt;--workers&lt;/span&gt; 4 &lt;span class="nt"&gt;--bind&lt;/span&gt; 0.0.0.0:8000 myapp:app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improved resource utilization&lt;/li&gt;
&lt;li&gt;Better fault isolation&lt;/li&gt;
&lt;li&gt;Easier scaling and load balancing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By embracing the process model for concurrency, your application can efficiently scale to handle increased load and diverse workloads.&lt;/p&gt;




&lt;h3&gt;
  
  
  9. Disposability
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Maximize robustness with fast startup and graceful shutdown&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;12-factor apps are designed to be started or stopped at a moment's notice. This disposability enhances the app's robustness and flexibility in a dynamic environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key aspects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimize startup time&lt;/li&gt;
&lt;li&gt;Shut down gracefully when receiving a SIGTERM signal&lt;/li&gt;
&lt;li&gt;Handle unexpected terminations robustly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use lightweight containers or serverless platforms&lt;/li&gt;
&lt;li&gt;Implement health checks&lt;/li&gt;
&lt;li&gt;Use queues for long-running tasks&lt;/li&gt;
&lt;li&gt;Implement proper exception handling and logging&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example: Graceful shutdown in a Node.js application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// ... app setup ...&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App is running on port 3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SIGTERM&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SIGTERM signal received: closing HTTP server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;HTTP server closed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By ensuring your application is disposable, you improve its resilience in the face of failures and its ability to scale rapidly in response to changing demands.&lt;/p&gt;




&lt;h3&gt;
  
  
  10. Dev/Prod Parity
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Keep development, staging, and production as similar as possible&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 12-factor methodology emphasizes maintaining similarity between development, staging, and production environments. This parity reduces the risk of unforeseen issues in production and simplifies the development process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key dimensions of parity:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Time&lt;/strong&gt;: Minimize time between development and production deployment&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Personnel&lt;/strong&gt;: Developers who write code should be involved in deploying it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tools&lt;/strong&gt;: Keep development and production tools as similar as possible&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Strategies for achieving dev/prod parity:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use containerization (e.g., Docker) to ensure consistent environments&lt;/li&gt;
&lt;li&gt;Implement Infrastructure as Code (IaC) for consistent provisioning&lt;/li&gt;
&lt;li&gt;Use feature flags to manage differences between environments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Using Docker for environment parity&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Dockerfile&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:14&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package*.json ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["npm", "start"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduced risk of environment-specific bugs&lt;/li&gt;
&lt;li&gt;Faster, more reliable deployments&lt;/li&gt;
&lt;li&gt;Improved developer productivity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By maintaining dev/prod parity, you create a more streamlined development process and reduce the likelihood of unexpected issues in production.&lt;/p&gt;




&lt;h3&gt;
  
  
  11. Logs
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Treat logs as event streams&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the 12-factor methodology, logs are treated as event streams, providing valuable insights into the behavior of running applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App never concerns itself with routing or storage of its output stream&lt;/li&gt;
&lt;li&gt;Logs are written to stdout&lt;/li&gt;
&lt;li&gt;Archival and analysis are handled by the execution environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Logging best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use structured logging formats (e.g., JSON)&lt;/li&gt;
&lt;li&gt;Include relevant contextual information in log entries&lt;/li&gt;
&lt;li&gt;Use log levels appropriately (DEBUG, INFO, WARN, ERROR)&lt;/li&gt;
&lt;li&gt;Avoid writing logs to files within the application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example: Structured logging in Python using &lt;code&gt;structlog&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;structlog&lt;/span&gt;

&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;structlog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_logger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Processing order&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Process the order
&lt;/span&gt;    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Order processed successfully&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;process_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;12345&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;99.99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easier log aggregation and analysis&lt;/li&gt;
&lt;li&gt;Improved debugging and troubleshooting&lt;/li&gt;
&lt;li&gt;Better visibility into application behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By treating logs as event streams, you gain valuable insights into your application's behavior and performance, facilitating easier debugging and monitoring.&lt;/p&gt;




&lt;h3&gt;
  
  
  12. Admin Processes
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Run admin/management tasks as one-off processes&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 12-factor app recommends running administrative or management tasks as one-off processes, ensuring they run in an identical environment to the regular long-running processes of the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of admin processes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database migrations&lt;/li&gt;
&lt;li&gt;One-time scripts&lt;/li&gt;
&lt;li&gt;Console (REPL) for running arbitrary code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ship admin code with application code&lt;/li&gt;
&lt;li&gt;Use the same release for admin processes and regular processes&lt;/li&gt;
&lt;li&gt;Use the same dependency isolation techniques for admin code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example: Database migration script in a Ruby on Rails application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# db/migrate/20210901000000_create_users.rb&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;6.1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;change&lt;/span&gt;
    &lt;span class="n"&gt;create_table&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:name&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timestamps&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Running the migration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistency between admin tasks and regular app processes&lt;/li&gt;
&lt;li&gt;Reduced risk of environment-specific issues&lt;/li&gt;
&lt;li&gt;Easier management and tracking of administrative actions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By running admin processes as one-off tasks in the same environment as your application, you ensure consistency and reduce the risk of environment-specific issues.&lt;/p&gt;




&lt;h2&gt;
  
  
  Benefits of the 12-Factor App Methodology
&lt;/h2&gt;

&lt;p&gt;Adopting the 12-Factor App methodology brings numerous advantages to modern software development:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Portability&lt;/strong&gt;: Apps can be easily moved between execution environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: The methodology naturally supports horizontal scaling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability&lt;/strong&gt;: Clear separation of concerns makes&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>devops</category>
      <category>productivity</category>
      <category>learning</category>
      <category>development</category>
    </item>
  </channel>
</rss>
