Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Handout: UNIT-I
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
The analysis of algorithms is the determination of the amount of resources (such as time
and storage) necessary to execute the algorithm. In theoretical analysis of algorithms, it is
common to estimate their complexity in the asymptotic sense, i.e., to estimate the complexity
function for arbitrarily large input. Big O notation, Big-omega notation and Big-theta notation
are used to represent the complexity of the algorithm. A good algorithm chooses efficient data
structure for its data representation and executes faster and consumes less space in the memory.
A data structure is a particular way of organizing data in a computer so that it can be
used efficiently. Different kinds of data structures are suited to different kinds of applications,
and some are highly specialized to specific tasks. For example, B-trees are particularly wellsuited for implementation of databases, while compiler implementations usually use hash tables
to look up identifiers. We have STACK, QUEUE, Linked Lists, Trees, Graphs as examples of
data structures.
DATA STRUCTURES
Handout: UNIT-II
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
elements at the rear and removes elements from the front of the sequence. You will note that a
queue removes elements in the same order in which they were stored, and hence a queue
provides FIFO (first- in / first-out), or FCFS (first-come / first-served), ordering.
A queue is a container of objects (a linear collection) that are inserted and removed
according to the first- in first-out (FIFO) principle. An excellent example of a queue is a line of
students in the food court of the UC. New additions to a line made to the back of the queue,
while removal (or serving) happens in the front. In the queue only two operations are allowed
enqueue and dequeue. Enqueue means to insert an item into the back of the queue, dequeue
means removing the front item.
Text Books
1. Data Structure with C, Seymour Lipschutz, TMH
2. Fundamentals of Data Structure in C, 2-e, Horowitz,Sahni, Anderson Freed,University
Prees
3. Data Structures Using C, Reema Thareja,OXFORD
DATA STRUCTURES
Handout: UNIT-III
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
Single Linked list is a sequence of nodes with links. The nodes do not reside in sequential
locations. The locations of the nodes may change on different runs. The address of the left or
right element will be stored in the node. So it can traversal either left to right or right to left.
In doubly linked lists the address of the left and right element will be stored in the node. So it
allow searches in both directions
TEXT BOOKS:
1. Data Structure with C, Seymour Lipschutz, TMH
2. Data Structures Using C, Reema Thareja,OXFORD
3. Data Structures, 2-e, Richard F, Gilberg , Forouzan, Cengage
DATA STRUCTURES
Handout: UNIT-IV
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
2.
The remaining elements of tree form an ordered collection of zero or more disjoint
subsets called sub tree.
Binary Tree:
A binary tree is defined as a finite set of elements, called nodes, such that:
1)
2)
Tree contains a distinguished node called root node, and the remaining nodes form an
ordered pair of disjoint binary trees
R
T1
T2
In the above tree R is the root node and T1 and T2 are called subtrees. T1 and T2 are left
and right successor of R. The node R is called parent node and T1 and T2 are called children. All
lower level nodes are called descendants and upper level nodes are called ancestors of their
descendants. The line drawn between parent and child is called an edge or arc where as the
line(s) between and ancestor and descendant is called path. A node without any children is called
a terminal or leaf node and all others are called non-terminal or non-leaf node. A path ending
with a leaf is called a branch.
Each node in a binary tree is assigned a level number, as follows. The root node is
assigned the level number 0, and every other node is assigned a level number, which are 1 more
than the level number of its parent. The nodes of same level number are said to belong to same
generation. Nodes of same parent are called siblings. The depth or height of a tree is the
maximum level number of the tree or maximum number of nodes in a branch of a tree. Two trees
are said to be similar if they have the same structure and are said to be copies if they are similar
and if they have same contents at corresponding nodes.
Complete Binary Tree:
A binary tree is said to be complete if all its level except possibly
the last, have maximum number of possible nodes, and if all the
nodes at the last level appear as far left as possible.
Full binary tree:
A binary tree said to be full if all its level have maximum number
of possible node.
Extended Binary Tree (Strictly Binary Tree or 2-tree):
A binary tree is said to be Extended binary tree if each node has
either 0 or 2 children. In this case the leaf nodes are called external
nodes and the node with two children are called internal nodes.
Terminology of tree
1. Root - the top most node in a tree.
2. Parent - the converse notion of child.
3. Siblings - nodes with the same parent.
4. Descendant - a node reachable by repeated proceeding from parent to child.
5. Leaf - a node with no children.
6. Inte rnal node - a node with at least one child.
7. Degree - number of sub trees of a node.
8. Edge - connection between one node to another.
9. Path - a sequence of nodes and edges connecting a node with a descendant.
10. Level - The level of a node is defined by 1 + the number of connections between the node
and the root.
11. Height - The height of a node is the length of the longest downward path between the
node and a leaf.
12. Forest - A forest is a set of n 0 disjoint trees.
TEXT BOOKS:
1.
2.
3.
4.
DATA STRUCTURES
Handout: UNIT-V
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
A complete binary tree of height h is a binary tree that is full down to level h 1, with
level h filled in with from left to right. More formally, a binary tree of height h is complete if
1. All nodes at level h-2 and above have two children each
2. When a node at level h-1 has children, all nodes to its left at the same level have two children
each
3. When a node at level h-1 has one child, it is a left child.
Note that a full binary tree is complete. A binary tree is height balanced or simply balanced if the
height of any nodes right sub tree differs from the height of the nodes left tree by no more than
1. A complete binary tree is balanced.
TEXT BOOKS
1.
2.
3.
4.
DATA STRUCTURES
Handout: UNIT-VI
COURSE: II Year B. Tech
BRANCH: ECE-A
CLASS
YEAR: 2014-2015
: II-I Sem.
neighbors(G, x): lists all nodes y such that there is an edge from x to y.
Adjacency matrix
One of the easiest ways to implement a graph is to use a two-dimensional matrix. A twodimensional matrix, in which the rows represent source vertices and columns represent
destination vertices. Data on edges and vertices must be stored externally. Only the cost for one
edge can be stored between each pair of vertices.
An Adjacency List
A more space-efficient way to implement a sparsely connected graph is to use an
adjacency list. In an adjacency list implementation we keep a master list of all the vertices in the
Graph object and then each vertex object in the graph maintains a list of the other vertices that it
is connected to.
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data
structures. One starts at the root (selecting some arbitrary node as the root in the case of a graph)
and explores as far as possible along each branch before backtracking.
Breadth-first search (BFS) is a strategy for searching in a graph when search is limited to
essentially two operations: (a) visit and inspect a node of a graph; (b) gain access to visit the
nodes that neighbor the currently visited node. The BFS begins at a root node and inspects all the
neighboring nodes. Then for each of those neighbor nodes in turn, it inspects their neighbor
nodes which were unvisited, and so on. Compare BFS with the equivalent, but more memoryefficient Iterative deepening depth- first search and contrast with depth-first search.
TEXT BOOKS
1. Data Structures, 2-e, Richard F, Gilberg , Forouzan, Cengage
2. Data Structures and algorithm analysis in C,2 nd edition Mark Allen Weiss, Pearson
3. Data Structures and Algorithms, 2008,G.A.V.Pai, TMH