<style> .reveal-up, .reveal-left, .reveal-right, .reveal-stagger > * { opacity: 1 !important; transform: none !important; } </style>
  1. Learn
  2. DSA
  3. Foundations
All lessons in this course

Lesson 1 of 50 10 minBeginner

What are data structures and algorithms?

What the two words mean, why the way you store data decides how fast your program is, and how this course is organised.

Every program does two things: it keeps data (beams, users, orders, pixels) and it does work with that data (search, sort, add up, find a path). Data structures and algorithms are simply the study of doing those two things well.

  • A data structure is a way of organising data in memory so that the operations you need are fast. An array, a list, a dictionary and a tree are all data structures.
  • An algorithm is a precise, step-by-step recipe that turns an input into the right output in a finite number of steps. “Check each beam until you find the one with this ID” is an algorithm.

The two go together. The right structure makes a simple algorithm fast; the wrong one makes even a clever algorithm slow. Try it: the same question asked of the same data, stored three different ways.

Interactive

Same question, three data structures

A model has 1,000 beams. Find beam B-1000. Count how many beams each approach has to look at.

Beams
Find
List, checked one by onebeams.Find(b => b.Id == id)
1,000 checks · stops when it finds the beam
Sorted array, binary searchArray.BinarySearch(ids, id)
10 checks · halves the search range every check
Dictionary (hash table)byId.TryGetValue(id, out var b)
1 check · jumps straight to the right slot

Bars use a log scale so that 1 and 1,000,000 both fit. The real gap is much bigger than it looks.

Done 10,000 times (say, once per clash check), the list needs 10,000,000 checks, the sorted array 100,000, the Dictionary about 10,000. Same data, same answer: only the structure changed.

Why learn this if .NET already has List and Dictionary?

You will rarely write your own hash table at work, but you choose between structures every day, and the wrong choice is one of the most common causes of slow software. Knowing how they work inside tells you which one to pick and what it costs.

  • Performance: a check that takes 1 second on 1,000 elements might take 11 days on a million if the algorithm is O(n²). BIM models easily have a million elements.
  • Interviews: almost every developer interview has DSA questions, from freshers to senior roles.
  • Problem solving: many “hard” problems become easy once you recognise them as a known pattern: a graph search, a sliding window, a heap.

The main data structures at a glance

StructureIn .NETFast atSlow at
Arrayint[]Read/write by indexGrowing, inserting in the middle
Dynamic arrayList<T>Index access, adding at the endInserting/removing at the front, searching
Linked listLinkedList<T>Inserting/removing at a known nodeAccess by index
StackStack<T>Push/pop at the top (last in, first out)Anything below the top
QueueQueue<T>Add at back, take from front (first in, first out)Anything in the middle
Hash tableDictionary<K,V>, HashSet<T>Lookup by keyKeeping things in order
Balanced treeSortedDictionary<K,V>, SortedSet<T>Ordered data, ranges, min/maxSlower than hashing for plain lookups
HeapPriorityQueue<T,P>Always taking the smallest/most urgent itemSearching for an arbitrary item
Graph(you build it)Connections: networks, routes, dependenciesDepends on how it is stored

Do not worry about memorising this table. Every row has its own lesson later, with a visual of how it works inside.

Your first algorithm

Finding the largest value is a classic first algorithm. It is precise (no guessing), it always finishes, and it is correct for every non-empty input.

MaxLoad.cs
static int Max(int[] values){    if (values.Length == 0)        throw new ArgumentException("Need at least one value.");     int best = values[0];               // assume the first is the largest    for (int i = 1; i < values.Length; i++)    {        if (values[i] > best)           // found a bigger one?            best = values[i];    }    return best;} int[] loads = { 12, 45, 7, 88, 23 };Console.WriteLine(Max(loads));
Output
88

A good algorithm description answers four questions: what is the input, what is the output, what are the steps, and how do we know it is correct (here: after each step, best is the largest value seen so far).

How we judge an algorithm

  1. Correct: it gives the right answer for every valid input, including edge cases (empty input, one element, duplicates, negative numbers).
  2. Time: how the number of steps grows as the input grows. This is Big-O, the next lesson.
  3. Memory: how much extra memory it needs (space complexity).
  4. Simple: easy to read, test and change. A clever algorithm nobody understands is a risk.

How this course is organised

ModuleWhat you will learn
FoundationsBig-O, counting steps, memory cost, recursion trees
Linear data structuresArrays, dynamic arrays, linked lists, stacks, queues
Searching and sortingBinary search and the important sorting algorithms
Hashing and techniquesHash tables, two pointers, sliding window, prefix sums, bits
TreesBinary trees, BSTs, balanced trees, heaps, tries
GraphsBFS, DFS, topological sort, shortest paths, spanning trees, union-find
Algorithm designGreedy, divide and conquer, backtracking, dynamic programming
Master levelSegment trees, string matching, spatial indexes, geometry, hard problems
Quick check

Which statement is true?

Quick check

You need to check, many times, whether an element ID has already been processed. Which structure fits best?

Practice

Write FirstLongerThan(double[] lengths, double limit) that returns the index of the first beam longer than limit, or -1 if there is none. Test it with { 6.5, 9.0, 14.2, 3.1, 12.8 } and a limit of 12.

Show a hint

Loop with an index, return as soon as you find a match, and return -1 after the loop.

Show the solution
Solution.cs
static int FirstLongerThan(double[] lengths, double limit){    for (int i = 0; i < lengths.Length; i++)    {        if (lengths[i] > limit)            return i;          // stop at the first match    }    return -1;                 // checked everything, none found} double[] beams = { 6.5, 9.0, 14.2, 3.1, 12.8 };Console.WriteLine(FirstLongerThan(beams, 12));Console.WriteLine(FirstLongerThan(beams, 20));
Output
2
-1

Remember

  • A data structure organises data so certain operations are fast; an algorithm is a precise recipe that solves a problem.
  • The same question can take 1 step or a million steps depending on how the data is stored.
  • Judge algorithms by correctness first, then time, memory and simplicity.
  • .NET already provides most structures; DSA teaches you which one to choose and why.
0 of 50 lessons completed