logo CBCE Skill INDIA

Welcome to CBCE Skill INDIA. An ISO 9001:2015 Certified Autonomous Body | Best Quality Computer and Skills Training Provider Organization. Established Under Indian Trust Act 1882, Govt. of India. Identity No. - IV-190200628, and registered under NITI Aayog Govt. of India. Identity No. - WB/2023/0344555. Also registered under Ministry of Micro, Small & Medium Enterprises - MSME (Govt. of India). Registration Number - UDYAM-WB-06-0031863

What is an example of ADT?


Example of ADT
 

An example of an Abstract Data Type (ADT) is the "Stack." A stack is a widely used ADT that represents a linear data structure where elements are stored and retrieved in a Last-In, First-Out (LIFO) fashion. This means that the last item pushed onto the stack is the first item to be popped off. Stacks are commonly used in programming for various applications, such as function call management, expression evaluation, and undo operations.

 

Here's an abstract Definition of a Stack ADT:

 

Stack ADT:

  • Data Structure: A stack is a collection of elements where elements are added and removed from one end, often referred to as the "top" of the stack.

  • Operations: A stack supports the following fundamental operations:

    1. Push: Adds an element to the top of the stack.
    2. Pop: Removes and returns the element at the top of the stack.
    3. Peek (or Top): Retrieves the element at the top of the stack without removing it.
    4. IsEmpty: Checks if the stack is empty.
    5. Size: Returns the number of elements in the stack.

 

Here's an example of how you might use a Stack ADT in a programming context (in Python):

# Create an empty stack
stack = []

# Push elements onto the stack
stack.append(1)
stack.append(2)
stack.append(3)

# The stack now contains [1, 2, 3]

# Pop elements from the stack
top_element = stack.pop()  # Removes and returns 3
second_element = stack.pop()  # Removes and returns 2

# The stack now contains [1]

# Check if the stack is empty
is_empty = len(stack) == 0  # True

# Peek at the top element without removing it
top_element = stack[-1]  # Returns 1

 

In this example, the stack is implemented using a Python list, but the abstract concept of a stack, with its defined operations, is what makes it an ADT. The ADT abstracts away the implementation details and focuses on the behavior and functionality of the data structure. You could implement a stack using different data structures (e.g., an array or a linked list) in other programming languages while adhering to the same ADT principles.

 

Thank you.

Popular Post:

Give us your feedback!

Your email address will not be published. Required fields are marked *
0 Comments Write Comment