💻
Programming Medium

Data Structures and Algorithms Basics

A programming test with 15 medium-level questions and answers on data structures and algorithms.

15 Questions
30s Per Question
0+ Plays
← All Programming Quizzes 📚 Study Guide for this category →
💡 Create account to save scores & earn XP
📋 View All 15 Questions & Answers

1. What is the worst-case time complexity of quicksort?

  • A. O(n log n)
  • B. O(n²) ✓
  • C. O(log n)
  • D. O(1)

💡 Quicksort's worst-case time complexity is O(n²), which occurs with poor pivot selection.

2. Which sorting algorithm repeatedly steps through a list, swapping adjacent elements if they are in the wrong order?

  • A. Bubble sort ✓
  • B. Quick sort
  • C. Merge sort
  • D. Heap sort

💡 Bubble sort repeatedly compares and swaps adjacent elements to gradually sort a list.

3. What is a 'queue' data structure?

  • A. A collection that follows First In, First Out (FIFO) order ✓
  • B. A collection that follows Last In, First Out (LIFO) order
  • C. A sorting algorithm
  • D. A type of loop

💡 A queue follows the First In, First Out (FIFO) principle, where the first item added is the first removed.

4. What is a 'stack' data structure?

  • A. A collection that follows Last In, First Out (LIFO) order ✓
  • B. A collection that follows First In, First Out (FIFO) order
  • C. A type of tree
  • D. A type of graph

💡 A stack follows the Last In, First Out (LIFO) principle, where the most recently added item is removed first.

5. What is 'Big O notation' used for?

  • A. Describing the performance or complexity of an algorithm ✓
  • B. Writing comments
  • C. Declaring variables
  • D. Styling code

💡 Big O notation describes how an algorithm's time or space requirements grow relative to input size.

6. What is a 'linked list'?

  • A. A sequence of nodes where each node points to the next ✓
  • B. An array with fixed size
  • C. A type of loop
  • D. A sorting algorithm

💡 A linked list is a data structure made of nodes, each pointing to the next node in the sequence.

7. What is 'recursion' in programming?

  • A. A function that calls itself ✓
  • B. A type of loop
  • C. A sorting algorithm
  • D. A data type

💡 Recursion occurs when a function calls itself to solve smaller instances of the same problem.

8. What is a 'graph' in data structures?

  • A. A collection of nodes connected by edges ✓
  • B. A type of chart
  • C. A sorting algorithm
  • D. A single linked list

💡 A graph is a data structure consisting of nodes (vertices) connected by edges.

9. What is a 'binary tree'?

  • A. A tree data structure where each node has at most two children ✓
  • B. A tree with only one node
  • C. A type of array
  • D. A type of loop

💡 A binary tree is a hierarchical data structure where each node has at most two children.

10. Which sorting algorithm uses a divide-and-conquer approach with O(n log n) average time complexity?

  • A. Merge sort ✓
  • B. Bubble sort
  • C. Selection sort
  • D. Insertion sort

💡 Merge sort divides the array into halves, sorts them recursively, and merges them, achieving O(n log n) average complexity.

11. What is the purpose of a 'hash function'?

  • A. To convert input data into a fixed-size value, typically for indexing ✓
  • B. To sort an array
  • C. To create a loop
  • D. To compile code

💡 A hash function converts input data into a fixed-size output, typically used for indexing in hash tables.

12. What is 'dynamic programming' used for?

  • A. Solving complex problems by breaking them into simpler overlapping subproblems ✓
  • B. Writing dynamic websites
  • C. Creating animations
  • D. Styling applications

💡 Dynamic programming solves complex problems by breaking them into simpler, overlapping subproblems and storing results.

13. What does 'hashing' typically provide in a hash table?

  • A. Fast average-case lookup, insertion, and deletion ✓
  • B. Guaranteed order preservation
  • C. Automatic sorting
  • D. Slower search than a list

💡 Hashing provides fast average-case performance for lookup, insertion, and deletion operations in a hash table.

14. What is the time complexity of accessing an element in an array by index?

  • A. O(1) ✓
  • B. O(log n)
  • C. O(n)
  • D. O(n²)

💡 Accessing an array element by index takes constant time, O(1), since the memory address can be calculated directly.

15. What is the time complexity of searching in a balanced binary search tree?

  • A. O(1)
  • B. O(log n) ✓
  • C. O(n)
  • D. O(n²)

💡 Searching in a balanced binary search tree takes O(log n) time due to its balanced structure.

More Programming Quizzes

View all Programming quizzes →