Data Structures - Module 1
Data Structures - Module 1
Module 1
ARJUN K P
AP, SCSE
GU
IDENTIFIERS AND KEYWORDS
• Identifiers are basically names given to
program elements such as variables, arrays,
and functions.
• Like every computer language, C has a set of
reserved words often known as keywords that
cannot be used as an identifier
VARIABLES AND CONSTANTS
• A variable is defined as a meaningful name
given to a data storage location in the
computer memory.
• When using a variable, we actually refer to the
address of the memory where the data is
stored.
• Constants are identifiers whose values do not
change
Data Structure
int i, marks[1 ];
for(i= ;i<1 ;i++)
scanf("%d", &marks[i])
OPERATIONS ON ARRAY
• Traversing an array
• Inserting an element in an array
• Searching an element in an array
• Deleting an element from an array
• Merging two arrays
• Sorting an array in ascending or descending
order
Traversing an array
Inserting an element in an array
Algorithm to insert an element in the middle
of an array
Algorithm to delete the last element of an
array
Algorithm to delete an element from the
middle of an array
Merging Two arrays
MULTI-DIMENSIONAL ARRAY
• A multi-dimensional array in simple terms is
an array of arrays
• As we have one index in a one dimensional
array, two indices in a two-dimensional array,
in the same way, we have n indices in an n-
dimensional array or multi-dimensional array.
APPLICATIONS OF ARRAYS
• Arrays are widely used to implement
mathematical vectors, matrices, and other
kinds of rectangular tables.
• Many databases include one-dimensional
arrays whose elements are records.
• Arrays are also used to implement other data
structures such as strings, stacks, queues,
heaps, and hash tables
Row- and column-major order
• row-major order and column-major order are
methods for storing multidimensional
arrays in linear storage such as random access
memory.
APPLICATIONS OF ARRAYS
• Arrays can be used for sorting elements in
ascending or descending order
Linked Lists
• A linked list is a collection of data elements
called nodes in which the linear
representation is given by links from one node
to the next node.
• While declaring arrays, we have to specify the
size of the array, which will restrict the
number of elements that the array can store
Linked Lists
• A linked list does not store its elements in
consecutive memory locations and the user
can add any number of elements to it.
• a linked list does not allow random access of
data.
• Elements in a linked list can be accessed only
in a sequential manner
Basic terminologies
• A linked list, in simple terms, is a linear
collection of data elements
• These data elements are called nodes.
• Linked list is a data structure which in turn
can be used to implement other data
structures
Basic terminologies
• every node contains two parts, an integer and
a pointer to the next node.
• The left part of the node which contains data
may include a simple data type.
• The right part of the node contains a pointer
to the next node (or address of the next node
in sequence).
Basic terminologies
• The last node will have no next node
connected to it, so it will store a special value
called NULL
• the NULL pointer is represented by X.
how a linked list is maintained in the
memory.
SINGLY LINKED LISTS
• A singly linked list allows traversal of data only
in one way.
traversing a Linked List
CIRCULAR LINKED LIST
• In a circular linked list, the last node contains a
pointer to the first node of the list.
DOUBLY LINKED LIST
• A doubly linked list or a two-way linked list is a
more complex type of linked list which
contains a pointer to the next as well as the
previous node in the sequence.
CIRCULAR DOUBLY LINKED LIST
CIRCULAR DOUBLY LINKED LIST
• A circular doubly linked list or a circular two-
way linked list is a more complex type of
linked list which contains a pointer to the next
as well as the previous node in the sequence.
APPLICATIONS OF LINKED LIST - Polynomial
representation
• 6x3 + 9x2 + 7x + 1.