Introduction-to-Data-Structure
Introduction-to-Data-Structure
The name "Data Structure" is a combination of two words: "Data" and "Structure".
Let's go over each word individually:
• Data: Data is information that must be processed and stored in a computer.
Data can be anything from numbers to characters to dates to photos to
videos.
• Structure: Structure refers to how data is structured. It specifies the
relationship between various data elements and how they are kept in
memory. The structure has an impact on the efficiency of data operations.
3. Overhead in Maintenance
Maintaining complex data structures involves careful memory management and
error handling.
Example:
In a Graph, ensuring correct connections, preventing loops or duplicates, and
updating nodes can be tedious.
6. Learning Curve
Explanation:
For new programmers, understanding how to choose and implement the correct
data structure takes time and practice.
Arrays
An Array is a collection of elements of the same data type stored in contiguous
memory locations. It is a linear data structure that provides efficient access to its
elements based on their indices. Each element in an array is referred to by its
index, which is an integer that starts from 0. The elements are stored in a
contiguous block of memory, which allows for fast access to elements based on
their indices.
Arrays can be used to store a variety of data types, including numbers, strings, and
objects. Arrays can have a single dimension (also called a one-dimensional array) or
multiple dimensions (e.g. two-dimensional arrays, three-dimensional arrays, etc.).
Arrays are widely used in programming to store and manipulate data. They are
used as building blocks for more complex data structures and are used in a variety
of algorithms and applications.
Array data structures have many applications, including:
1. Storing collections of data, such as lists of items or numbers
2. Implementing mathematical objects such as matrices and vectors
3. Implementing dynamic data structures such as stacks, queues, and hash
tables
4. Implementing tables, databases, and look-up tables
5. Implementing trees and graphs
6. Image processing and computer graphics
7. Representing strings and text data
8. Performing numerical computations and simulations.
Linked List
A linked list is a data structure consisting of a sequence of nodes, where each node
holds data and a reference (link) to the next node in the sequence. The reference is
stored in a field called "next". The last node in the list contains a null reference
indicating the end of the list.
There are two main types of linked lists: singly linked lists and doubly linked lists.
In a singly linked list, each node only has a reference to the next node in the list,
while in a doubly linked list, each node has a reference to both the next node and
the previous node.
A linked list has the following advantages over an array:
1. Dynamic size: Linked lists can grow or shrink in size during execution of a
program, while the size of an array needs to be fixed when it is declared.
2. Ease of insertion and deletion: Inserting or deleting an element in a linked
list is easier compared to arrays, as elements in linked lists do not need to be
shifted.
3. No wastage of space: In arrays, unused space is wasted, while in linked lists,
space is used only as needed.
Queue
A queue is a type of linear data structure that operates on the First in First Out
(FIFO) principle. That is, the first item put into the queue will be the first to be
removed. The last item added to the queue will be removed at last.