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

ADTs, Data Structures, Recursion

1. The document discusses abstract data types (ADTs), which model types of data through components, properties, and operations without specifying how the data is stored or algorithms are implemented. 2. The stages of ADTs are specification, representation, and implementation. Specification identifies the data components, properties, and operations. Representation designs how data is stored. Implementation provides algorithms to perform operations. 3. Data structures and algorithms are used to implement ADTs. Common data structures include stacks, queues, linked lists, trees, and graphs. Good algorithms are definite, effective, finite, correct, general, and efficient.

Uploaded by

liam lorenz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

ADTs, Data Structures, Recursion

1. The document discusses abstract data types (ADTs), which model types of data through components, properties, and operations without specifying how the data is stored or algorithms are implemented. 2. The stages of ADTs are specification, representation, and implementation. Specification identifies the data components, properties, and operations. Representation designs how data is stored. Implementation provides algorithms to perform operations. 3. Data structures and algorithms are used to implement ADTs. Common data structures include stacks, queues, linked lists, trees, and graphs. Good algorithms are definite, effective, finite, correct, general, and efficient.

Uploaded by

liam lorenz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Data Structures and Algorithms o The result in this stage is a data structure

o How is the data stored?


ADTs (Abstract Data Types) and Recursion ▪ Ex. Node – a container of related data;
represents a group of data and how it
Abstract data types separates from other data; denoted in
➢ Computational Problems Deal with closed figures (rectangles, circles) and is
o Data – information to state knowledge about connected by edges (determines the
a world/something relationship between the nodes).
▪ Grades, biometrics • One node per student
o Operations – manipulate data to reason ▪ Ex. Arrays – names and grades are
about world or what is happening. indexed.
▪ Knowing who has the highest average in
1CSE, Arranging biometrics of UST
students.

➢ Abstract Data Type(ADT) is a model or a description


of a type of data. It identifies the component and
properties of a type of data as well as the operations ▪ Decided by someone implementing the
performed to the data. ADT only mentions the ADT
operations that are to be performed but not how 3. Implementation
these operations will be implemented. It does not o A procedural description of how each
specify how the data will be organized or stored, operation is carried out using data
what algorithms to be used when implementing structures.
operations o How are the operations performed?
➢ It is called abstract because it gives an ▪ Ex.
implementation independent view.
➢ Abstraction – providing only the essentials but hiding
the details.
o composed of
o Data – components and properties of a type
of data and the relationships among these
data. o Decided by someone implementing the ADT
o Operations o OOP languages implement ADTs naturally
▪ Field
ADT Stages ▪ Methods
Given Problem: Determine the top-notcher in a class o The results for implementation is the
1. Specification procedural description which is the
o Identification of the data’s components, algorithm.
properties, relationships among its
components and the operations performed
in the data. ADTs can be written in:
o What are the data? ➢ Any programming language (mostly suited for
▪ Ex list of n students arranged object-oriented programming languages)
alphabetically with average grades ➢ Pseudocode
o What are the operations?
▪ Ex. Determine students with highest Sets of Data
average grade ➢ May be
o From point of view of user o Static – change infrequently; changes rarely
▪ Alphabet, books in the bible, days of the
2. Representation week, month of the year
o A design on how to store instances of the o Dynamic – items are added and deleted over
data. It aims to show the relationship among time. Changes at a fast speed rate.
the components of the data and the storage. ▪ Ex. Age, prices
➢ Factors in modeling data sets as ADTs:
o Data relationships
o Operations on data
o Static or Dynamic?

➢ Some ADTs
o Stacks, queues, linked lists, trees, graphs,
hash tables

➢ ADTs can play a significant role in the development


of software that is reliable, efficient, and flexible
that’s why we have to identify how we’re going to
correctly assign a specific type of ADT.

public class Main

