0% found this document useful (0 votes)
7 views4 pages

Dsa 02

Linear data structures store data sequentially and include arrays, lists, stacks, queues, and deques. Each structure has unique characteristics and operations, such as fixed size for arrays and dynamic resizing for lists. These structures are essential for various applications, with stacks and queues serving specific use cases like undo operations and task scheduling.

Uploaded by

22bph016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Dsa 02

Linear data structures store data sequentially and include arrays, lists, stacks, queues, and deques. Each structure has unique characteristics and operations, such as fixed size for arrays and dynamic resizing for lists. These structures are essential for various applications, with stacks and queues serving specific use cases like undo operations and task scheduling.

Uploaded by

22bph016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Structures Part 1 - Linear Structures

Introduction to Linear Structures


Linear data structures store data in a sequential manner. Each element is connected to its
previous and next elements. They are easy to implement and provide efficient traversal.

Common Linear Structures:

●​ Arrays​

●​ Lists​

●​ Stacks​

●​ Queues​

●​ Deques​

Arrays
An array is a collection of items stored at contiguous memory locations.

Characteristics:

●​ Fixed size​

●​ Homogeneous elements​

●​ Indexed access​

Operations:

●​ Access: O(1)​

●​ Insertion: O(n)​
●​ Deletion: O(n)​

Example in Python:

arr = [1, 2, 3, 4, 5]

print(arr[2]) # Access element

arr.append(6) # Insertion

arr.pop(1) # Deletion

Lists
Lists in Python are dynamic arrays that can hold heterogeneous data.

Characteristics:

●​ Dynamic resizing​

●​ Supports various data types​

●​ Built-in methods for manipulation​

Example:

my_list = ['apple', 42, 3.14]

my_list.append('banana')

print(my_list)

Stacks
A stack is a LIFO (Last In, First Out) data structure.

Operations:
●​ Push: Add an item to the top​

●​ Pop: Remove the top item​

Use Cases:

●​ Undo operations in software​

●​ Function call management​

Implementation:

stack = []

stack.append(10)

stack.append(20)

print(stack.pop()) # Output: 20

Queues
A queue is a FIFO (First In, First Out) data structure.

Operations:

●​ Enqueue: Add an item to the rear​

●​ Dequeue: Remove an item from the front​

Use Cases:

●​ Print queue management​

●​ Task scheduling​

Implementation:
from collections import deque

queue = deque(['A', 'B', 'C'])

queue.append('D')

queue.popleft()

Deques
Double-ended queues (deques) allow insertion and deletion from both ends.

Use Cases:

●​ Palindrome checking​

●​ Browser history navigation​

Example:

dq = deque([1, 2, 3])

dq.appendleft(0)

dq.append(4)

dq.pop()

dq.popleft()

Conclusion
Linear data structures are fundamental for various applications, from simple data storage to
complex operations. In the next document, we will explore non-linear data structures like trees
and graphs.

You might also like