You are on page 1of 12

DATA STRUCTURES

Handout: UNIT-I
COURSE: II Year B. Tech

BRANCH: ECE-A

CLASS

YEAR: 2014-2015

: II-I Sem.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-I


Preliminaries of algorithm: Algorithm analysis and complexity.
Data Structure : Definition and types of data structures
Recursion: Definition, Design Methodology and Implementation of recursive algorithms, Linear
and binary recursion, recursive algorithms for factorial function, GCD computation, Fibonacci
sequence, Towers of Hanoi, Tail recursion
List Searches using Linear Search, Binary Search, Fibonacci Search.
Sorting Techniques: Basic concepts, Sorting by: insertion (Insertion sort), selection (heap sort),
exchange (bubble sort, quick sort), distribution (radix sort) and merging (merge sort) Algorithms.
SUMMARY

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.

A recursive definition (or inductive definition) in mathematical logic and computer


science is used to define an object in terms of itself. The simplest form of recursion is linear
recursion. It occurs where an action has a simple repetitive structure consisting of some basic
step followed by the action again. Factorial calculation can be the example of linear recursion. A
binary-recursive routine (potentially) calls itself twice. Fibonacci numbers calculation can be the
example of binary recursion.
Computer systems are often used to store large amounts of data from which individual
records must be retrieved according to some search criterion. Thus the efficient storage of data
to facilitate fast searching is an important issue.
A sorting algorithm is an algorithm that puts elements of a list in a certain order. The
most-used orders are numerical order and lexicographical order. Efficient sorting is important for
optimizing the use of other algorithms (such as search and merge algorithms) which require input
data to be in sorted lists.
Text Books
1. Data Structures, 2-e, Richard F, Gilberg , Forouzan, Cengage
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-II
COURSE: II Year B. Tech

BRANCH: ECE-A

CLASS

YEAR: 2014-2015

: II-I Sem.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-II


Stacks and Queues:
Basic Stack Operations, Representation of a Stack using Arrays, Stack Applications: Reversing
list, Factorial Calculation, In-fix- to postfix Transformation, Evaluating Arithmetic
Expressions.
Queues: Basic Queues Operations, Representation of a Queue using array, Implementation of
Queue Operations using Stack, Applications of Queues-Round robin Algorithm, Enqueue,
Dequeue, Circular Queues, Priority Queues.
SUMMARY
Stack:
It is a sequence of items that are accessible at only one end of the sequence. Think of a
stack as a collection of items that are piled one on top of the other, with access limited to the
topmost item. A stack inserts item on the top of the stack and removes item from the top of the
stack. It has LIFO (last- in / first-out) ordering for the items on the stack.
It is a container of objects that are inserted and removed according to the last- in first-out
(LIFO) principle. In the pushdown stacks only two operations are allowed: push the item into the
stack, and pop the item out of the stack. A stack is a limited access data structure - elements can
be added and removed from the stack only at the top. push adds an item to the top of the stack,
pop removes the item from the top. A helpful analogy is to think of a stack of books; you can
remove only the top book, also you can add a new book o n the top.
Type of Stack:
Linear Stack
Linked List Stack
Queue
A queue is a sequential storage structure that permits access only at the two ends of the
sequence. We refer to the ends of the sequence as the front and rear. A queue inserts new

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.

Type of the Queue:


Linear Queue: non-circular queue, circular queue, priority queue
Linked List Queue: non-circular queue, circular queue, priority queue

Ope ration of Queue:


Add: insert operation for the queue is adding item to the new element at the rear of queue.
Delete: remove operation for the queue is deleting item from the front element of queue.

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.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-III


Linked Lists:
Introduction, single linked list, representation of a linked list in memory, Operations on a single
linked list, merging two single linked lists into one list, Reversing a single linked list,
applications of single linked list to represent polynomial expressions and sparse matrix
manipulation, Advantages and disadvantages of single linked list, Circular linked list, Double
linked list
SUMMARY
Linked list is a data structure that allows sequential access to the elements. A list lays out the
sequence in a row, starting at the first element (called front) and proceeding in successive order
to the last element (called back). Each element in a list may contain links that identify both the
next and the preceding item in the sequence. Linked list provides efficient operations to insert
and delete an element at any position in the sequence. Each elements of Linked list called node.

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.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-IV


