0% found this document useful (0 votes)
11 views

Topic 1 - Data Modelling

The document discusses key concepts in data modeling including: - Representing information using abstract data types and modeling real-world problems. - Graphs as a useful way to represent data, including nodes, edges, circuits, different types of graphs. - Abstract data types as containers that abstract several primitive types and have specifications defining operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Topic 1 - Data Modelling

The document discusses key concepts in data modeling including: - Representing information using abstract data types and modeling real-world problems. - Graphs as a useful way to represent data, including nodes, edges, circuits, different types of graphs. - Abstract data types as containers that abstract several primitive types and have specifications defining operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Topic 1 - Data Modelling

UNIT 3 — AREA OF STUDY 1 (FROM THE STUDY DESIGN)


On completion of this unit the student should be able to define and explain the
representation of information using abstract data types, and devise formal representations
for modelling various kinds of real-world information problems using appropriate abstract
data types.

Graph Theory
A large chunk of time in Algorithmics is devoted to the study of graphs, as they are a very
useful way of representing data. Below is an example of a graph, you can drag it around and
zoom in and out (all graph examples in Algorithmics 24 are interactive like this one).

e 15
d
2

b 7
a
8

Let’s go through the key things that make up a graph.

Nodes and Edges


These are nodes:
✦ Algorithmics 24
a b

Nodes (also sometimes called a vertices) represent some point of data (maybe a city, house,
computer, or road intersection). To provide information about how two nodes are related we can
connect them together with an edge.

10
a b

Edges represent a connection between two things that themselves are represented as nodes (for
example: roads connecting cities or network cables connecting computers). Notice that, in the
above graph, there is a "10" over the edge? That’s the edge’s weight, it could be used to
represent the distance between two places, or the number of changes between two states. The
weight of an edge basically represents a characteristic of that connection between nodes.

Edges can also be directed, meaning that they have a direction by which the connection goes.
This is represented by the arrow on the end of the edge. We call the node at the end of the
arrow the target (or terminal) node, and the one at the start the source node.

✦ Algorithmics 24
10
a b

Circuits
A graph contains a circuit if there is more than one path that connects two nodes. This pops
up when there is a "loop" or "circle" in the edges of a graph. Circuits themselves
specifically contain no repeated edges (but they can contain repeated nodes) and start and end
on the same node. Note that, in the graph below, there is a circuit following the path of "a",
"b", "c" then "a" again. If there wasn’t an edge between "c" and "a", then there wouldn’t be a
circuit in this graph.

c
d
a

Graphs
A Graph is a collection of nodes and edges that may or may not be joining those nodes. We’ve
already explored what a graph looks like before, but here are a few specific categories of
graph:

✦ Algorithmics 24
Connected Graphs: These graphs are ones where every node is connected to every other node,
either directly or indirectly. That is, starting from any node, you can reach any other node
by traversing one or more edges.

Complete Graphs: A complete graph is a type of graph in which every pair of distinct
vertices is connected by a unique edge. In other words, there is a direct edge between every
pair of nodes, meaning each node is directly connected to every other node, without needing
to traverse through a different node. This makes it a form of a fully connected network.

Directed Graphs: Directed graphs feature exclusively edges that are directed.
Directed Acyclic Graphs: On the other hand, a directed acyclic graph (DAG) is a directed
graph with no directed cycles. That is, it consists of vertices and edges, with each edge
directed from one vertex to another, such that following those directions will never form a
closed loop. The term "acyclic" refers to the fact that there’s no way to start at any
vertex v and follow a consistently-directed sequence of edges that eventually loops back to
v again.

Weighted Graphs: A Weighted graph is one that has weights on all of its edges.

Trees: A tree is a kind of graph that is connected, but does not contain any circuits.

Subgraphs: A Subgraph is a part of a larger graph. All edges and nodes in a subgraph must
be in the original graph, but not all edges and nodes in the original graph have to be in
the subgraph.

Transitive Closure
The transitive closure of a graph is a concept in graph theory, which involves determining if
there is a directed path between all pairs of vertices. In other words, it tells you which
vertices are reachable from other vertices.

Complete & Connected Graphs


While both connected and complete graphs both make sure all vertices/nodes are reachable, the
difference lies in the number of edges.

In a connected graph, there needs to be at least one path between every pair of vertices. This
does not mean every pair of vertices needs to be directly connected with a unique edge.
Instead, it just requires the possibility of reaching any vertex from another, possibly
through other vertices.

On the other hand, in a complete graph, every pair of distinct vertices must be connected by a
unique edge. This signifies that each vertex/node is directly connected to every other vertex
in the graph. This requires many more edges than a connected graph.

In simple terms, all complete graphs are connected, but not all connected graphs are complete.

Paths and Cycles


When talking about graphs, we tend to spend a lot of time talking about collections of
connected edges. And so, we have specific words that are used to describe specific instances
of those edges. These are walks, trails, paths, and cycles (and circuits, but we’ve already
talked about them in "circuits"). And there are subcategories of each of those categories.

