caption

2.10.1 Trees: Video

trees are about the most basic data structure that you're ever going to come across there they pervade computer science and other subjects so let's talk about them and the simplest definition of a tree is that a tree is a connected graph with no cycles in this setting we're talking about simple graphs and trees with undirected edges well in order to make sense out of that we'd better have a definition of a cycle there's a picture of a typical tree but to be precise what's a cycle in a simple graph well it's a closed walk of length greater than 2 that doesn't cross itself so the not crossing itself is the standard definition of a cycle that we were using in a directed graph it simply means that it's a path except that the beginning and end vertex are the same so it looks like you start someplace at V and then you go around to a and to W and it's all distinct vertices as you go around in this path except that the path ends where it starts at V which is what keeps it from being a path it makes it a cycle now the length greater than 2 is what is the difference between the definition of cycle between simple graphs and directed graphs in a directed graph it's perfectly possible to have a self-loop of length 1 that is an interesting and important kind of cycle to have but we forbid them in simple graphs because there's no way to avoid having a cycle of length 2 because you always have the ability to go back and forth and cross an edge that's not interesting and so we don't consider that to be a cycle a cycle then has to be of length greater than 2 it also rules out the cycle of length 0 which you get by taking a vertex or by itself ok with that technical definition we now know what a cycle is in this simple graph and we understand the definition of tree here are some more pictures of trees simple graphs with no cycles now they really come up all the time and why is that well there are family trees which you may be familiar with where you're during a picture of the descendants of a given person and they keep branching out in a you know tree structure as traditionally displayed there are search tree which come up the whole time in computer science where you branch on the answer to some question which tells you which way to search next there are game trees which we've already discussed in this class which are used to define great games and strategies their parse trees that come up in in compiler technology and in language theory and in the responding trees which we're going to be talking about some today now there in addition to these places where trees come up there are a lot of different kinds of trees there's rooted trees where there's some designated vertex called the root and you think of getting to all the other vertices from the road there are ordered trees where when you're at a given vertex there's a distinct order in which you are going to be in which the exit edges from a vertex are there's a first one in the second one the third one or a left one in the next leftmost and so on so that there's an order in which you can choose to leave the vertex there are binary trees in which each vertex has sort of two ways out exactly or no ways out if it's a so-called leaf and then there are complete trees whose definition olive is not important to us because we're not going to consider any of these there's also by the way directed trees in which edges are have a direction as in a digraph tree but we're not considering any of these we're going to focus on so-called pure trees which are unordered unrooted undirected and that's what we're talking about so let's examine some more properties of trees and equivalent definitions of trees it will be important for theoretical reasons and convenience to know lots of different characterizations of trees so we've starting off in the definition which says it's a connected simple graph with no cycles but there's other ways to characterize it so an edge in a simple graph is called a cut edge if when you remove it from the graph two vertices that used to be connected that is used to have a path between them cease to have a path between them so here's a we'll graph illustration and that edge e is a cut edge because if I delete it then there are now two components there used to be two vertices actually any of the vertices here used to be connected to any of the vertices there via that edge but once I've deleted that edge all of those vertices here and there that used to be connected no longer are so that makes via cut edge Oh F is not a cut edge because even if I delete edge F there is in fact still a path from every vertex to every other vertex here so that F is not disconnecting anything um and as I say it's still connected after you delete it so now we get a simple way to characterize trees in terms of cut edges because an edge is not a cut edge if and only if it's on a cycle if you think about that if it's on a cycle and you cut an edge out of a cycle then everything on the cycle still connected by going the other way around the cycle that doesn't use that edge and if it's not on a cycle then in fact you can think through that deleting it means that there's not going to be two paths between two things that it's at its endpoints and so it will separate them okay so another way then to define a tree is to say a tree is a connected graph where every edge is a cut edge then as soon as you cut any edge out of a tree it stops being connected that yields another way to say that something is a tree a tree is a simple graph that is connected and is edged minimal which again means that if you remove any edge it stops having that property of being connected so it's an edge minimal connected graph that's kind of the reason why trees are so important because if you're trying to figure out a way to get a whole bunch of things a whole bunch of vertices connected a tree is gonna have the minimum number of edges that are sufficient to get them all connected if you think about different nodes in a network that need to communicate with each other and you want to know how many direct connections do there have to be between these communication centers in order for everybody to talk to everybody else the answer is it's got to be a tree on n vertices and a tree on n vertices is going to have exactly n minus 1 edges so that gives you I still another equivalent definition of a tree a tree is a connected graph that has n vertices and n minus 1 edges a kind of dual way to think about it is that a tree is an acyclic graph that has as many edges as it possibly could without having any cycles so typically an acyclic graph might not be connected but as long as it's not connected you can keep adding edges that will connect things up without creating cycles but the minute you get a tree so that everything is connected you can't add another edge so an edge 'men an edge maximal acyclic graph is still another way to characterize trees and maybe the most useful way is to say that a graph in which there is a unique path between any two vertices is a tree so of course if there's a unique path in particular isn't passed so all the vertices have to be connected but what makes it a tree is that there aren't two different ways to connect between two vertices because as soon as the word that would be a cycle and those are some of the basic ways that trees can be formulated equivalently and in fact there's lots more but this is enough for today

As found on YouTube