assignment final (2)
assignment final (2)
fasil campus
department of computer engineering
algorithm assignment
name id
asmamaw kassie 00727/14
GONDAR ETHIOPIA
2. Backtracking 🔄✨
Backtracking recursively explores all possibilities and backtracks when a solution is not feasible.
• Examples:
○ Solving puzzles like Sudoku 🧩 and N-Queens Problem ♟.
○ Combinatorial problems like Subset Sum and Permutation Generation.
🔑 Applications:
• Game Solvers 🎮
• Cryptography 🔒
• Pathfinding Algorithms 📍
Page 2
• Greedy Choice Property: A locally optimal choice leads to a globally optimal solution.
• Optimal Substructure: The problem can be broken down into smaller subproblems that can be
solved independently.
2. Graph Algorithms 🌐🗺
Greedy techniques are widely used in finding paths, spanning trees, and networks.
• Minimum Spanning Tree (MST):
○ Prim's Algorithm
○ Kruskal's Algorithm
• Shortest Path:
○ Dijkstra’s Algorithm for weighted graphs.
🔑 Real-World Applications:
• Network design (telecommunications) 📡
• Routing protocols 🚦
3. Huffman Encoding 📜🔢
Huffman’s algorithm constructs an optimal binary tree for data compression using a greedy approach.
🔑 Real-World Applications:
• Compression in ZIP files 📂
• Transmission protocols in telecommunications 📞
Page 3
• Doesn’t guarantee the optimal solution for all problems.
• Works only when the greedy choice property and optimal substructure hold.
1. Hashing Algorithms 💡🔑
Overview
Hashing is a technique for mapping data to a fixed-size value (called a hash) using a mathematical
function.
• Primary Purpose: Quickly locate or retrieve data.
• Key Idea: A hash function converts input data into a compact numerical value (hash code) that
represents the original data.
• Structure: The hash code is used as an index to store/retrieve data in a hash table.
Real-Time Applications of Hashing 🌍
1. Data Storage and Retrieval 📚
○ Database Indexing: Hashing is used to locate records efficiently.
○ Cache Mechanisms: Store data for fast lookup (e.g., LRU Cache).
2. Password Security 🔒
○ Hashing is used in password storage to protect sensitive data.
○ Algorithms like SHA-256 ensure secure hash generation.
3. Data Integrity Checks ✅
○ Hash functions like MD5 and SHA verify the integrity of files.
○ Used in detecting file tampering during downloads.
4. Load Balancing 🌐
○ Hashing distributes tasks evenly across servers or storage devices.
○ Example: Web servers distributing client requests.
5. Compiler Design 🛠
○ Hashing helps store and retrieve symbols in symbol tables.
6. Blockchain 🔗
○ Hashing ensures the security and immutability of blockchain transactions.
2. Heap Algorithms 🏗🔼
Overview
A heap is a specialized tree-based data structure that satisfies the heap property:
• Max-Heap: The parent node is always greater than or equal to its children.
• Min-Heap: The parent node is always less than or equal to its children.
Heap algorithms are used to manage and retrieve data with specific priority efficiently.
Real-Time Applications of Heap Algorithms 🌟
1. Priority Queues 📤🔄
○ Implemented using heaps to manage tasks based on priority.
○ Example: Operating systems scheduling processes (CPU scheduling).
2. Sorting (Heap Sort) 📊
○ A sorting technique using a binary heap to arrange elements in ascending or descending
order.
3. Graph Algorithms 🌐
○ Dijkstra's Shortest Path Algorithm uses a min-heap to prioritize nodes based on distance.
○ Prim's Algorithm for minimum spanning trees relies on heaps.
4. Dynamic Median Finding 📈📉
○ Maintaining two heaps (min-heap and max-heap) to find the median in a stream of numbers
dynamically.
5. Memory Management 📦
○ Heaps are used in dynamic memory allocation in languages like C and C++.
○ Allocates or deallocates memory blocks efficiently.
⏳
Page 4
6. Event Simulation Systems ⏳
○ Events are scheduled and managed using heaps to handle the next event in priority order.
7. Data Compression 📜
○ Huffman Coding: A min-heap is used to build the encoding tree.
Page 5
2. Quality Inspection 🔍
○ Inspecting items one by one in a production line.
3. A endance Records 🗂
○ Finding a student’s name in an unsorted attendance sheet.
4. Inventory Management 🛒
○ Locating a specific product in a disorganized stock.
Bubble Sort 🫧
Overview
Bubble sort is simple and intuitive but inefficient for large datasets due to its O(n²) time complexity.
Applications:
Page 6
Applications:
1. Education 🏫
○ Teaching sorting concepts in programming classes.
2. Small Data Sorting 📜
○ Organizing small datasets where efficiency isn't critical.
3. Visual Simulations 🎥
○ Used to demonstrate sorting techniques interactively.
Selec on Sort ✔
Overview
Selection sort is straightforward and suitable for small datasets. It minimizes swaps but is still inefficient
for larger datasets due to O(n²) complexity.
Applications:
1. Embedded Systems 📡
○ Sorting small datasets in low-memory environments.
2. Hardware Systems 🖥
○ Arranging data in memory-constrained devices.
3. Name Tags 🏷
○ Sorting names alphabetically for events or meetings.
Page 7