Essential DSA u0026 SQL Interview Fundamentals Quiz

This quiz focuses on frequently asked Data Structures, Algorithms (DSA), and SQL questions seen in real-world technical interviews for software developers. Strengthen your core understanding of arrays, stacks, recursion, joins, query writing, and data problem-solving with concepts relevant to today’s hiring trends.

  1. Array Indexing

    In an array of 10 elements indexed from 0, what is the correct index to access the sixth element?

    1. 5
    2. 6
    3. 10
    4. 4

    Explanation: Arrays indexed from 0 mean the first element is at index 0, the second at index 1, and so on. Therefore, the sixth element is at index 5. Option 6 refers to the seventh element, while 4 is the fifth element, and 10 is outside the valid index range.

  2. Time Complexity - Searching

    What is the time complexity of searching for a value in an unsorted array of n elements?

    1. O(n log n)
    2. O(1)
    3. O(log n)
    4. O(n)

    Explanation: Searching an unsorted array requires checking each element one by one, leading to O(n) time. O(1) is possible only with indexed structures, O(log n) is typical for binary search in sorted arrays, and O(n log n) doesn't apply to basic search operations.

  3. Stack Usage

    Which data structure is best suited for tracking function calls in recursive algorithms?

    1. Heap
    2. Stack
    3. Queue
    4. Graph

    Explanation: A stack follows Last In, First Out (LIFO), making it ideal for managing recursion where each function call returns before its caller. Queues use First In, First Out (FIFO), heaps are for priority-based tasks, and graphs are structures to represent networks, not call sequences.

  4. SQL SELECT Syntax

    Which SQL statement returns the names from a 'students' table?

    1. SELECT students FROM name;
    2. SELECT name FROM students;
    3. GET name OUT OF students;
    4. PICK name FROM students;

    Explanation: The correct SQL syntax is 'SELECT column FROM table;'. The other options are not valid SQL syntax—'GET', 'PICK', and switched order of SELECT are incorrect.

  5. Primary Key Purpose

    What is the main purpose of a primary key in a database table?

    1. To store duplicate data
    2. To speed up queries
    3. To uniquely identify each row
    4. To link tables together

    Explanation: A primary key uniquely identifies every record, ensuring no duplicates. While foreign keys link tables, indexes speed up queries, and primary keys cannot store duplicate data.

  6. Recursion Example

    Which scenario best demonstrates recursion?

    1. Sorting using an iterative loop
    2. Retrieving data using a queue
    3. A function calling itself to calculate factorial
    4. Storing values in a stack

    Explanation: Recursion involves a function calling itself, as in finding the factorial. Iterative loops do not use self-calls. Stacks and queues are data structures, not function-call behaviors.

  7. SQL JOIN Usage

    Which SQL JOIN returns only the records with matching values in both joined tables?

    1. LEFT JOIN
    2. INNER JOIN
    3. RIGHT JOIN
    4. OUTER JOIN

    Explanation: INNER JOIN yields rows present in both tables with matching join keys. LEFT JOIN and RIGHT JOIN return unmatched rows from one table, while OUTER JOIN is a general term for combining matching and non-matching records.

  8. Queue Application

    A printer processes print jobs in the order they are received. Which data structure is most appropriate for this scenario?

    1. Queue
    2. Heap
    3. Stack
    4. Tree

    Explanation: A queue suits First In, First Out (FIFO) order, just like a printer job queue. Stacks use LIFO, heaps prioritize based on values rather than order, and trees represent hierarchical data rather than ordered processing.

  9. Finding Highest Salary Per Department

    Which SQL keyword helps find the highest salary in each department from an 'employees' table?

    1. INSERT INTO
    2. DROP
    3. GROUP BY
    4. ORDER BY

    Explanation: GROUP BY groups records so aggregate functions like MAX(salary) can be used for each department. ORDER BY sorts results, INSERT INTO adds rows, and DROP removes tables or columns.

  10. Iterative vs Recursive

    What is a key difference between iterative and recursive approaches to solving a problem?

    1. Iteration can only be used with arrays
    2. Recursive approaches call the same function within itself, while iterative approaches use loops
    3. Iterative methods always use more memory than recursion
    4. Recursion provides faster performance than iteration in all cases

    Explanation: Recursion is characterized by a function calling itself until a condition is met, whereas iteration relies on repeated loops. Iteration does not always use more memory; in fact, recursion can require more due to call stack consumption. Neither recursion nor iteration is universally faster. Iteration applies to multiple structures, not just arrays.