ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP2117Abstract Data Types
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP2117

    Data Structures

    Progress0 / 37 done
    Topics37
    1Abstract Data Types2Complexity Analysis3Big Oh Notation4Stacks (Linked Lists and Array Implementations)5Recursion and analyzing recursive algorithms6Divide and Conquer Algorithms7Sorting Algorithms8Selection Sort9Insertion Sort10Merge Sort11Quick Sort12Bubble Sort13Heap Sort14Shell Sort15Radix Sort16Bucket Sort17Queue18Dequeuer19Priority Queues (linked and array implementations of queues)20Linked List and Its Various Types21Sorted Linked List22Searching an Unsorted Array23Binary Search for Sorted Arrays24Hashing and Indexing25Open Addressing and Chaining26Trees and Tree Traversals27Binary Search Trees28Heaps29M-Way Trees30Balanced Trees31Graphs32Breadth-First Traversal33Depth-First Traversal34Topological Order35Shortest Path36Adjacency Matrix and Adjacency List Implementations37Memory Management and Garbage Collection
    6 min read
    Topic 1 of 37
    Topic Study Note Illustration
    01

    Abstract Data Types

    An Abstract Data Type (ADT) is a way to describe the logical structure and operations of a data type without worrying about how it's implemented in a...

    Abstract Data Types (ADT)

    An Abstract Data Type (ADT) is a way to describe the logical structure and operations of a data type without worrying about how it's implemented in a specific programming language. In simple terms, ADT focuses on what operations can be done on data and how the data behaves, rather than how those operations are carried out internally.

    Think of ADT as a "blueprint" for data. It tells us what operations the data should support, but not exactly how to implement them. For example, it might describe that we can "add an element" or "remove an element," but it doesn't say whether to use an array or a linked list to store the data.

    Key Components of ADTs:

    1. Data: What kind of data is being stored? It defines the type of data the structure will handle (e.g., integers, characters, objects).

    2. Operations: What operations can be performed on the data? It defines what you can do with the data, like inserting, deleting, or accessing elements.

    3. Rules: These are the rules for how data should behave when the operations are performed. For example, in a stack, the rule is Last In, First Out (LIFO), meaning the last element added is the first one to be removed.

    Common Abstract Data Types

    1. Stack

      • A stack is a data structure that follows the "Last In, First Out" (LIFO) principle. This means that the last element added to the stack is the first one to be removed. You can think of it like a stack of plates: the last plate you place on top is the first one you take off.
      • Operations:
        • push(): Add an element to the top of the stack.
        • pop(): Remove the top element from the stack.
        • peek(): View the top element without removing it.
        • isEmpty(): Check if the stack is empty.
      • Rules: Last In, First Out (LIFO).

      Example in C++:

      class Stack {
      private:
          int arr[100];  // array to store stack elements
          int top;       // top index of the stack
      public:
          Stack() { top = -1; } // constructor initializes stack
          void push(int x) { arr[++top] = x; } // add an element
          void pop() { if (top >= 0) top--; }  // remove the top element
          int peek() { return arr[top]; }      // view the top element
          bool isEmpty() { return top == -1; } // check if stack is empty
      };
      
    2. Queue

      • A queue is a data structure that follows the "First In, First Out" (FIFO) principle. This means that the first element added to the queue is the first one to be removed. It's like a line at a ticket counter, where the person who arrives first is the first to be served.
      • Operations:
        • enqueue(): Add an element to the end of the queue.
        • dequeue(): Remove the front element from the queue.
        • front(): View the front element without removing it.
        • isEmpty(): Check if the queue is empty.
      • Rules: First In, First Out (FIFO).

      Example in C++:

      class Queue {
      private:
          int arr[100];  // array to store queue elements
          int front, rear; // front and rear indexes
      public:
          Queue() { front = -1; rear = -1; }
          void enqueue(int x) { arr[++rear] = x; if (front == -1) front = 0; }
          void dequeue() { if (front <= rear) front++; }
          int getFront() { return arr[front]; }
          bool isEmpty() { return front == -1 || front > rear; }
      };
      
    3. List

      • A list in C++ is a data structure that allows you to store a collection of elements in a sequence. Unlike arrays, lists can easily grow or shrink in size because they don't need a fixed size when created. A linked list is a common type of list, where each element (called a node) points to the next element in the sequence. This makes inserting or removing elements efficient, especially when you don't know the size in advance. In C++, lists are part of the Standard Template Library (STL) and allow operations like adding, removing, and accessing elements in an ordered way
      • Operations:
        • insert(): Add an element at a specific position.
        • remove(): Remove an element.
        • get(): Access an element by index.
        • size(): Get the total number of elements.
      • Rules: No strict ordering rules like stacks or queues.
    4. Tree

      • A tree is a hierarchical data structure where data is stored in nodes, and each node can have a parent and zero or more children. The top node is called the root, and nodes with no children are called leaves. Trees are used to represent structures with a hierarchy, like folder structures in file systems or organization charts. In C++, trees are often used to implement efficient searching and sorting algorithms, like binary search trees (BST), where each node has at most two children, and data is organized so searching for an element is faster.
      • Operations:
        • insert(): Add a new node.
        • remove(): Delete a node.
        • traverse(): Visit all nodes (inorder, preorder, postorder).
        • search(): Find a specific node.
      • Rules: Data is organized in a hierarchical structure, with a root node and children.

    Why Use ADTs?

    1. Abstraction: ADTs hide the details of how data is stored and manipulated. This makes it easier to use the data type without worrying about the underlying complexity.

    2. Modularity: ADTs allow you to break down complex problems by separating the "what" from the "how". You can define operations first, then implement them later, which is good for designing large systems.

    3. Reusability: Once an ADT is defined, it can be used in different parts of a program or in different programs altogether.

    Difference Between ADT and Data Structure

    • ADT: Focuses on what the operations are (conceptual).
    • Data Structure: Focuses on how the operations are performed and how the data is organized in memory (concrete).

    For example, an ADT might define a "List" with operations like "insert", "delete", and "get", while a linked list or an array would be actual data structures that implement the ADT in C++.

    Conclusion

    Abstract Data Types are an essential concept in computer science because they allow us to think about data in a higher-level, more abstract way. They help define the operations and rules that govern how data should behave without worrying about the actual implementation. This approach makes it easier to design and use data structures like stacks, queues, and lists in programming.

    Next topic 2 →
    Complexity Analysis

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Data Structures