A path is a sequence of edges containing no repeated edges and no repeated nodes.

✦ Algorithmics 24
A cycle is a path that starts and ends on the same node (that start and end node is the one
exception to the rule of paths that there can be no repeated nodes).

This is a path because it starts at node A, ends at node E, and there are no repeated edges or
nodes along the way. Every node and edge is unique and traversed only once.
e

This forms a cycle because it is a path that starts and ends at the same node, A. Note that in
the definition of a cycle, the starting/ending node is allowed to be the same, which makes
this sequence a valid cycle. All other nodes (B, C, D, E) and edges are unique and not
repeated, satisfying the path criteria except for the allowance of the start and end node to
repeat in the case of a cycle.

c
e

b
a

Decision Trees
A Decision Tree is a tree whose branches represent the outcomes of a series of decisions.
Decision Trees can be used to compare outcomes and choose decisions that lead to good results.

✦ Algorithmics 24
State Graphs
State graphs are like maps that illustrate various conditions, or "states," for a system and
the pathways, or transitions, between these states. Each state represents a specific behavior
or condition of the system. The transitions indicate how the system shifts from one state to
another, usually triggered by events or specific conditions. The graph begins at a starting,
or "initial," state, and follows the paths from state to state according to the specific
rules, or "transitions, until it reaches a final state. By following the paths in a state
graph, you can understand and predict how the system will behave based on given scenarios or
conditions.

Abstract Data Types


Traditionally, there are two data types; primitive, and abstract. Abstract Data Types (ADTs)
are containers for information that 'abstract', similar in meaning to 'use as a base' several
primitive types. Each different type of ADT has specific "operators" defining how information
in the ADT is created, accessed and deleted.

Each ADT has a specification associated with it, which informs the possible operations that
can be performed involving the ADT. Note that the specification is not specific to any
programming language, and does not tell us about how the ADT is implemented in code. For
Algorithmics you do not need to know how individual ADTs are implemented.

There is one unique type of operator, called a constructor. Constructors, as indicated by its
name, initializes the ADT with specific sets of data. This is shown using the 'create'

✦ Algorithmics 24
specification - Lists for example, does not take any values within its constructor, and hence
just returns itself. Arrays however, take an integer and then returns itself. The reasons for
these values are different per ADT but this is beyond the scope of the study design.

KEY TO REMEMBER
Programming is subject to zero-based numbering, meaning that to get the first element of a
list, you would get the '0’th index, the second element, the '1’st index, etc.
Arrays
Arrays are a method of storing elements in a collection that is of a fixed length. Elements in
an array can only be accessed by their index in the array. You can think of it like a book: it
has a fixed length, and you can get a page’s information by turning to that page number.

Arrays can be used to store a fixed number of elements, such as the days of the week, the
seats in a cinema hall, or temperature readings over a month.

Arrays are suitable when you know the number of elements beforehand, and when you need fast
access to elements at specific positions.

NAME: Array
OPERATORS:
Create (Constructor): Integer -> Array
Set: Array × Integer × Element -> Array
Get: Array × Integer -> Element

 

Lists
A list is similar to an array, but instead of having one unchangeable length, it is flexible
and can have any length. Elements can be inserted to the list at any point and can be deleted
at any point too. The list ADT is very similar to an actual list like you might have in your
notes app: you can read and edit information at any point in the list, and add new elements to
it in any way that you’d like.

Lists are used for inventories, to-do lists, and any scenario where the number of items can
change over time.

Lists are suitable for cases where you need dynamic storage, and when the number of elements
can change frequently.

NAME: List
OPERATORS:
Create (Constructor): -> List
IsEmpty: List -> Boolean
Get: List × Integer -> Element
Set: List × Integer × Element -> List

✦ Algorithmics 24
Insert: List × Integer × Element -> list
Delete: List × Integer -> List

 

Stacks
A Stack is an ordered collection of items that are retrieved in a last in, first out (LIFO)
basis. That is, new elements are added to the top of the stack, and items are taken from the
top of the stack also. You can only take items from the top of the stack, and cannot get them
from anywhere else in the stack.
Stacks are used in undo operations in software applications, browser history (last page
visited is the first one to go back to), and for parsing expressions (e.g., bracket matching).

Stacks are suitable for scenarios where you need to track actions in a reverse order, such as
navigating backward or tracking recursive function calls.

NAME: Stack
OPERATORS:
Create (Constructor): -> Stack
IsEmpty: Stack -> Boolean
Push: Stack × Element -> Stack
Peek: Stack -> Element
Pop: Stack -> Stack

 

Queues
A Queue is like a stack, in that it is an ordered collection of items, but unlike a stack, the
items in a queue are retrieved in a first in, first out (FIFO) order. New elements are added
to the end of the queue, and elements can only be retrieved if they are at the front of the
queue.

