Files
G4G0-2/Data Structures/Week 1/Lecture 2 - Data Structures & ADTs.md
2025-01-30 09:27:31 +00:00

95 lines
7.8 KiB
Markdown
Executable File

- "Software engineering is the application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software, and the study of these approaches."
- Software Development Lifecycles allow creation or modification of computer systems. One phase is the **implementation** stage.
# Data #Structures
- Arrangement of data in computer memory
- Makes data quickly available to the processor
- A sort of software allowing data to be stored, organised and accessed.
# Abstract Data Types ( #ADT )
- ADT is used to define high level features and operations for data structures.
- Required before exploration of implementation of data structures.
- Before implementing a linked list for example, it would be good to understand what we want to do with said defined linked list.
- Should be able to insert, delete, search, and see if it is populated.
- ADT is a model of data structure that specifies characteristics of the collection, and the operations performed on it.
- Abstract, since it does not specify how the ADT will be implemented
- Just need to know type of data required, and allowed operations.
- Any given ADT can have multiple implementations.
# Types of Data Structures
| Data Type | Description |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Integer | Represents number with no decimal point |
| Float | Represents number with decimal point |
| Character | Represents single char |
| Boolean | Represents logical values |
| Tree | Flexible, versatile and powerful. Non-linear. Used to represent data items processing hierarchical relationships between the grandfather and his children and grandchildren. Ideal data structure for representing hierarchical data. |
| Graph | Non-Linear. Consists of a finite set of ordered pairs called edges. Set of elements connected by edges. Each element called vertex and node. |
| Arrays | Collection of elements. Used in mathematical processes like matrices, algebra, etc. Each element of an array is referenced by subscripted variables or values, called subscript or index, enclosed in parethesis. |
| Linked List | Collection of data elements. Consists of 2 parts, Info and Link. Info gives information, and Link is address of next node. Linked List can be implemented by using pointers. |
| Stack | List of data elements. In a stack, elements may be inserted or deleted at one end, known as the top of the stack. Performs Push and Pop operations. The former meaning adding to the top of the stack, the latter meaning removing from the top of the stack. Also called Last-in-First-Out (LIFO) |
| Queue | Linear list of elements. In a queue, elements are added at one end, the rear, and existing elements are removed from the other end, at the front. Also called First-in-First-out (FIFO) |
# #ADTs And Data Structures
- Common ADTs:
- Stack
- Queue
- Priority Queue
- Dictionary
- Sequence
- Set
- Common Implementations used to Implement
- Array
- Linked List
- Hash Table
- Trees
- Binary Search, Heaps
- Data structure is a **concrete** implementation of an ADT, helps you store and organise data in memory.
## Implementation
- OOP concerned with interacting objects, however, objects do not need to know the implementation. Rather, it juts needs to know the interface, public fields and methods of the class, from which the object was created.
- Specifically, does not need to know how the object stores it data, or how the operations are performed.
- An ADT is a collection of data, and set of operations on the data.
- In Java, for example, we do this using interface types.
- A Java interface cannot contain an implementation of methods, only the signature (name, parameters, and exceptions)
### Example
![](Pasted%20image%2020240918103827.png)
- Using interface types allow for the possibility of several different implementations, but with a guarantee of consistent sets.
- Data structures can then be defined as a concrete implementations within a language.
- For example, in Java, the ArrayList data type provides a collection of information and operations for storage and access of information. It implements the `List<E>` interface, and this ADT is based on Array. Implementation is hidden, but we may understand the cost of operations.
# Abstraction, Modularisation, Encapsulation
- Abstraction is the ability to consider only relevant features of problems, and not get involved with finer details
- Separation of purpose from implementation. Specifying *what* something does, rather than how.
- Modularisation is breaking down problems into smaller sub-problems
- ![](Pasted%20image%2020240918102704.png)
- Encapsulation is the process of binding an object's state and behaviors. A method of wrapping data and code acting on data into a single unit (ex. Classes).
- We may want to keep classes separated and prevent them from being tightly coupled with each other.
- With encapsulation, variables of data of a given class is hidden from other classes, and can only be accessed through methods of it's own class.
- Also known as **Information Hiding**, which is the process of hiding details of an object or function.
## Summary
- #Abstraction removes unnecessary complexity
- #Modularisation helps us to more easily manage large problems
- #Encapsulation "protects" the user from unnecessary implementation details
# Algorithm
- Starting point to any solution is the specification. A step-by-step sequence of instructions leading to said solution.
- The steps are modularised, to introduce finer detail later on as the process continues to clarity. At this point, the algorithm can be implemented as code.
- As this process continues, the programmer gains insight into which data structures would be more appropriate, however details are left until implementation as code.
### Example
![](Pasted%20image%2020240918104728.png)