Data Structures-I Linear
Lists
CHAPTER 7.1
Data
Structure
“ A 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, behaviors and properties.
• Data can be summarized in different
ways and new information can be created.
• Data can be represented in the following
ways:
– Raw data
– Data item
Data Type v/s Data
• A dataStructure
type is a set of some values on which
we can perform limited operations like we can’t
use decimal point(.) with an integer nor can we
multiply two strings.
• whereas a data structure provides the method to
store a data, to access it and to manipulate it.
• A data stored in a data structure has its own
method of working. For example insertion and
deletion in a stack happen on the same end.
• Python has a collection data type-list. But when
a list is used as a data structure its behaviour is
different.
Data
Structure
• Simple data structure
– Array or linear List
• Compound data structure
– Linear
• Stack
• Queue
• Linked list
– Non-linear
• Tree
• Python has the following built-in linear data
structure–Lists, Tuples, Dictionaries, Sets
Linear List Arrays
•Here linear list refers to a named list which
contains data elements of same type.
• These elements can be represented by
an index like 0,1,2,…
• Array can be 1D, 2D or 3D
• In python arrays can be implemented
using List data type or numpy arrays
S tac
• It is termed as LIFO ks
structure (Last
in First Out)
because the last input value is accessed first.
• It has a unique way of operation.
• insertion and deletion can be done from only end
which is called the TOP.
Queu
• Queue is called a es structure
FIFO (First In First
Out) because the element that is input first is
accessed first
• In a queue insertion occurs at the rear end and
deletion occurs at the front end.
Linked
• It is a special list inList
which elements are connected
to each other in the form of nodes
• Every node has two or more parts among
which one at least one part has the capacity to
store the address of next node
• In this insertion and deletion occurs in any place
• Linked list is of types- singly and doubly
Tre
• It is a multi level dataes
structure in which nodes are
related to each other hierarchically
• The bottom most node in tree which is not
connected to any other node is called leaf
• The top most node is called root
Operations in Data Structure
• Insertion
• Deletion
• Searchi
ng
• Traversa
l
• Sorting
• Merging
Linear
• List
A linear data structure is one whose elements follow a
sequence
• Elements of same data type stored in a sequence
form an array
• Array is the basic data structure
Linear Search in Linear
List
Binary Search in
Linear List
Insertion in a Linear List
(Traditional)
Insertion Using bisect
module
Deletion from sorted
Linear List
List
We create list comprehension
using many ways:
First Way:
Second Way:
• Third way: It is called list comprehension
List
comprehension
num<5 Num>5 so
multiplied by 2
Advantages of List
comprehension
• Code reduction
• Faster code processing
Nested/2 D
• In a list if there Lists
are one or more list as elements, the
list is called nested list
• A 2D list is one in which all elements are of same
dimension
Creation of Nested/2 D
Lists
We can use a nested loop to create
nested/2D list
-
Traversal of Nested/2 D
Lists
Accessing 2D List
Elements
Slicing 2D
List