public static void main(String[] args) {

int array[] = {12, 8, 3, 3, 5, 10};

int index = 1;

int value = array[0];

for (int i = 1; i < array.length ; i++) {

if (array[i] > value) {

index = i + 1;

value = array[i];

System.out.println(index);

}
Algorithms CASE STUDY (Character Sequence ADT)
➢ A computational problem is solved by performing Stage 1 – Specification
finite set of instructions called an algorithm. ➢ Data:
➢ Well-defined procedure that processes input values o Sequence of characters – the length is from
to generate desired output values 0 up to 255 characters.
➢ It implements operations using data structures ➢ Operations
➢ Abu Ja’Far Muhammad lbn Musa Al-Khwarizmi o toString – function that returns the
o A mathematician and an astronomer conversation of the sequence to string
o Wrote the books (discovered by Europeans) o isFull – functions that returns true if the
that are containing the procedures to characters sequence is full.
perform math operations o Append – subroutine that adds a character
o Al-Khwarizmi -> Algorithm at the end of the sequence, unless it is
➢ Describe process precisely and concisely already full.
o Using natural language (ex. English)
▪ This process can be ambiguous. Stage 2 – Representation
o Using programming language (ex. Java, C,
C++)
▪ This process can be too technical and
very hard to read.
o Using Pseudocode – combination of NL and Stage 3 - Implementation
PL
▪ Recommended process; this allows
narrative but well-defined description
of steps.

Combined to form more complex algorithms


➢ Programs = Data Structures + Algorithms

Procedure or Method: Algorithm Module


➢ Functions – perform computations on inputs then
return value.
➢ Subroutines – it outputs devices, modifies global
data, and it does not return value; has side effects.
Usually written in small codes.

Aspects/Properties of Good Algorithm


• Has Input – it has an instance for a problem to be
solved.
• Has Output – it must produce a result
• Definite – steps should not be ambiguous; there is
only one way to interpret each step that is precisely
specified.
• Effective – each step must execute properly as
expected.
• Finite – the algorithm must have a termination
• Correct – produces the desired output,
corresponding to the given input.
• General - it has to have a correct output for every
valid input or problem instance.
• Efficient – less resources/space shall be occupied.
Data Structures
➢ Is a storage used to store and organize data; way of
arranging data into a computer so that it can be
accessed and updated efficiently
➢ Can also be used for processing and retrieving. It
determines how much space is required to store the
ADT and this also directly influences the effiency of
the algorithms
➢ Are representations that show relationships among
data in a computer environment.
➢ Use primitive or composite data structures
o Primitive data types
▪ Bit/Boolean
▪ Bit string/byte/int/char
▪ Strings of char/ floating point numbers
o Composite data types
▪ Ordered tuple
▪ Arrays, structs, classes/objects
➢ Terminologies
o Arrays – allows data of the same type to be
arranged in cells; they are indexed from 1 to
the given size.
o Strings – sequences of characters of given
length.
o Structs – allows data to be group into a single
data type.
o Classes – allows data and operations to be
defined also as a single data type. Instances
of classes are called objects.
➢ Affect how operations are carried out.

➢ Ex ADT:
o Path of points in 3-D
o Measure total path length
➢ In C:

Jamboard Link:
https://jamboard.google.com/d/1sgBFVWqK3Hf4Nm_E
YzXbKoApJzIcqUzSLgQ42Nm8wPk/viewer?pli=1&f=1
Iteration vs Recursion
➢ Ways to repeatedly execute a set of instructions in
an algorithm
➢ Basic statements used in algorithms: decorations, Recursive Definition 2
input-output statements, assignments, conditional
and looping statements.

Iteration
➢ An execution of a loop’s body
➢ Iterating a block of statements (looping once)
➢ An algorithm that solves a problem using iteration is
called an iterative algorithm

Recursion
➢ If a chain of procedure contains the same procedure
at least twice, the algo is said to be recursive
➢ A programming technique in which a function calls
themselves; process of solving a problem by reducing
it into smaller versions of itself.
➢ Solves the problem by breaking it into smaller Recursive Definition 3
instances or parts of a problem
➢ It is similar to the ff:
o Mathematical induction
o Recursive algorithm
o Recurrence relations
o Recursive definitions
➢ 2 elements
o Basis – gives direct definition, proof or
solution to the smallest part
o Recursive step – solves a problem in terms of
by defining, proving, or solving something in
terms of the smaller version of itself; it is
applied to the smaller version. Tower of Hanoi

Recursive definition 1
Recursion Pros and Cons
• Alternate solution to a problem of a size n
• State recursive step?
• State basis?
• Con – translating to algorithm
• Pros – follows logic, easy to look at than iteration
• Con – less efficient, because it has redundant
calculations
• Conversion to iteration?

You might also like