SlideShare a Scribd company logo
Linear
Data Structure
Feb 1, 2025
What is
Arrays?
Arrays
An array is a data structure consisting of
a collection of elements (values or
variables), each identified by at least one
array index or key. Depending on the
language, array types may overlap (or be
identified with) other data types that
describe aggregates of values, such as
lists and strings.
Is the Arrays always of a fixed size?
Arrays at core are of fixed size only,
but most of the languages provide
dynamic sized arrays using the
underlying fixed sized arrays. For
example, vector in C++, ArrayList in
Java and list in Python. In C language,
the array has a fixed size meaning
once the size is given to it, it cannot
be changed i.e. you can’t shrink it nor
can you expand it.
Applications of Array Data Structures
Below are some applications of arrays.
● Searching: If data in array is sorted, we can search an item in O(log n) time. We can also find
floor(), ceiling(), kth smallest, kth largest, etc efficiently.
● Matrices: Two-dimensional arrays are used for matrices in computations like graph algorithms
and image processing.
● Implementing other data structures: Arrays are used as the underlying data structure for
implementing stacks and queues.
● Dynamic programming: Dynamic programming algorithms often use arrays to store
intermediate results of subproblems in order to solve a larger problem.
● Data Buffers: Arrays serve as data buffers and queues, temporarily storing incoming data like
network packets, file streams, and database results before processing.
Advantages of Array Data Structure
● Efficient and Fast Access: Arrays allow direct and efficient access to any element in the collection
with constant access time, as the data is stored in contiguous memory locations.
● Memory Efficiency: Arrays store elements in contiguous memory, allowing efficient allocation in a
single block and reducing memory fragmentation.
● Versatility: Arrays can be used to store a wide range of data types, including integers,
floating-point numbers, characters, and even complex data structures such as objects and
pointers.
● Compatibility with hardware: The array data structure is compatible with most hardware
architectures, making it a versatile tool for programming in a wide range of environments.
Disadvantages of Array Data Structure
● Fixed Size: Arrays have a fixed size set at creation. Expanding an array requires creating a
new one and copying elements, which is time-consuming and memory-intensive.
● Memory Allocation Issues: Allocating large arrays can cause memory exhaustion, leading to
crashes, especially on systems with limited resources.
● Insertion and Deletion Challenges: Adding or removing elements requires shifting subsequent
elements, making these operations inefficient.
● Limited Data Type Support: Arrays support only elements of the same type, limiting their use
with complex data types.
● Lack of Flexibility: Fixed size and limited type support make arrays less adaptable than
structures like linked lists or trees.
Linear Search
Searching Array
Binary Search
Binary Search is a searching
algorithm used in a sorted
array. In this algorithm, the
element is found by repeatedly
dividing the search interval in
half and deciding the next
interval to find the element.
Linear Search is defined as a
sequential search algorithm that
starts at one end and goes through
each element of a list until the
desired element or group of
elements is found.
Ternary Search
Ternary search is a divide and
conquer algorithm that can be
used to find an element in an
array.
Activity Time!
Input: arr[] = {1, 1, 2, 1, 3, 4, 5, 2, 8};
query[] = [0, 4], [1, 3] [2, 4]
The visualization
What is the output?
Difference Between
Stack and Queue
Data Structures
Stacks
A stack is a linear data structure that follows
the Last In, First Out (LIFO) principle. This
means that the last element added to the
stack is the first one to be removed. It can be
visualized as a pile of plates where you can
only add or remove the top plate.
Operations on Stack
Push
Adds an element to the top of
the stack.
Pop
Removes and returns the top
element of the stack.
Peek (or Top)
Returns the top element of
the stack without removing it.
isEmpty
Checks if the stack is empty.
Size
Returns the number of
elements in the stack.
Use Case of Stacks
The call stack in
programming languages
keeps track of function
calls and returns.
Function Call Management Expression Evaluation Backtracking
Used in parsing
expressions and evaluating
postfix or prefix notations.
Helps in algorithms that
require exploring all
possibilities, such as maze
solving and depth-first
search.
Queues
A queue is a linear data structure that follows the First In,
First Out (FIFO) principle. This means that the first element
added to the queue is the first one to be removed. It can be
visualized as a line of people waiting for a service, where
the first person in line is the first to be served.
Operations on Queue
Enqueue
Adds an element to the end
(rear) of the queue.
Dequeue
Removes and returns the front
element of the queue.
Front (or Peek)
Returns the front element of the
queue without removing it.
isEmpty
Checks if the queue is empty.
Size
Returns the number of
elements in the queue.
Use Case of Queues
Operating systems use
queues to manage tasks and
processes.
Task Scheduling Breadth-First Search (BFS) Buffering
In graph traversal algorithms,
queues help in exploring
nodes level by level.
Used in situations where data
is transferred asynchronously,
such as IO buffers and print
spooling.
Activity Time!

