DataStructure and Algorithms
DataStructure and Algorithms
Doubly linked lists: are very similar to singly-linked lists. The only difference is that each node has a
reference to both the next and previous nodes in the list.
Tree : A tree as consisting of nodes (also called vertices or points) and edges (also called lines, or,
in order to stress the directedness, arcs) with a tree-like structure.
Types Of Tree
Quad Tree
Binary Tree
Binary Search Tree
AVL Tree
Heap Tree
Parent node – is connected to the given node (via an edge) on the level above
Sibling : Nodes that have the same parent are known as siblings
The maximal length of a path in a tree : is also called the height of the tree.
Complete binary tree : binary tree that is completely filled, with the possible exception of
It is implemented as an array.
(i.e. In a max heap, every node’s key is larger than (or equal to) the keys of its children.)
Heap Strategies : There are two strategies in heap: (1) Min heap ,(2) Max heap.
Max heap: Each parent node in max heap have a value that is greater than or equal its children.
For example, the node at the root of the tree will have the largest value in the tree.
Min Heap : Each parent node in min heap have a value that is less than or equal its children.
For example, the node at the root of the tree will have the smallest value in the tree.
The binary heap :is a data structure that can be used to quickly find the maximum (or minimum) value
in a set of values.
Binary Search Tree : The defining characteristic of a binary search tree is this: A node’s left child must
have a key less than its parent, and a node’s right child must have a key greater
than or equal to its parents.
AVL Tree : A binary search tree with a self-balancing condition stating. The difference between the
height of the left and right subtrees cannot be no more than one .In an AVL tree, a well-
known technique is called tree rotation.
Graph : A graph is a non-linear datastructure consisting of nodes and edges . A graph consists of a
series of nodes (also called vertices or points) and edges(also called lines,links). It consists
of a finite set of vertices (or nodes) and set of edges which connect a pair of nodes.
1. Adjacency Martix
2. Adjacency List
Directed Graph : In directed graphs (also called digraphs), each edge comes with one or two
directions, which are usually indicated by arrows. Same as undirected graph but
orientation of edges is significant.
Simple graph: A graph is said to be simple if it has no self-loops (i.e., edges connected at both ends to
the same vertex)
Connected graph: a graph is at least one path from every vertex to every other vertex.
Adjacency : two vertices are adjacent if they are connected by a single edge.
A circle : is a non-empty path whose first vertex is the same as its last vertex.
A digraph is weakly connected if for every two vertices A and B there is either a path from A to B or a
path from B to A.
One of the canonical applications for weighted graphs :is finding the shortest path between two
nodes. These algorithms are used in Google Maps for example.
Tranversals : Fundamental operation, to find out which vertices can be reached from a specified
vertex.An algorithm that provides a systematic way to start at a specified vertex and then
move along edges to other vertex.Every vertex that is connected to this vertex has to be
visited at the end.
Depth-first Search : Can be implemented with a stack to remember where it should go when it reaches
a dead end.DFS goes far way from the starting point as quickly as possible and
returns only if it reaches a dead end.
The purpose of a graph is to present data that are too numerous or complicated to be described
adequately in the text and in less space (Do not use graphs for small amounts of data that could be
conveyed succinctly in a sentence).
Type of Algorithms
Dijkstra’s algorithm : is an algorithm for finding the shortest paths between nodes in a graph. It finds
the shortest path between that node and every other.
It is also called SPF (Shortest Path First), which is used in the routing protocol
OSPF, Open Shortest Path First.
Floyd’s algorithm : is an algorithm for finding the shortest path between all the pairs of vertices in a
weighted graph. It works for both the directed and undirected weighted graphs.
*(does not work for the graphs with negative cycles (where the sum of the edges in a cycle is negative))
Dijkstra's algorithm finds the shortest path between a single vertex and all other vertices.
They are most commonly used in linear programs where large numbers of
variables are involved.
Recursive Algorithms : Instead of executing a specific process within the function, the function calls
itself repeatedly until a certain condition is met.
There are two main parts of a recursive function; the base case and the recursive call.
The base case is important because without it, the function would theoretically
repeat forever.
Linear Search
Binary Search
Linear search : (sequential search) is a method for finding an element within a list. It sequentially checks
each element of the list until a match is found or the whole list has been searched.
Binary Search: search a sorted array by repeatedly dividing the search interval in half.
If the value of the search key is less than the item in the middle of the interval, narrow the
interval to the lower half.
Flow of computation
Networks of communication
Data organization
Shortest path in road or a network