📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 2 – Python Data Structures (university of allahabad)
🔴 UNIT 2 – Python Data Structures
1️⃣ Introduction to Python Data Structures
✅ What is a Data Structure?
A data structure is a way to store, organize, and manage data efficiently so that operations can be performed easily.
Python provides built-in data structures, such as:
2️⃣ Python Data Types (Revisited)
🔹 Mutable Data Types
Data that can be changed after creation.
-
List
-
Dictionary
-
Set
🔹 Immutable Data Types
Data that cannot be changed.
-
Integer
-
Float
-
String
-
Tuple
3️⃣ Python Lists
✅ Definition
A list is an ordered, mutable collection of elements.
Example:
🔹 List Characteristics
✔ Ordered
✔ Mutable
✔ Allows duplicate values
✔ Indexed
🔹 List Operations
Accessing elements
Slicing
Adding elements
Removing elements
4️⃣ List Slicing
Syntax:
Example:
Output:
5️⃣ Indexing
-
Positive indexing → Left to right
-
Negative indexing → Right to left
6️⃣ List Concatenation
Output:
7️⃣ Searching in Python
🔹 Linear Search
Searches element one by one.
✔ Simple
❌ Slow for large data
🔹 Binary Search
Works only on sorted lists
✔ Fast
✔ Efficient
8️⃣ Inductive Function Definition
Meaning:
A function defined using:
-
Base case
-
Recursive case
Example:
9️⃣ Sorting Techniques
🔹 Selection Sort
Steps:
-
Find minimum
-
Swap with first element
-
Repeat
🔹 Insertion Sort
🔟 In-Place Sorting
Definition:
Sorting without using extra memory.
✔ Selection Sort
✔ Insertion Sort
1️⃣1️⃣ Tuples
Definition:
Tuple is an ordered but immutable collection.
✔ Faster than list
✔ Used for fixed data
1️⃣2️⃣ Mutability Concept
| Data Type | Mutable |
|---|---|
| List | Yes |
| Tuple | No |
| String | No |
| Dictionary | Yes |
1️⃣3️⃣ Programs Using Lists
Find Maximum Element
Find Minimum Element
Find Mean
Comments
Post a Comment