More Related Content

Similar to Linear Data structure Array stacks and Queues (20)

PPTX
DS Module 1.pptx
SaralaT3
 
PPTX
DataStructureccvdgddfffdesddsssdssPpt.pptx
bgmi52926
 
PPTX
Different types of sorting used in programming.pptx
aadithyaaa2005
 
PPTX
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
PPTX
DataStructurePpt.pptx
ssuser031f35
 
PPTX
Introduction to data structures (ss)
Madishetty Prathibha
 
PPT
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
PDF
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
PPTX
ntroduction of Algorithms, Analysing Algorithms. Arrays: Sparse Matrices - Re...
kalaip3
 
PPT
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
sumitbardhan
 
PPTX
Dsa unit 1
ColorfullMedia
 
PPT
Intro ds
John Fathima
 
PPT
1597380885789.ppt
PraveenKumar977108
 
PPTX
Data structure Assignment Help
JosephErin
 
PDF
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
PDF
Unit.1 Introduction to Data Structuresres
amplopsurat
 
PPTX
DS_PPT.pptx
MeghaKulkarni27
 
PPTX
Data_structure.pptx
priya415376
 
PPTX
DSA.pptx based on basic dsa concepts for engineers
SaketKumar846792
 
PPTX
Data structures - Introduction
DeepaThirumurugan
 
DS Module 1.pptx
SaralaT3
 
DataStructureccvdgddfffdesddsssdssPpt.pptx
bgmi52926
 
Different types of sorting used in programming.pptx
aadithyaaa2005
 
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
DataStructurePpt.pptx
ssuser031f35
 
Introduction to data structures (ss)
Madishetty Prathibha
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
ntroduction of Algorithms, Analysing Algorithms. Arrays: Sparse Matrices - Re...
kalaip3
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
sumitbardhan
 
Dsa unit 1
ColorfullMedia
 
Intro ds
John Fathima
 
1597380885789.ppt
PraveenKumar977108
 
Data structure Assignment Help
JosephErin
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
Unit.1 Introduction to Data Structuresres
amplopsurat
 
DS_PPT.pptx
MeghaKulkarni27
 
Data_structure.pptx
priya415376
 
DSA.pptx based on basic dsa concepts for engineers
SaketKumar846792
 
Data structures - Introduction
DeepaThirumurugan
 

Recently uploaded (20)

PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
smart lot access control system with eye
rasabzahra
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
smart lot access control system with eye
rasabzahra
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Ad