Trees:
Basic tree concepts, Binary Trees: Properties, Representation of Binary Trees using arrays and
linked lists, operations on a Binary tree , Binary Tree Traversals (recursive), Creation of binary
tree from in-order and pre(post)order traversals,
SUMMARY
Trees
A tree is a nonlinear data structure and is generally defined as a nonempty finite set of elements,
called nodes such that:
1.

T contains a distinguished node called root of the tree.

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)

Tree is empty (called the null tree or empty tree) or

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 Structure with C, Seymour Lipschutz, TMH


Data Structures Using C, Reema Thareja,OXFORD
Data Structures, 2-e, Richard F, Gilberg , Forouzan, Cengage
Data Structures and algorithm analysis in C,2nd edition Mark Allen Weiss, Pearson

DATA STRUCTURES
Handout: UNIT-V
COURSE: II Year B. Tech

BRANCH: ECE-A

CLASS

YEAR: 2014-2015

: II-I Sem.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-V


ADVANCED CONCEPTS OF TREES: Tree Travels using stack (non recursive), Threaded
Binary Trees. Binary search tree, Basic concepts, BST operations: insertion, deletion, Balanced
binary trees need, basics and applications in computer science.
SUMMARY
Binary Search Tree
A binary tree consists of nodes and branches. A node is a place where data is stored,
There is one special node the root which is the starting point of the tree. Branches connect the
nodes to each other. A branch is either a left branch or a right branch. Accordingly a node is
said to have a left child and a right child. A node without children is called a leaf. Non- leaf
nodes are called internal nodes. There is a single path from any node to any other node in the
tree. Another useful attribute of a node is its distance from the root, called its depth. Distance is
counted in number of branches from the root. The depth of the root is zero. Nodes at the same
depth are said to be at the same level, with the root being at level zero. The height of a tree is the
maximum level (or depth) at which there is a node. Alternatively, the height of a tree is the
distance of the farthest leaf from the root.
A binary search tree is a binary tree whose entries can be arranged in order. For every
node x in the tree, the value of the entry x is greater than the values of all the entries in the left
sub tree of x, and smaller than the values of all the entries in the right sub tree
Full, complete, and balanced binary tree
In a full binary tree of height h, all nodes that are at a level less than h have two children
each. Each node in a full binary tree has left and right sub trees of the same height. Among
binary trees of height h, a full binary tree has as many leaves as possible, and they all are at level
h. In short, a full binary tree has no missing nodes.

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, 2-e, Richard F, Gilberg , Forouzan, Cengage


Data Structures and algorithm analysis in C,2 nd edition Mark Allen Weiss, Pearson
Data Structures and Algorithms, 2008,G.A.V.Pai, TMH
Classic Data Structures, 2-e, Debasis ,Samanta,PHI,2009

DATA STRUCTURES
Handout: UNIT-VI
COURSE: II Year B. Tech

BRANCH: ECE-A

CLASS

YEAR: 2014-2015

: II-I Sem.

Faculty Name: Sri P.KIRAN SREE

Designation: Associate Professor

Topics to be covered in UNIT-VI


Basic concepts, Representations of Graphs: using Linked list and adjacency matrix, Graph
algorithms Graph Traversals (BFS & DFS), applications: Dijkstras shortest path, Transitive
closure, Minimum Spanning Tree using Prims Algorithm, warshalls Algorithm.
SUMMARY
A graph data structure consists of a finite (and possibly mutable) set of ordered pairs,
called edges or arcs, of certain entities called nodes or vertices. As in mathematics, an edge
(x,y) is said to point or go from x to y.
The basic operations provided by a graph data structure G usually include:

adjacent(G, x, y): tests whether there is an edge from node x to node y.

neighbors(G, x): lists all nodes y such that there is an edge from x to y.

add(G, x, y): adds to G the edge from x to y, if it is not there.

delete(G, x, y): removes the edge from x to y, if it is there.

get_node_value(G, x): returns the value associated with the node x.

set_node_value(G, x, a): sets the value associated with the node x to a.

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

You might also like