The document outlines a course on data structures. It covers 10 units: pointers and dynamic memory allocation, arrays, strings, structures and unions, file handling, stacks and queues. It defines data structures and different types including linear (arrays, stacks, queues, linked lists) and non-linear (trees and graphs). It also discusses static and dynamic data structures, basic terminology, why we should learn data structures, and common operations like traversal, search, insertion, deletion, sorting, and merge.
2. COURSE OUTLINE
2
Unit 1
Pointers and
dynamic memory
allocation
1
Unit 2
Arrays
2
Unit 3..
Strings, Structures
and Unions
3
Unit 4
File Handling
4
Unit 5
Stacks and Queues
5
3. 3
INTRODUCTION TO DATA STRUCTURES
Data structure is a representation of the logical relationship existing between individual elements of data. In other
words, a data structure defines a way of organizing all data items that consider not only the elements stored but
also their relationship to each other.The term data structure is used to describe the way data is stored.
To develop a program of an algorithm we should select an appropriate data structure for that algorithm.
Therefore, the data structure is represented as:
Algorithm + Data structure = Program
4. 4
LINEAR AND NONLINEAR DATA STRUCTURE
Linear Data Structure:
A data structure is said to be linear if its elements form a sequence or a linear list. Linear data structures like an
array, stacks, queues, and linked lists organize data in linear order. In these data structures, one element is connected
to only one another element in a linear form.
Non-linear Data Structure:
A data structure is said to be nonlinear if its elements form a hierarchical classification where data items appear at
various levels. one element is connected to the 'n' number of elements. Trees and Graphs are widely used non-linear
data structures. Tree and graph structures represent the hierarchical relationship between individual data elements.
Graphs are nothing but trees with certain restrictions removed.
Data structures are divided into two types:
Primitive data structures.
Non-primitive data structures.
5. 5
PRIMITIVE AND NON-PRIMITIVE DATA STRUCTURES
Primitive Data Structures: These are the basic data structures that directly operate upon the
machine instructions.They have different representations on different computers. Integers, floating
point numbers, character constants, string constants, and pointers come under this category.
Non-primitive data structures: These are more complicated data structures and are derived from
primitive data structures.They emphasize grouping the same or different data items with a relationship
between each data item. Arrays, lists, and files come under this category.
6. 6
STATIC AND DYNAMIC DATA STRUCTURE
Data structures can also be classified as:
Static data structure: It is a type of data structure where the size is allocated at the compile
time.Therefore, the maximum size is fixed.
Dynamic data structure: It is a type of data structure where the size is allocated at the run
time.Therefore, the maximum size is flexible.
7. 7
BASIC TERMINOLOGIES RELATED TO DATA STRUCTURES
Data: We can define data as an elementary value or a collection of values. For example, the Employee's name and ID
are the data related to the Employee.
Data Items: A Single unit of value is known as Data Item.
Group Items: Data Items that have subordinate data items are known as Group Items. For example, a student’s name
can have a first, middle, and last name.
Elementary Items: Data Items that are unable to divide into sub-items are known as Elementary Items. For example,
the Roll Number of the students.
Entity and Attribute: A class of certain objects is represented by an Entity. It consists of different Attributes. Each
Attribute symbolizes the specific property of that Entity. For example,
Student Name Roll Number Gender Specialization Year of admission
Rajneesh 425 Male AI ML 2022
Ashutosh 424 Male Data Science 2022
8. 8
Field: A single elementary unit of information symbolizing the Attribute of an Entity is known as
Field.
Record: A collection of different data items are known as a Record. For example, if we talk about the
employee entity, then its name, id, address, and job title can be grouped to form the record for the
employee.
File: A collection of different Records of one entity type is known as a File. For example, if there are
100 employees, there will be 25 records in the related file containing data about each employee.
BASIC TERMINOLOGIES RELATED TO DATA STRUCTURES
9. 9
WHY SHOULD WE LEARN DATA STRUCTURES?
1. Data Structures and Algorithms are two of the key aspects of Computer Science.
2. Data Structures allow us to organize and store data, whereas Algorithms allow us to process that data
meaningfully.
3. Learning Data Structures and Algorithms will help us become better Programmers.
4. We will be able to write code that is more effective and reliable.
5. We will also be able to solve problems more quickly and efficiently.
10. 10
TYPES OF LINEAR DATA STRUCTURES
1. Array
2. Linked Lists
3. Stacks
4. Queues
11. 11
ARRAY
Arrays are most frequently used in programming.
Mathematical problems like matrix, algebra and etc. can be easily handled by arrays.An array is a
collection of homogeneous data elements described by a single name.
Each element of an array is referenced by a subscripted variable or value, called subscript or index
enclosed in parenthesis.
If an element of an array is referenced by a single subscript, then the array is known as a one-
dimensional array or linear array and if two subscripts are required to reference an element, the array
is known as a two-dimensional array, and so on.
Analogously the arrays whose elements are referenced by two or more subscripts are called multi-
dimensional arrays.
12. 12
TEACH A COURSE
ONE DIMENSIONAL ARRAY
One-dimensional array (or linear array) is a set of ‘n’ finite numbers of homogenous data elements such as :
The elements of the array are referenced respectively by an index set consisting of ‘n’ consecutive numbers.
The elements of the array are stored respectively in successive memory locations.‘n’ number of elements is called
the length or size of an array.
The elements of an array ‘A’ may be denoted in C as
A[0],A[1],A[2], ......A[n –1]
The number ‘n’ in A[n] is called a subscript or an index and A[n] is called a subscripted variable.
If ‘n’ is 10, then the array elements A[0],A[1]......A[9] are stored in sequential memory locations as follows
13. 13
MULTI DIMENSIONAL ARRAY
• If we are reading or writing a two-dimensional array, two loops are required. Similarly, the array of ‘n’ dimensions
would require ‘n’ loops.The structure of the two-dimensional array is illustrated in the following figure:
int A[10][10];
14. 14
LISTS
an array is an ordered set, which consists of a fixed number of elements.
No deletion or insertion operations are performed on arrays.Another main disadvantage is its fixed length; we
cannot add elements to the array.
Lists overcome all the above limitations. A list is an ordered set consisting of a varying number of elements to
which insertion and deletion can be made.A list represented by displaying the relationship between the adjacent
elements is said to be a linear list.Any other list is said to be non-linear.
List can be implemented by using pointers. Each element is referred to as a node; therefore a list can be defined
as a collection of nodes as shown below :
15. 15
TYPES OF LINKED LISTS
1. Singly Linked List: A Singly Linked List is the most common type of Linked List. Each node has data and
a pointer field containing an address to the next node.
2. Doubly Linked List: A Doubly Linked List consists of an information field and two pointer fields. The
information field contains the data. The first pointer field contains an address of the previous node,
whereas another pointer field contains a reference to the next node. Thus, we can go in both
directions (backward as well as forward).
3. Circular Linked List: The Circular Linked List is similar to the Singly Linked List. The only key difference
is that the last node contains the address of the first node, forming a circular loop in the Circular
Linked List.
16. 16
STACKS
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. Stacks can be implemented with the help of contiguous
memory, an Array, non-contiguous memory, a Linked List
17. 17
QUEUES
A Queue is a linear data structure similar to a Stack with some limitations on the insertion and deletion of the
elements.The insertion of an element in a Queue is done at one end, and the removal is done at another or
opposite end.Thus, we can conclude that the Queue data structure follows FIFO (First In, First Out) principle to
manipulate the data elements. Implementation of Queues can be done using Arrays, Linked Lists, or Stacks.
19. 19
TREES
A Tree is a Non-Linear Data Structure and a
hierarchy containing a collection of nodes such that
each node of the tree stores a value and a list of
references to other nodes (the "children").
The Tree data structure is a specialized method to
arrange and collect data in the computer to be
utilized more effectively. It contains a central node,
structural nodes, and sub-nodes connected via
edges.
20. 20
A Graph is another example of a Non-Linear Data
Structure comprising a finite number of nodes or vertices
and the edges connecting them. The Graphs are utilized to
address problems of the real world in which it denotes the
problem area as a network such as social networks, circuit
networks, and telephone networks.
21. 21
OPERATIONS OF DATA STRUCTURES
1. Traversal: Traversing a data structure means accessing each data element exactly once so it can be administered. For
example, traversing is required while printing the names of all the employees in a department.
2. Search: Search is another data structure operation which means to find the location of one or more data elements that
meet certain constraints. Such a data element may or may not be present in the given set of data elements. For
example, we can use the search operation to find the names of all the employees who have the experience of more
than 5 years.
3. Insertion: Insertion means inserting or adding new data elements to the collection. For example, we can use the
insertion operation to add the details of a new employee the company has recently hired.
4. Deletion: Deletion means to remove or delete a specific data element from the given list of data elements. For example,
we can use the deleting operation to delete the name of an employee who has left the job.
5. Sorting: Sorting means to arrange the data elements in either Ascending or Descending order depending on the type of
application. For example, we can use the sorting operation to arrange the names of employees in a department in
alphabetical order or estimate the top three performers of the month by arranging the performance of the employees
in descending order and extracting the details of the top three.
22. 22
OPERATIONS OF DATA STRUCTURES
6. Merge: Merge means to combine data elements of two sorted lists in order to form a single list of sorted data
elements.
7. Create: Create is an operation used to reserve memory for the data elements of the program. We can perform
this operation using a declaration statement. The creation of data structure can take place either during the
following:
1. Compile-time
2. Run-time
8. Selection: Selection means selecting a particular data from the available data. We can select any particular data
by specifying conditions inside the loop.
9. Update: The Update operation allows us to update or modify the data in the data structure. We can also update
any particular data by specifying some conditions inside the loop, like the Selection operation.
10. Splitting: The Splitting operation allows us to divide data into various subparts decreasing the overall process
completion time.