Linear Data structure Array stacks and Queues

  • 3. Arrays An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. Depending on the language, array types may overlap (or be identified with) other data types that describe aggregates of values, such as lists and strings.
  • 4. Is the Arrays always of a fixed size? Arrays at core are of fixed size only, but most of the languages provide dynamic sized arrays using the underlying fixed sized arrays. For example, vector in C++, ArrayList in Java and list in Python. In C language, the array has a fixed size meaning once the size is given to it, it cannot be changed i.e. you can’t shrink it nor can you expand it.
  • 5. Applications of Array Data Structures Below are some applications of arrays. ● Searching: If data in array is sorted, we can search an item in O(log n) time. We can also find floor(), ceiling(), kth smallest, kth largest, etc efficiently. ● Matrices: Two-dimensional arrays are used for matrices in computations like graph algorithms and image processing. ● Implementing other data structures: Arrays are used as the underlying data structure for implementing stacks and queues. ● Dynamic programming: Dynamic programming algorithms often use arrays to store intermediate results of subproblems in order to solve a larger problem. ● Data Buffers: Arrays serve as data buffers and queues, temporarily storing incoming data like network packets, file streams, and database results before processing.
  • 6. Advantages of Array Data Structure ● Efficient and Fast Access: Arrays allow direct and efficient access to any element in the collection with constant access time, as the data is stored in contiguous memory locations. ● Memory Efficiency: Arrays store elements in contiguous memory, allowing efficient allocation in a single block and reducing memory fragmentation. ● Versatility: Arrays can be used to store a wide range of data types, including integers, floating-point numbers, characters, and even complex data structures such as objects and pointers. ● Compatibility with hardware: The array data structure is compatible with most hardware architectures, making it a versatile tool for programming in a wide range of environments.
  • 7. Disadvantages of Array Data Structure ● Fixed Size: Arrays have a fixed size set at creation. Expanding an array requires creating a new one and copying elements, which is time-consuming and memory-intensive. ● Memory Allocation Issues: Allocating large arrays can cause memory exhaustion, leading to crashes, especially on systems with limited resources. ● Insertion and Deletion Challenges: Adding or removing elements requires shifting subsequent elements, making these operations inefficient. ● Limited Data Type Support: Arrays support only elements of the same type, limiting their use with complex data types. ● Lack of Flexibility: Fixed size and limited type support make arrays less adaptable than structures like linked lists or trees.
  • 8. Linear Search Searching Array Binary Search Binary Search is a searching algorithm used in a sorted array. In this algorithm, the element is found by repeatedly dividing the search interval in half and deciding the next interval to find the element. Linear Search is defined as a sequential search algorithm that starts at one end and goes through each element of a list until the desired element or group of elements is found. Ternary Search Ternary search is a divide and conquer algorithm that can be used to find an element in an array.
  • 9. Activity Time! Input: arr[] = {1, 1, 2, 1, 3, 4, 5, 2, 8}; query[] = [0, 4], [1, 3] [2, 4] The visualization What is the output?
  • 10. Difference Between Stack and Queue Data Structures
  • 11. Stacks A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means that the last element added to the stack is the first one to be removed. It can be visualized as a pile of plates where you can only add or remove the top plate.
  • 12. Operations on Stack Push Adds an element to the top of the stack. Pop Removes and returns the top element of the stack. Peek (or Top) Returns the top element of the stack without removing it. isEmpty Checks if the stack is empty. Size Returns the number of elements in the stack.
  • 13. Use Case of Stacks The call stack in programming languages keeps track of function calls and returns. Function Call Management Expression Evaluation Backtracking Used in parsing expressions and evaluating postfix or prefix notations. Helps in algorithms that require exploring all possibilities, such as maze solving and depth-first search.
  • 14. Queues A queue is a linear data structure that follows the First In, First Out (FIFO) principle. This means that the first element added to the queue is the first one to be removed. It can be visualized as a line of people waiting for a service, where the first person in line is the first to be served.
  • 15. Operations on Queue Enqueue Adds an element to the end (rear) of the queue. Dequeue Removes and returns the front element of the queue. Front (or Peek) Returns the front element of the queue without removing it. isEmpty Checks if the queue is empty. Size Returns the number of elements in the queue.
  • 16. Use Case of Queues Operating systems use queues to manage tasks and processes. Task Scheduling Breadth-First Search (BFS) Buffering In graph traversal algorithms, queues help in exploring nodes level by level. Used in situations where data is transferred asynchronously, such as IO buffers and print spooling.