DS&A

Data Structures and Algorithms

Three Ways to Think About Recursion

Mar 122018

Like all important ideas, recursion can be thought about in many ways, and there is no single “correct” or “best” way to think about it. Rather, each way of thinking is useful for some purposes, but not helpful in every situation.

In the posts about recursion on trees and linked lists, we thought about:

  • What recursion is,
  • How to find recursive structures in problems, and
  • How to write simple recursive functions to solve those problems.

We haven’t yet thought about how recursive functions actually work — what happens when a recursive function is called? In this post we’ll see three different ways to think about how recursive functions are actually computed.

Graph Problems

Mar 052018

Graphs and networks are useful because they’re very general — graphs show up almost everywhere. Given that there are so many different examples of graph structures, then, it’s perhaps surprising that there aren’t actually very many different kinds of problems involving graphs.

That is, there are many computing problems which graphs can help with, but not many kinds of problem. Usually, after translating from the problem domain into the language of graphs, the problem turns out to be one of a relatively small number of “classical graph problems”.

Graphs

Mar 052018

A tree is an abstract idea, a common kind of structure which we find across many different applications. A tree models a relation between pairs of things:

  • A section of an article contains another section,
  • A directory contains another directory,
  • An HTML tag contains other HTML tags,
  • An employee manages another employee,
  • A process spawns another process.

A “relation between pairs of things” is very abstract and very general — in almost any context, there are relations between pairs of things which we might want to model in a computer program. However, not every relation defines a tree structure.

Tree Data Structures

Feb 262018

Abstract data types define what data can be represented and what operations can be performed on it, but not how the data should be stored or structured in a program. Data structures are concrete implementations of ADTs which fill in these details — they define how the data should be stored in memory, and what instructions should be followed to perform the operations.

Trees are both; we have an abstract idea of what a tree is, but there are also data structures for them, which we’ll look at in this post. In fact, we can even use tree data structures to implement other ADTs, such as sets or dictionaries.(1)

Atom

hosted on werp.site