Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Itt 05213

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

DAR ES SALAAM INSTITUTE OF TECHNOLOGY

DRAFT
INSTRUCTOR: MR YUSTIN MWINUKA

MODULE: ITT 05213 FUNDAMENTALS OF DATA STRUCTURES AND ALGORITHMS

RECOMMENDED REFERENCES

 Richard S. & Lewis J. P. (2011). Fundamentals of OOP and Data


Structure in Java. Cambridge University Press. ISBN 139780521662208
 Deitel P., & Deitel H. M. (2015). C How to Program 8th ed. Pearson. ISBN
139780133976892

INTEGRATED METHOD OF ASSESSMENT

Continuous Assessment Component 60%

Oral Presentation, Written Exams, Assignments, Practical and Tests

End of Semester Examination 40%

Contacts  Phone: 0675916478 || Yustin.mwinuka@dit.ac.tz


Table of Contents

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.

Types of Data Structure

Basically, data structures are divided into two types:

 Linear data structure


 Non-linear data structure

Linear data structures


In linear data structures, the elements are arranged in sequence one after the other. Since
elements are arranged in a particular order, they are easy to implement.

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.

Non-linear data structures


Unlike linear data structures, elements in non-linear data structures are not in any sequence.
Instead, they are arranged in a hierarchical manner where one element will be connected to one
or more elements. Non-linear data structures are further divided into graph and tree-based data
structures.

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.

Assignment 01 --- presentation(individually)

Write Notes on the following

 Linked lists in data structures


 Trees in data structures
 Graphs in data structures
 Stack in data structures
 Queue in data structures
Pg. 3 BIG OBIG O

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.

 The topmost node of the tree is called the root,


 The nodes below are called child nodes.
 Each node can have multiple child nodes, child nodes can also have their own child nodes, forming a
recursive structure.

Basic Terminologies in Tree Data Structure:

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.

Subtree: Any node of the tree along with its descendant.

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.

Directed and Undirected Graph


A graph can be directed or undirected. However, in an undirected graph, edges are not
associated with the directions with them. An undirected graph is shown in the above figure
since its edges are not attached to any of the directions. If an edge exists between vertex A and
B then the vertices can be traversed from B to A as well as from A to B.

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

A directed graph is shown in the following figure.

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.

Degree of the Node


A degree of a node is the number of edges that are connected with that node. A node with
degree 0 is called as isolated node.
Pg. 8 BIG OBIG O

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.

For example, an algorithm to add two numbers:

1. Take two number inputs


2. Add numbers using the + operator
3. Display the result

Qualities of a Good Algorithm


 Input and output should be defined precisely.
 Each step in the algorithm should be clear and unambiguous.
 Algorithms should be the most effective among many different ways to solve a problem.
 An algorithm shouldn't include computer code. Instead, the algorithm should be written in
such a way that it can be used in different programming languages.
Pg. 9 BIG OBIG O

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

What is an Algorithm? (programiz.com)


 Algorithm to add two numbers
 Algorithm to find the largest among three numbers
 Algorithm to find all the roots of the quadratic equation
 Algorithm to find the factorial
 Algorithm to check prime number
 Algorithm of Fibonacci series
Pg. 10 BIG OBIG O

BIG O
Big o Notation

== measures how the running time or space requirement grows as the input size grows

You might also like