Queues are used for scheduling jobs in printers, call center systems, and managing requests on
a web server.

Queues are suitable for handling tasks in the order they arrive, such as processing customer
requests.

NAME: Queue
OPERATORS:
Create (Constructor): -> Queue
IsEmpty: Queue -> Boolean
Append: Queue × Element -> Queue
Peek: Queue -> Element
Serve: Queue -> Queue

 

Priority Queues ✦ Algorithmics 24


A Priority Queue is just a queue, but the order in which elements are considered for removal
from the queue is determined by their "priority" value. So, for example, if all elements in a
priority queue had a priority of one, and an element with priority of two was added to the
queue, then that two priority element would be removed first. Priority Queues still follow the
first in, first out, rule. But consider the highest priority values first, before moving on to
lower ones.
Note that Priority Queues can consider both when the minimum value is the highest priority, or
when the maximum value has the highest priority. For simplicity’s sake, the ADT specification
assumes that the lower value has the higher priority.

Priority queues are used in operating systems for process scheduling, emergency services where
more critical cases are attended first, and in pathfinding algorithms (like Dijkstra’s and
A*).

Priority queues are suitable when order of removal depends on specific criteria than simple
arrival time, like urgency or importance.

NAME: Priority Queue


OPERATORS:
Create (Constructor): -> Priority Queue
IsEmpty: Priority Queue -> Boolean
InsertWithPriority: Priority Queue × Element × Integer -> Priority Queue
GetMin: Priority Queue -> Element
RemoveMin: Priority Queue -> Priority Queue

 

Dictionaries (Maps)
A Dictionary is an unordered collection of key-value pairs. That is, it contains a bunch of
keys, where each key represents a specific value. In an actual real-life dictionary, the keys
would be words, and the values would be their definitions. We call that connection between a
key and a value a "key-value pair".

In some programming languages, dictionaries are called Maps, however for the purposes of the
Study Design we only use the term dictionary.

Dictionaries are used for caches, database indexing, and associative arrays where you want to
retrieve values based on specific keys.

NAME: Dictionary
OPERATORS:
Create (Constructor): -> Dictionary
HasKey: Dictionary × Element -> Boolean
Add: Dictionary × Element × Element -> Dictionary
Update: Dictionary × Element × Element -> Dictionary

✦ Algorithmics 24
Remove: Dictionary × Element -> Dictionary
Get: Dictionary × Element -> Element

 

Graphs
All of the following relate to the previously mentioned Graph Theory, note that the specifics
of these DO NOT need to be remembered;
Social networks use graphs to represent users and their friendships, roads and the
intersections can be modeled as a graph for route planning, and recommendation systems use
graphs to understand and predict relationships between entities.

NAME: UndirectedGraph
OPERATORS:
Create (Constructor): -> UndirectedGraph
AddNode: UndirectedGraph × Element -> UndirectedGraph
AddEdge: UndirectedGraph × Element × Element -> UndirectedGraph
RemoveEdge: UndirectedGraph × Element × Element -> UndirectedGraph
Adjacent: UndirectedGraph × Element × Element -> Boolean
Neighbours: UndirectedGraph × Element -> List

 

NAME: DirectedGraph
OPERATORS:
Create (Constructor): -> DirectedGraph
AddNode: DirectedGraph × Element -> DirectedGraph
AddEdge: DirectedGraph × Element × Element -> DirectedGraph
RemoveEdge: DirectedGraph × Element × Element -> DirectedGraph
Adjacent: DirectedGraph × Element × Element -> Boolean
Neighbours: DirectedGraph × Element -> List
Predecessors: DirectedGraph × Element -> List
Successors: DirectedGraph × Element -> List

 

Unweighted Graph ADT (inherits from UndirectedGraph and DirectedGraph since an unweighted
graph can be either)

NAME: UnweightedGraph
OPERATORS: (Same as either UndirectedGraph or DirectedGraph)

 

✦ Algorithmics 24
NAME: WeightedGraph
OPERATORS:
Create: -> WeightedGraph
AddNode: WeightedGraph × Element -> WeightedGraph
AddEdge: WeightedGraph × Element × Element × Number -> WeightedGraph
UpdateEdgeWeight: WeightedGraph × Element × Element × Number -> WeightedGraph
RemoveEdge: WeightedGraph × Element × Element -> WeightedGraph
Adjacent: WeightedGraph × Element × Element -> Boolean
Neighbours: WeightedGraph × Element -> List
GetEdgeWeight: WeightedGraph × Element × Element -> Number

 

AOS 1 - Practice Questions

VCAA 2023 MCQ Question 1


Which of the following is the signature specification for the 'push' operation of a stack?

A. stack → stack

B. stack → element

C. element × stack → stack

D. element × stack → element

Answer

VCAA 2023 MCQ Question 2


Which one of the following graphs is a directed acyclic graph?

A.

✦ Algorithmics 24

B.
C.

D.

Answer

You might also like