Data Structures Introduction1
Data Structures Introduction1
Dr Deepak Gupta
Assistant Professor, SMIEEE
CSED, MNNIT Allahabad, Prayagraj
Email: deepakg@mnnit.ac.in
Course Description
This course introduces the student’s fundamentals of data structures and takes
them forward to software design along with the course on Algorithms. It details
how the choice of data structures impacts the performance of programs for given
software application. This is a precursor to DBMS and Operating Systems. A lab
course is associated with it to strengthen the concepts.
Syllabus
UNIT 1: UNIT-1: Introduction: Basic Terminology, Elementary Data Organization,
Algorithm, Efficiency of an Algorithm, Time and Space Complexity, Asymptotic
notations: Theta, Big-O, and Omega, Time-Space trade-off. Abstract Data Types (ADT)
UNIT II: Arrays: Definition, Single and Multidimensional Arrays, Representation of
Arrays: Row Major Order, and Column Major Order, Application of arrays, Sparse
Matrices and their representations.
Linked Lists: Array Implementation and Dynamic Implementation of Singly Linked
Lists, Doubly Linked List, Circularly Linked List, Operations on a Linked List.
Insertion, Deletion, Traversal, Polynomial Representation and Addition, Generalized
Linked List
Stacks: Abstract Data Type, Primitive Stack operations: Push & Pop, Array and Linked
Implementation of Stack in C, Application of stack: Prefix and Postfix Expressions,
Evaluation of postfix expression, Recursion, Tower of Hanoi Problem, Simulating
Recursion, Principles of recursion, Tail recursion, Removal of recursion
Queues: Abstract Data Type, Operations on Queue: Create, Add, Delete, Full and
Empty, Circular queues, Array and linked implementation of queues in C, Deque and
Priority Queue.
Syllabus
UNIT III: Basic terminology, k-ary trees, Binary Trees, Binary Tree Representation: Array
Representation and Dynamic Representation, Complete Binary Tree, Algebraic Expressions,
Extended Binary Trees, Array and Linked Representation of Binary trees, Tree Traversal
algorithms: In order, Preorder and Post order, Binary Search Trees, Threaded Binary trees,
Traversing Threaded Binary trees, Forest, Huffman algorithm, Heap, B/B+ Tree, AVL tree
UNIT IV: Sequential search, Binary Search, Comparison and Analysis Internal Sorting:
Bubble Sort, Selection Sort, Insertion Sort, Two Way Merge Sort, Heap Sort, Quick Sort,
Hashing
Unit V: Terminology, Sequential and linked Representations of Graphs: Adjacency Matrices,
Adjacency List, Adjacency Multi list, Graph Traversal: Depth First Search and Breadth First
Search, Connected Component, Spanning Trees, Minimum Cost Spanning Trees: Prims and
Kruskal algorithm. Shortest Path algorithm: Dijikstra Algorithm
Books
Text Books:
Reference Books:
1. Horowitz and Sahani, “Fundamentals of Data Structures”, Galgotia
Publication
2. Donald Knuth, “The Art of Computer Programming”, vol. 1 and vol. 3.
3. Jean Paul Trembley and Paul G. Sorenson, “An Introduction to Data
Structures with applications”, McGraw Hill
4. R. Kruse et al, “Data Structures and Program Design in C”, Pearson
Education
5. Lipschutz, “Data Structures” Schaum’s Outline Series, TM
Time Table
Introduction
Data: Data is the plural of “datum” (which is rarely used) and may be thought
of as representing numbers, words, facts, figures, images, etc.
Data Type: A data type is a collection of objects and a set of operations that
act on those objects.
For example in C, int data type can take values in a range and operations that
can be performed are addition, subtraction, multiplication, division, bitwise
operations etc.
Data type or Primitive Data types are the predefined data types that are
supported in the programming language. The size depends upon the type of
data type. Primitive Data types can hold only a single value in one specific
location.
int marks[10];
marks[0] marks[1] marks[2] marks[3] marks[4] marks[5] marks[6] marks[7] marks[8] marks[9]
Dynamic Data Structures:
The data structures having a dynamic size are known as Dynamic Data
Structures. The memory of these data structures is allocated at the run time,
and their size varies during the run time of the code. Moreover, the user
can change the size as well as the data elements stored in these data
structures at the run time of the code.
Linked Lists
A Linked List is another example of a linear data structure used to store a
collection of data elements dynamically. Data elements in a linked list are
represented by the nodes, connected using links or pointers.
Stack
A Stack is a Linear Data Structure that follows the LIFO (Last In, First Out)
principle that allows operations like insertion and deletion from one end of
the Stack, i.e., Top.
Real-life examples of Stacks are piles of books,
a deck of cards, piles of money, and many
more.
Queue
It follows the First-In-First-Out (FIFO) principle. Elements are inserted at the
back of the queue and removed from the front.
Non-Linear Data Structures
Non-Linear Data Structures are data structures where the data elements are
not arranged in sequential order. Here, the insertion and removal of data are
not feasible in a linear manner. There exists a hierarchical relationship
between the individual data items.
G = (V, E)
Algorithm: An algorithm is a finite set of instructions that, if followed,
accomplishes a particular task.
In addition, all algorithms must satisfy the following criteria:
1. Input: There are zero or more quantities that are externally supplied.
The fixed part includes space needed for storing instructions, constants,
variables, and structured variables.
float abc(float a, float b, float c)
{ Sabc(I) = 0.
return a+b+b*c+(a+b-c)/(a+b)+4
}
Variable part includes space needed for the recursion stack, and for
structured variables that are allocated space dynamically during the run-
time of the program.
Type Name Number of bytes
Ex: Recursive function for summing a list
Parameter: array pointer list[] 4
of numbers
float rsum(float list[], int n) Parameter: integer n 4
{
return address 4
if (n) return rsum(list, n-1)+list(n-1);
return 0; Total per recursive call 12
}
Srsum(Max_size) = 12*Max_size.
Ex: Iterative function for summing a list of numbers
float sum(float list[], int n)
{
float tempsum = 0;
int i; Sabc(I) = 0.
for(i=0; i<n; i++)
tempsum += list[i];
return tempsum
} Time Complexity
1 1 1 1 1 1 1 2
2 1 1 2 2 4 8 4
4 1 2 4 8 16 64 8
8 1 3 8 24 64 512 256