TREES
 Tree is a non-linear data structure which
organizes data in a hierarchical structure
and this is a recursive definition. A tree is
a connected graph without any circuits. If
in a graph, there is one and only one path
between every pair of vertices, then
graph is called as a tree.
 Binary tree is a special type of data structure. In
binary tree, every node can have a maximum of 2
children, which are known as Left child and Right
Child. It is a method of placing and locating the
records in a database, especially when all the data
is known to be in random access memory (RAM).
 In computer science, tree traversal (also known as tree
search) is a form of graph traversal and refers to the
process of visiting (checking and/or updating) each
node in a tree data structure, exactly once. Such
traversals are classified by the order in which the nodes
are visited. The following algorithms are described for a
binary tree, but they may be generalized to other trees
as well.
 The idea of threaded binary trees is to make
inorder traversal faster and do it without stack and
without recursion. A binary tree is made threaded
by making all right child pointers that would
normally be NULL point to the inorder successor
of the node (if it exists). There are two types of
threaded binary trees.
 Definition: A way to represent a multiway tree as a binary tree. The
leftmost child, c, of a node, n, in the multiway tree is the left child,
c’, of the corresponding node, n’, in the binary tree. The
immediately right sibling of c is the right child of c’.
 Formal Definition: A multiway tree T can be represented by a
corresponding binary tree B. Let {n1,…, nk} be nodes of the
multiway tree, T. Let {n’1,…, n’k} be nodes of the corresponding
binary tree B. Node nk corresponds to n’k. In particular, nodes nk
and n’k have the same labels and if nk is the root of T, n’k is the
root of B.
 Graph is a data structure that consists of following two components:
 1. A finite set of vertices also called as nodes.
 2. A finite set of ordered pair of the form (u, v) called as edge. The pair is
ordered because (u, v) is not same as (v, u) in case of a directed
graph(di-graph). The pair of the form (u, v) indicates that there is an
edge from vertex u to vertex v. The edges may contain weight/value/cost.
 Graphs are used to represent many real-life applications: Graphs are
used to represent networks. The networks may include paths in a city or
telephone network or circuit network. Graphs are also used in social
networks like linkedIn, Facebook. For example, in Facebook, each
person is represented with a vertex(or node). Each node is a structure
and contains information like person id, name, gender and locale. See
this for more applications of graph.
 Graph traversal is a technique used for
searching a vertex in a graph. The graph
traversal is also used to decide the order
of vertices is visited in the search process.
A graph traversal finds the edges to be
used in the search process without
creating loops.

 A spanning tree is a subset of Graph G, which has
all the vertices covered with minimum possible
number of edges. Hence, a spanning tree does not
have cycles and it cannot be disconnected.
 By this definition, we can draw a conclusion that
every connected and undirected Graph G has at
least one spanning tree. A disconnected graph
does not have any spanning tree, as it cannot be
spanned to all its vertices.
 In graph theory, a component, sometimes called a
connected component, of an undirected graph is a
subgraph in which any two vertices are connected to
each other by paths, and which is connected to no
additional vertices in the supergraph. For example,
the graph shown in the illustration has three
components.
Data structures for single-source shortest paths.
Given an edge-weighted digraph and a designated
vertex s, a shortest-paths tree (SPT) is a subgraph
containing s and all the vertices reachable from s
that forms a directed tree rooted at s such that
every tree path is a shortest path in the digraph
 Transitive closure of a graph. Given a directed graph, find out if a vertex j
is reachable from another vertex i for all vertex pairs (i, j) in the given
graph. ... The reach-ability matrix is called transitive closure of a graph.
 Transitive Closure of a Graph using DFS. Given a directed graph, find out
if a vertex v is reachable from another vertex u for all vertex pairs (u, v) in
the given graph. Here reachable mean that there is a path from vertex u to
v. The reach-ability matrix is called transitive closure of a graph.
 Activity network (activity graph) A graphical
method for showing dependencies between
tasks (activities) in a project. The network
consists of nodes connected by arcs. Nodes
denote events and represent the culmination
of one or more activities.
 Topological Sort. The topological sort algorithm takes
a directed graph and returns an array of the nodes
where each node appears before all the nodes it points
to. The ordering of the nodes in the array is called a
topological ordering. Since node 1 points to nodes 2
and 3, node 1 appears before them in the ordering.
 Critical path is the sequential activities from start to the end of a project.
Although many projects have only one critical path, some projects may
have more than one critical paths depending on the flow logic used in the
project.
 If there is a delay in any of the activities under the critical path, there will
be a delay of the project deliverables.
 Most of the times, if such delay is occurred, project acceleration or re-
sequencing is done in order to achieve the deadlines.

data structures and algorithms Unit 2

  • 1.
  • 2.
     Tree isa non-linear data structure which organizes data in a hierarchical structure and this is a recursive definition. A tree is a connected graph without any circuits. If in a graph, there is one and only one path between every pair of vertices, then graph is called as a tree.
  • 3.
     Binary treeis a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child. It is a method of placing and locating the records in a database, especially when all the data is known to be in random access memory (RAM).
  • 4.
     In computerscience, tree traversal (also known as tree search) is a form of graph traversal and refers to the process of visiting (checking and/or updating) each node in a tree data structure, exactly once. Such traversals are classified by the order in which the nodes are visited. The following algorithms are described for a binary tree, but they may be generalized to other trees as well.
  • 5.
     The ideaof threaded binary trees is to make inorder traversal faster and do it without stack and without recursion. A binary tree is made threaded by making all right child pointers that would normally be NULL point to the inorder successor of the node (if it exists). There are two types of threaded binary trees.
  • 6.
     Definition: Away to represent a multiway tree as a binary tree. The leftmost child, c, of a node, n, in the multiway tree is the left child, c’, of the corresponding node, n’, in the binary tree. The immediately right sibling of c is the right child of c’.  Formal Definition: A multiway tree T can be represented by a corresponding binary tree B. Let {n1,…, nk} be nodes of the multiway tree, T. Let {n’1,…, n’k} be nodes of the corresponding binary tree B. Node nk corresponds to n’k. In particular, nodes nk and n’k have the same labels and if nk is the root of T, n’k is the root of B.
  • 7.
     Graph isa data structure that consists of following two components:  1. A finite set of vertices also called as nodes.  2. A finite set of ordered pair of the form (u, v) called as edge. The pair is ordered because (u, v) is not same as (v, u) in case of a directed graph(di-graph). The pair of the form (u, v) indicates that there is an edge from vertex u to vertex v. The edges may contain weight/value/cost.  Graphs are used to represent many real-life applications: Graphs are used to represent networks. The networks may include paths in a city or telephone network or circuit network. Graphs are also used in social networks like linkedIn, Facebook. For example, in Facebook, each person is represented with a vertex(or node). Each node is a structure and contains information like person id, name, gender and locale. See this for more applications of graph.
  • 8.
     Graph traversalis a technique used for searching a vertex in a graph. The graph traversal is also used to decide the order of vertices is visited in the search process. A graph traversal finds the edges to be used in the search process without creating loops.
  • 9.
      A spanningtree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected.  By this definition, we can draw a conclusion that every connected and undirected Graph G has at least one spanning tree. A disconnected graph does not have any spanning tree, as it cannot be spanned to all its vertices.
  • 10.
     In graphtheory, a component, sometimes called a connected component, of an undirected graph is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the supergraph. For example, the graph shown in the illustration has three components.
  • 11.
    Data structures forsingle-source shortest paths. Given an edge-weighted digraph and a designated vertex s, a shortest-paths tree (SPT) is a subgraph containing s and all the vertices reachable from s that forms a directed tree rooted at s such that every tree path is a shortest path in the digraph
  • 12.
     Transitive closureof a graph. Given a directed graph, find out if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. ... The reach-ability matrix is called transitive closure of a graph.  Transitive Closure of a Graph using DFS. Given a directed graph, find out if a vertex v is reachable from another vertex u for all vertex pairs (u, v) in the given graph. Here reachable mean that there is a path from vertex u to v. The reach-ability matrix is called transitive closure of a graph.
  • 13.
     Activity network(activity graph) A graphical method for showing dependencies between tasks (activities) in a project. The network consists of nodes connected by arcs. Nodes denote events and represent the culmination of one or more activities.
  • 14.
     Topological Sort.The topological sort algorithm takes a directed graph and returns an array of the nodes where each node appears before all the nodes it points to. The ordering of the nodes in the array is called a topological ordering. Since node 1 points to nodes 2 and 3, node 1 appears before them in the ordering.
  • 15.
     Critical pathis the sequential activities from start to the end of a project. Although many projects have only one critical path, some projects may have more than one critical paths depending on the flow logic used in the project.  If there is a delay in any of the activities under the critical path, there will be a delay of the project deliverables.  Most of the times, if such delay is occurred, project acceleration or re- sequencing is done in order to achieve the deadlines.