What is Numerical Data
Numerical data is a data type expressed in numbers, rather
than natural language description. Sometimes called
quantitative data, numerical data is always collected in
number form. Numerical data differentiates itself from other
number form data types with its ability to carry out
arithmetic operations with these numbers.
For example, numerical data of the number of male students
and female students in a class may be taken, then added
together to get the total number of students in the class. This
characteristic is one of the major ways of identifying
numerical data.
What are the Types of Numerical Data?
Numerical data can take 2 different forms, namely; discrete
data, which represents countable items and continuous data,
which represents data measurement. The continuous type of
numerical data is further sub-divided into interval and ratio
data, which is known to be used for measuring items.
Discrete Data
Discrete Data represents countable items and can take both
numerical and categorical forms, depending on usage. It
takes on values that can be grouped into a list, where the list
may either be finite or infinite. Whether finite or infinite,
discrete data take on counting numbers like 1 to 10 or 1 to
infinity, with these groups of numbers being countably finite
and countably infinite respectively.
A more practical example of discrete data will be counting
the cups of water required to empty a bucket and counting
the cups of water required to empty an ocean—the former is
finite countable while the latter is infinite countable.
Continuous Data:
This is a type of numerical data which represents
measurements—their values are described as intervals on a
real number line, rather than take counting numbers. For
example, the Cumulative Grade Point Average (CGPA) in a 5
point grading system defines first-class students as those
whose CGPA falls under 4.50 – 5.00, second class upper as
3.50 – 4.49, second class lower as 2.50 – 3.49, third class as
1.5 – 2.49, pass as 1.00 – 1.49 and fail as 0.00 – 0.99..
A student may score a point 4.495, 2.125, 3.5 or any possible
number from 0 to 5. In this case, the continuous data is
regarded as being uncountably finite.
Continuous data may be subdivided into two types, namely;
Interval & Ratio Data.
Interval Data
This is a data type measured along a scale, in which each
point is placed at an equal distance from one another.
Interval data takes numerical values that can only take the
addition and subtraction operations.
For example, the temperature of a body measured in degrees
Celsius or degrees Fahrenheit is regarded as interval data.
This temperature does not have a zero point.
Ratio Data
Ratio data is a continuous data type similar to interval data
but has a zero point. In other words, ratio data is interval
data with zero points. For ratio data, the temperature may
not only be measured in degrees Celsius and degrees
Fahrenheit, but also in Kelvin. The presence of zero-point
accommodates the measurement of 0 Kelvin.
Character Data Types
Character data types are strings of ASCII characters. Upper
and lower case alphabetic characters are accepted literally.
There are two fixed-length character data types, char and c,
and two variable-length character data types: varchar and
text.
The maximum row length in a table is 2008 bytes. Therefore,
the maximum length of a character column is 2008 minus
any additional space requirements. Additional space
requirements for character columns are as follows:
•varchar columns require two additional bytes to store a length
specifier
•nullable char and varchar columns require one additional byte
to store a null indicator
Char Data Type
Char strings can contain any printing or non-printing
character, and the null character ("\0"). In uncompressed
tables, char strings are stored blank-padded to the declared
length. (If the column is nullable, char columns require an
additional byte of storage.) For example, if you enter "ABC"
into a char(5) column, five bytes are stored, as follows:
"ABC "
In compressed tables, trailing blanks are removed from char
columns. In general, if your application must preserve trailing
blanks, use varchar.
Leading and embedded blanks are significant when
comparing char strings (unlike c strings). For example, the
following char strings are different:
"A B C"
"ABC"
When retrieving char strings using the question mark (?)
wildcard character, you must include any trailing blanks you
want to match. For example, to retrieve the following char
string:
"ABC "
the wildcard specification must also contain trailing blanks:
"??? "
Length is not significant when comparing char strings. For
example, the following char strings are equal, even though
the second string contains trailing blanks:
"ABC" = "ABC "
Character is a synonym for char.
C Data Type
The c data type accepts only printing characters. Non-
printing characters, such as control characters, are converted
into blanks.
The DBMS ignores blanks when comparing c strings. For
example, the c string:
"the house is around the corner"
is treated identically to:
"thehouseisaroundthecorner"
The c type is supported for backward compatibility, but char
is the recommended fixed-length character data type.
Arrays Array is a type of linear data structure that is defined as a collection of elements with
same or different data types. They exist in both single dimension and multiple dimensions.
These data structures come into picture when there is a necessity to store multiple elements of
similar nature together at one place.
The difference between an array index and a memory address is that the array index acts like
a key value to label the elements in the array. However, a memory address is the starting
address of free memory available.
Following are the important terms to understand the concept of Array.
Element − Each item stored in an array is called an element.
Index − Each location of an element in an array has a numerical index, which is used
to identify the element.
Syntax
Creating an array in C and C++ programming languages −
data_type array_name[array_size] = {elements separated using commas}
or,
data_type array_name[array_size];
Creating an array in Java programming language −
data_type[] array_name = {elements separated by commas}
or,
data_type array_name = new data_type[array_size];
Need for Arrays
Arrays are used as solutions to many problems from the small sorting problems to more
complex problems like travelling salesperson problem. There are many data structures other
than arrays that provide efficient time and space complexity for these problems, so what
makes using arrays better? The answer lies in the random access lookup time.
Arrays provide O(1) random access lookup time. That means, accessing the 1st index of the
array and the 1000th index of the array will both take the same time. This is due to the fact
that array comes with a pointer and an offset value. The pointer points to the right location of
the memory and the offset value shows how far to look in the said memory.
array_name[index]
| |
Pointer Offset
Therefore, in an array with 6 elements, to access the 1st element, array is pointed towards the
0th index. Similarly, to access the 6th element, array is pointed towards the 5th index.
Array Representation
Arrays are represented as a collection of buckets where each bucket stores one element.
These buckets are indexed from ‘0’ to ‘n-1’, where n is the size of that particular array. For
example, an array with size 10 will have buckets indexed from 0 to 9.
This indexing will be similar for the multidimensional arrays as well. If it is a 2-dimensional
array, it will have sub-buckets in each bucket. Then it will be indexed as array_name[m][n],
where m and n are the sizes of each level in the array.
As per the above illustration, following are the important points to be considered.
Index starts with 0.
Array length is 9 which means it can store 9 elements.
Each element can be accessed via its index. For example, we can fetch an element at
index 6 as 23.
Basic Operations in the Arrays
The basic operations in the Arrays are insertion, deletion, searching, display, traverse, and
update. These operations are usually performed to either modify the data in the array or to
report the status of the array.
Following are the basic operations supported by an array.
Traverse − print all the array elements one by one.
Insertion − Adds an element at the given index.
Deletion − Deletes an element at the given index.
Search − Searches an element using the given index or by the value.
Update − Updates an element at the given index.
Display − Displays the contents of the array.
Advantages of Array
Array provides the single name for the group of variables of the same type. Therefore,
it is easy to remember the name of all the elements of an array.
Traversing an array is a very simple process; we just need to increment the base
address of the array in order to visit each element one by one.
Any element in the array can be directly accessed by using the index.
Disadvantages of Array
Array is homogenous. It means that the elements with similar data type can be stored
in it.
In array, there is static memory allocation that is size of an array cannot be altered.
There will be wastage of memory if we store less number of elements than the
declared size.
Types of Array in Data Structure
In computer programming, an array is a data structure that stores a collection of elements of the
same type. There are several types of Arrays in data structure Those are:
One-dimensional array:
A one-dimensional array, also known as a vector, is the simplest type of array. It consists of a single
row or column of elements and is accessed using a single index.
Example
int myArray[5] = {1, 2, 3, 4, 5};
Two-dimensional array:
A two-dimensional array, also known as a matrix, is an array of arrays. It consists of a grid of
elements that can be accessed using two indices.
Strings as Arrays of Characters
Strings are actually one-dimensional array of characters terminated by a null
character '\0'. Thus a null-terminated string contains the characters that comprise the string
followed by a null.
The following declaration and initialization create a string consisting of the word "Hello". To
hold the null character at the end of the array, the size of the character array containing the
string is one more than the number of characters in the word "Hello."
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
If you follow the rule of array initialization then you can write the above statement as follows
−
char greeting[] = "Hello";
Following is the memory presentation of the above defined string in C/C++
Actually, you do not place the null character at the end of a string constant. The C compiler
automatically places the '\0' at the end of the string when it initializes the array. Let us try to print
the above mentioned string