Knowledge Guide
HomeDSAFoundations

Quiz (3)

Grokking Algorithm Complexity and Big-O Rate this course Ask Author Contribute Back to course home 0% completed Vote For New Content ​ Introduction Course Overview Basics of Algorithm Analysis Introduction to Algorithm Analysis Measuring Efficiency Functions and Their Growth Rates Asymptotic Notations Overview of Asymptotic Analysis Big-O Notation (O-notation) Big-Omega Notation (Ω-notation) Big-Theta Notation (Θ-notation) Little-o and Little-omega Notations Comparing Asymptotic Notations Time Complexity Analysis Understanding Time Complexity Analyzing Control Structures Analyzing Simple Algorithms Best, Worst, and Average Cases Constant Time: O(1) Linear Time: O(n) Quadratic Time: O(n²) Quiz Space Complexity Analysis Understanding Space Complexity Analyzing Space Complexity of Algorithms Constant Space: O(1) Linear Space: O(n) Quadratic Space: O(n²) Quiz Analyzing Recursive Algorithms Introduction to Recursion Recursion Tree Method Recurrence Relation Method Master Theorem Method Space Complexity Analysis of Recursive Algorithm Logarithmic Time and Space: O(log n) Linearithmic Time: O(n log n) Exponential Time and Space: O(2ⁿ) Quiz Data Structures and Complexity Analysis Array Linked List Hash Table and Set Stack and Queue Binary Search Tree Quiz Practical Applications and Case Studies Sorting Algorithms Graph Algorithms Dynamic Programming Algorithms Coding Interview Problems Trade-offs in Algorithm Design Quiz Question 1 What is the time complexity of the following recursive function? public void printNumbers(int n) { if (n == 0) return; System.out.println(n); printNumbers(n - 1); } A O(1) B O(n) C O(n 2 ) D O(log n) Question 2 What is the space complexity of the following recursive function? public int factorial(int n) { if (n == 0) return 1; return n * factorial(n - 1); } A O(1) B O(log n) C O(n) D O(n 2 ) Question 3 Analyze the time complexity of the following code: public int fibonacci(int n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } A O(n) B O(n 2 ) C O(2 n ) D O(log n) Question 4 What is the space complexity of the following recursive function using memoization? import java.util.HashMap; public class Solution { private HashMap<Integer, Integer> memo = new HashMap<>(); public int fib(int n) { if (n <= 1) return n; if (memo.containsKey(n)) return memo.get(n); int result = fib(n - 1) + fib(n - 2); memo.put(n, result); return result; } } A O(1) B O(n log n) C O(n 2 ) D O(n) Question 5 What is the time complexity of the following recursive function? public void nestedRecursion(int n) { if (n <= 0) return; nestedRecursion(n - 1); nestedRecursion(n - 1); } A O(n) B O(2 n ) C O(n 2 ) D O(logn) Question 6 Analyze the space complexity of the following function: public int power(int x, int n) { if (n == 0) return 1; int temp = power(x, n / 2); if (n % 2 == 0) { return temp * temp; } else { return x * temp * temp; } } A O(n) B O(log n) C O(1) D O(n 2 ) Question 7 What is the time complexity of the following recursive function? public void printPattern(int n) { if (n == 0) return; for (int i = 0; i < n; i++) { System.out.print("*"); } System.out.println(); printPattern(n - 1); } A O(n) B O(2 n ) C O(logn) D O(n 2 ) Question 8 What is the time complexity of the following recursive function that calculates the depth of a binary tree? public int sumOfNodes(TreeNode root) { if (root == null) return 0; return root.val + sumOfNodes(root.left) + sumOfNodes(root.right); } A O(n) B O(log n) C O(n 2 ) D O(2 n ) Exponential Time and Space: O(2ⁿ) Array Mark as Completed On this page

🤖 Don't fully get this? Learn it with Claude

Stuck on Quiz (3)? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Quiz (3)** (DSA) and want to truly understand it. Explain Quiz (3) from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Quiz (3)** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Quiz (3)** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Quiz (3)** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes