Itt 05213
Itt 05213
Itt 05213
DRAFT
INSTRUCTOR: MR YUSTIN MWINUKA
RECOMMENDED REFERENCES
Contents
Data Structure_______________________________________________________________1
Algorithms__________________________________________________________________3
Examples___________________________________________________________________4
Pg. 1 BIG OBIG O
Data Structure
Introduction
Data structure is a storage that is used to store and organize data. It is a way of arranging data
on a computer so that it can be accessed and updated efficiently.
However, when the complexity of the program increases, the linear data structures might not be
the best choice because of operational complexities.
Pg. 2 BIG OBIG O
Examples are
Arrays
Elements in memory are arranged in continuous memory. All the elements of an array are of the
same type
Stack
Elements are stored in the LIFO principle. That is, the last element stored in a stack will be
removed first.
Queue
The queue data structure works in the FIFO principle where first element stored in the queue
will be removed first.
Graphs
Each node is called vertex and each vertex is connected to other vertices through edges.
Tree
Tree is also a collection of vertices and edges. However, in the tree data structure, there can
only be one edge between two vertices.
TREE
A tree data structure is a hierarchical structure that is used to represent and organize data in a way that is easy to
navigate and search. It is a collection of nodes that are connected by edges and has a hierarchical relationship
between the nodes.
Parent Node: The node which is a predecessor of a node is called the parent node of that node. {B} is the parent
node of {D, E}.
Child Node: The node which is the immediate successor of a node is called the child node of that node. Examples:
{D, E} are the child nodes of {B}.
Root Node: The topmost node of a tree or the node which does not have any parent node is called the root node.
{A} is the root node of the tree. A non-empty tree must contain exactly one root node and exactly one path from the
root to all other nodes of the tree.
Leaf Node or External Node: The nodes which do not have any child nodes are called leaf nodes. {K, L, M, N, O, P}
are the leaf nodes of the tree.
Pg. 4 BIG OBIG O
Ancestor of a Node: Any predecessor nodes on the path of the root to that node are called Ancestors of that node.
{A,B} are the ancestor nodes of the node {E}
Descendant: Any successor node on the path from the leaf node to that node. {E,I} are the descendants of the
node {B}.
Sibling: Children of the same parent node are called siblings. {D,E} are called siblings.
Level of a node: The count of edges on the path from the root node to that node. The root node has level 0.
Internal node: A node with at least one child is called Internal Node.
Neighbour of a Node: Parent or child nodes of that node are called neighbors of that node.
Properties of a Tree:
A number of edges: An edge can be defined as the connection between two nodes. If a tree has N nodes then it
will have (N-1) edges. There is only one path from each node to any other node of the tree.
Depth of a node: The depth of a node is defined as the length of the path from the root to that node. Each edge
adds 1 unit of length to the path. So, it can also be defined as the number of edges in the path from the root of the
tree to the node.
Height of a node: The height of a node can be defined as the length of the longest path from the node to a leaf
node of the tree.
Height of the Tree: The height of a tree is the length of the longest path from the root of the tree to the leaf node of
the tree.
Degree of a Node: The total count of subtrees attached to that node is called the degree of the node. The degree of
a leaf node must be 0. The degree of a tree is the maximum degree of a node among all the nodes in the tree.
Read more
https://www.simplilearn.com/tutorials/data-structure-tutorial/trees-in-data-structure#:~:text=The%20tree%20is%20a
%20nonlinear,%E2%80%9D%2C%20both%20directed%20and%20undirected.
Pg. 5 BIG OBIG O
Graph
A graph can be defined as group of vertices and edges that are used to connect these vertices.
A graph can be seen as a cyclic tree, where the vertices (Nodes) maintain any complex
relationship among them instead of having a parent-child relationship.
Definition
A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices and
E(G) represents the set of edges that are used to connect these vertices.
A Graph G(V, E) with 5 vertices (A, B, C, D, E) and six edges ((A,B), (B,C), (C,E), (E,D), (D,B), (D,A)) is
shown in the following figure.
In a directed graph, edges form an ordered pair. Edges represent a specific path from some
vertex A to another vertex B. Node A is called the initial node while node B is called the terminal
node.
Pg. 6 BIG OBIG O
Graph Terminology
Path
A path can be defined as the sequence of nodes that are followed in order to reach some
terminal node V from the initial node U.
Closed Path
A path will be called as closed path if the initial node is the same as the terminal node. A path
will be closed path if V0=VN.
Simple Path
If all the nodes of the graph are distinct with an exception V 0=VN, then such path P is called as
the closed simple path.
Cycle
A cycle can be defined as a path which has no repeated edges or vertices except the first and
last vertices.
Connected Graph
A connected graph is one in which some path exists between every two vertices (u, v) in V. There
are no isolated nodes in a connected graph.
Pg. 7 BIG OBIG O
Complete Graph
A complete graph is the one in which every node is connected with all other nodes. A complete
graph contain n(n-1)/2 edges where n is the number of nodes in the graph.
Weighted Graph
In a weighted graph, each edge is assigned with some data such as length or weight. The weight
of an edge e can be given as w(e) which must be a positive (+) value indicating the cost of
traversing the edge.
Digraph
A digraph is a directed graph in which each edge of the graph is associated with some direction
and the traversing can be done only in the specified direction.
Loop
An edge that is associated with the similar end points can be called as Loop.
Adjacent Nodes
If two nodes u and v are connected via an edge e, then the nodes u and v are called as
neighbours or adjacent nodes.
Algorithms
In computer programming terms, an algorithm is a set of well-defined instructions to solve a
particular problem. It takes a set of input(s) and produces the desired output.
Types of algorithms
There are several types of algorithms available. Some important algorithms are:
Brute Force Algorithm: It is the simplest approach for a problem. A brute force algorithm is the
first approach that comes to finding when we see a problem.
Recursive Algorithm: A recursive algorithm is based on recursion. In this case, a problem is
broken into several sub-parts and called the same function again and again.
Backtracking Algorithm: The backtracking algorithm basically builds the solution by searching
among all possible solutions. Using this algorithm, we keep on building the solution following
criteria. Whenever a solution fails, we trace back to the failure point and build on the next solution
and continue this process till we find the solution or all possible solutions are looked after.
Searching Algorithm: Searching algorithms are the ones that are used for searching elements
or groups of elements from a particular data structure. They can be of different types based on
their approach or the data structure in which the element should be found.
Sorting Algorithm: Sorting is arranging a group of data in a particular manner according to the
requirement. The algorithms which help in performing this function are called sorting algorithms.
Generally sorting algorithms are used to sort groups of data in an increasing or decreasing
Homework
BIG O
Big o Notation
== measures how the running time or space requirement grows as the input size grows