Kurikulum Merdeka : Informatika (SMA Kelas X) || Stack And Queue
Table of Contents
Introduction
This tutorial provides a step-by-step guide to understanding Stack and Queue data structures as part of the Kurikulum Merdeka Informatika for SMA Kelas X. It is designed for both educators and students to facilitate learning and assessment throughout the course.
Step 1: Understanding Stack Data Structure
- Definition: A stack is a collection of elements that follows the Last In, First Out (LIFO) principle. The last element added to the stack is the first one to be removed.
- Operations:
- Push: Add an element to the top of the stack.
- Pop: Remove the element from the top of the stack.
- Peek: View the top element without removing it.
Practical Advice
- Visualize stacks using real-world examples, such as a stack of plates.
- Implement a stack in programming using an array or linked list.
Step 2: Implementing Stack in Code
Here’s a simple example of how to implement a stack using Python:
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop() if not self.is_empty() else None
def peek(self):
return self.items[-1] if not self.is_empty() else None
def is_empty(self):
return len(self.items) == 0
Step 3: Understanding Queue Data Structure
- Definition: A queue is a collection of elements that follows the First In, First Out (FIFO) principle. The first element added is the first one to be removed.
- Operations:
- Enqueue: Add an element to the end of the queue.
- Dequeue: Remove the element from the front of the queue.
- Front: View the front element without removing it.
Practical Advice
- Use real-world examples like a line of people waiting for service to illustrate queues.
- Discuss the importance of queues in scenarios like task scheduling.
Step 4: Implementing Queue in Code
Here’s an example of how to implement a queue using Python:
class Queue:
def __init__(self):
self.items = []
def enqueue(self, item):
self.items.insert(0, item)
def dequeue(self):
return self.items.pop() if not self.is_empty() else None
def front(self):
return self.items[-1] if not self.is_empty() else None
def is_empty(self):
return len(self.items) == 0
Step 5: Applying Stack and Queue in Real-World Scenarios
- Discuss applications for stacks:
- Undo mechanisms in software applications.
- Parsing expressions in compilers.
- Discuss applications for queues:
- Managing requests on a server.
- Print job scheduling.
Conclusion
Understanding stack and queue data structures is essential for programming and computer science. This tutorial offers foundational knowledge and practical implementations in Python to help you grasp these concepts. As you advance, consider experimenting with different applications and enhancing your understanding by creating projects that utilize these data structures.