What are the main collection types in Dart and when do you use each?
List: ordered, indexed, allows duplicates (O(1) access by index). Set: unordered, unique elements (O(1) loo...
15 questions
Algorithms, data structures, complexity, problems
List: ordered, indexed, allows duplicates (O(1) access by index). Set: unordered, unique elements (O(1) loo...
List.sort() sorts in-place using a Comparator<T> function. Implement Comparable<T> on a class to make it na...
Binary search on a sorted list runs in O(log n). Dart's collection package provides binarySearch(). Impleme...
Build a Node<T> class with value and next pointer. A LinkedList<T> holds a head reference. O(1) prepend/ins...
Recursion is clean for tree/graph traversal and divide-and-conquer algorithms. Avoid deep recursion in Dart...
List: O(1) access by index/add at end, O(n) insert/remove at front/middle, O(n) contains(). Set/Map (HashMa...
Binary search finds a value in a sorted list in O(log n) by repeatedly halving the search space. It's only ...
Dart's List.sort() uses Timsort — O(n log n) average/worst, O(n) best (nearly sorted). Sort custom objects ...
A linked list is a sequence of nodes where each node holds a value and a reference to the next node. O(1) i...
Stack (LIFO): use List with add/removeLast. Queue (FIFO): use dart:collection Queue with addLast/removeFirs...
HashMap stores key-value pairs in buckets indexed by key.hashCode % bucketCount. Lookup/insert/delete are O...
Recursion breaks a problem into smaller subproblems. Memoization caches results of expensive recursive call...
BFS (Breadth-First Search) explores level by level using a Queue — finds shortest path. DFS (Depth-First Se...
Two-pointer: use left/right pointers to solve pair/range problems in O(n) instead of O(n²). Sliding window:...
Dart's package:collection provides HeapPriorityQueue<E> — a min-heap by default. O(log n) add, O(log n) rem...