Linear List and Data Structure-1-3
Linear List and Data Structure-1-3
Data Structure is a named group of data of different data types which is stored in a specific way and can be
processed as a single unit. A data structure has well-defined operations, behaviour and properties. Data
Structure is the organisation of data in the computer’s memory.
Data Type defines the type of values we can store and operations we can perform. For example- in a variable
of int data type we cannot store decimal values. Data type also specifies the amount of memory a variable
consumes. Data Structure is the physical implementation that clearly defines a way of storing, accessing and
manipulation of data stored in Computer’s memory.
Python supports Lists as a collection of elements of heterogeneous data type. In Python we will use List as a
Data Structure.
Simple Data Structure: These are built from primitive data types like integer, float, string
or Boolean.
Example: Linear List or Array.
Complex Data Structure : Simple data structures can be combined in various ways to form
more complex data structures called Compund Data Structure. It is of two types:
i) Linear : These are single level data structure i.e. elements are stored in a
Linear or Sequential form.
Example : STACK, QUEUE, LINKED LIST
ii) Non-Linear: These are multilevel data structure.
Example: TREE and GRAPH
Introduction to different types of Data Structure:
Linear List/Arrays:
It refers to a named list of finite number of similar data elements. Each of the data elements
can be accessed by its unique index/subscript position usually 0,1,2,3,…
For example- if the list named “mylist” contains 10 elements -then the first element will be
mylist[0], second will be mylist[1] and so on.
Arrays can be Single Dimensional or Multi Dimensional. In Python- arrays are implemented
through List data types as Linear List or through NumPy arrays.
Stack:
It is a Data Structure that allows us to insert and delete items from one end of the list
Only. This end is called TOP.
Stack works on LIFO principle. It means the item which is added in the list at last will be
removed from the list at first.
Real life Examples: Stack of Plates, Stack of Books etc.
Computer based Examples: Undo Operation, Function Call etc.
Queue:
It is a Data Structure that allows insertion and deletion of elements from different ends
i.e. insertion from REAR END and deletion from FRONT END.
Queue works on FIFO principle. It means the item which is added in the list at first will
will be removed from the list at first.
Real life Examples: People standing in Queue for booking tickets.
Computer based Examples: Keyboard typing, Printing Job etc.
Linked List:
Linked List is a dynamic data structure i.e. the size of a Linked List is not pre-determined before
the execution of the program. It consumes memory as per requirement during runtime and
every item allocated dynamically is be known as NODE.
Each NODE contains 2 parts:
(1) INFO/LIST part which stores the actual data to store like roll no. name, marks etc.
(2) LINK part which holds the memory address of the next allocated node in memory
creating chain of linked items.
There are two types of Linked List- (i) Singly Linked List and (ii) Doubly Linked List
Trees:
Trees are multilevel Data Structure having hierarchical relationships among its elements called
Nodes.
Topmost node is called the Root of the tree and bottom most node is called Leaf of the tree.
Each of the node holds the address of nodes below it.