Please enable JavaScript.
Coggle requires JavaScript to display documents.
Data : Types - Coggle Diagram
Data : Types
Introduction
What is Data type
A set of
Values
Operations
In data types
Data sorted into sets
Operations modelled by functions
Tests modelled by
Relations on the sets
Functions on the set
Differences among languages exist in
Types of data allowed
Types of operations available
Mechanisms provided for
Storing data
Controlling operation sequence
Mathematical model -> Algebra
History
Few languages that support data structures
Fortran
Linked list and binary tree implemented with arrays
Cobol
Allowing programmers to specify decimal data values
Structured data type for information record
Pl/I
Accuracy specification for int and float
Improved support for a large number of data types
Algol 68
Few basic types
Few flexible structure defining operators
Concept of abstraction
Introduction
View/ representation of an entity
Allows to collect instances of entities
Common attributes need not be considered
Fundamental kinds
Data abstraction
Process abstraction
Concept of data abstraction
Similar driving factors for process abstraction
Variables can be declared even if their type is hidden
Type details can be hidden if they are not necessary
Includes programs in the subset that perform those activities
Only contains the data representation of a single particular data type
Concept of process abstraction
Not revealing the specifics of how it carries out its work
Give a program a means to define a procedure
Types of data
Who provides the data
Hardware
Int
Language
Standard libraries
Inbuilt
Other developers
Programmer constructed
Functions and library routines
In line code sequences
How they are manipulated in a program
Elementary data objects
Not defined in terms of other types
Usually, an ordered set with a least and greatest value
Always manipulates as a unit
Values stored in fixed memory space
Data structures
Built out of other types
Arrays
Records
Building blocks are components
Aggregation of data object
Require variable memory space for values
Types
Primitive data types
Boolean
Introduction
Logical data type
Concepts of true and false
Used to control programming structures
History
Simplest
Introduced in Algol 60
C89 uses numerical expressions as conditionals
More readable
Value representation
Single bit
Follows Boolean algebra
All languages -> false 0
Some languages -> true -1 (rather than 1)
Zero ->
Non-zero -> true
Character
Stored in computers as numeric codes
Single character as its value
Most commonly used
8-bit ASCII
ISO 8859-1
Unicode
Character set is aggregate of all characters
Assignment of numbers are code pages
Collating sequence -> Ordering characters
Code page -> Assignments of numbers to characters collectively in a set
Python supports single characters only
Numeric
Integers
Representation
Real World
Whole numbers
Computer
Hardware support
Not supported
Differences between integer data types
Size variation
Machine dependent
Languages dependent
May / may not allow negative
Storage representation
Unsigned
Signed
Sign-magnitude notation
One's complement
Two's complement
Operations on integer data
Arithmetic
Binary
Unary
Relation
Assignment
Bit operation
Floating point real numbers
Representation
Real World
Real numbers
Computer World
Exponent & mantissa
IEEE Floating-point standard 754
Computer Representation
Differ only in size of domain
Precision is accuracy
Range is combination of range of fractions and exponents
Types
Float
Standard size usually 4 bytes
Double
2x space of float
Larger range
Always signed
Represented as fractions and exponents
Issues
Only approximation
Stored in binary
Loss of accuracy
Fixed point real numbers
Store fixed number of decimal digits with fixed position for decimal point
Most large computers give hardware support
Primary data type in business data processing like Cobol
Storage Representation
Data stored
Using binary coded decimal (BCD)
As integers with decimal being attribute (scale factor)
Advantages
High precision
Disadvantages
Range of values is restricted (no exponents)
Wasting memory
Complex
Some programming languages support
Forton
Python
Explicitly specified in python
Represented as ordered pairs of floating point
Allows arithmetic
Descriptors
Collection of the attributes of a variable
If static required only at compile time
If dynamic used by the run-time system
Used for type checking and building code
Symbol table
Employed by a language translator
Information about
Declaration or presence in source code
Type
Scope level
Character string type
Values consists of sequence of characters
Design choices
String length
Static length string
Descriptor required only during compilation has
Name of type
Type’s length
Address of the first character
Limited dynamic length strings
Require run-time descriptor to store (except in C & C++)
Fixed maximum length
Current length
Dynamic length strings
Require a simpler run-time descriptor
Stores
Current length
Fixed max length
Require more complex storage management
Implementation
Linked list
Extra storage
Complex operations
Allocation and deallocation simple
Pointer array
Uses extra memory
Faster than with the linked-list approach
Adjacent storage cells
Less storage required
Faster string operations
Regular Expressions
Introduction
Describe text patterns
Comprised of
Characters
Meta-characters
Different versions are used
Characters have own syntax
Abbreviations
regexp
regex
Matching text done by regex engine
Does not consider the text semantics
Basic Elements
Position indicators
Character sets
Quantifiers
Anchors
Regex engine stops after first match
Characters
^ - start of the string
$ - end of the
\Z - End of string
\b - Word boundary
\B - Not word boundary
\< - Start of word
> - End of word
Character sets
Character classes
[xy] - x or y
[a-z] - a or b or ……z
[1-9a-zA-Z] - a or b or ……z or A or B or ……Z or 1 or 2 or ……9
[^1-9] - Any character other than a digit (negation)
. - Any character.
Character Class Abbreviations
\d - Match any character in the range 0 – 9
\D - Match any character NOT in the range 0 - 9
\s - Match any whitespace characters (space, tab etc.)
\S - Match any character NOT whitespace (space, tab)
\w - Match any character in the range 0 - 9, A - Z and a – z
\W - Match any character NOT the range 0 - 9, A - Z and a - z
Recursive Definition
a | b choice
ab sequence
(a) grouping
a* zero or more repetitions
a+ One or more repetitions
Quantifiers
Generally apply to the item that precede it
Specify repetition
User defined ordinal types
Enumeration
Ordered list of distinct values
Programmer defines
Literal names to be used for the values
Ordering in a declaration
Constants arenimplicitly assigned the inte values
Basic Operations
Relational operations
Assignment
Successor and predecessor
Can be simulated with integer but may have issues
No type checking
Could be assigned any value
Rarely intended
loops (depending on language)
Advantages
Enhanced Readability
No arithmetic operations
Cannot be reassigned
Evaluation
No benefit in C, but C++ slightly better
Sub-Range
Not a new type
Contiguous subsequence
Define new names
All parent operations defined for subrange except value assignment
Inbuilt in some languages
Implementation
Associating non negative int
Range checking must be implicitly included by complier