Data Structures Notes
Data Structures Notes
Data Structuring:
When data is processed by a computer, it involves the data being manipulated in some way.
The method of storing the manipulated data in memory all depends on how you’re going to process the data; the
organisation of the data is known as data structures.
Static and Dynamic data structures:
Static:
- The size of the structure is set at the beginning of the programme, and cannot be changed after this point.
- They are limited and inefficient, this is due to you having to know the size of the structure from the offset of the
programme.
- Easy to integrate into a programme.
- You always know how much memory will be required for the structure.
Dynamic:
- The size is not set, so the structure is able to expand and contrast with demands.
- More complex of a system to implement vs. a static system.
Arrays: Arrays are the simplest of all data structures. An array is a collection of variables that fit in the same data group,
under a single identifier. Each variable within an array is called an element, and is accessed by using its position in the array
as an index. Arrays are normally static structures meaning their size cannot be changed from its prefixed setting once the
programme has been run.
One-dimensional arrays:
NAMES = [‘Sam’, ‘Elliot’, ‘Scott’, ‘Lucy’, ‘Elle’] This is how an array looks in python.
NAMES
Changing a piece of data in this type of array is fairly simple, for example if you wanted to change Scott to Jack all you
would need to do is refer to the element, in this case ‘NAMES[2]’ and what you would like to change it to, it would look like
this: NAMES[2] = Jack. This would result in the array now looking like this:
NAMES
Two-dimensional arrays:
- You can also create arrays with more than a single dimension
- The implementation of multidimensional arrays differs from language to language., for example in Python, you
can simply create an array and then place another array inside each element of it.
- This is how a two-dimensional array would look, as you can see it uses multiple indexes to allow for a greater
amount of data to be stored:
Changing elements in a multidimensional array works the same as in a one-dimensional array, except to show which index
needs to be changed you need multiple index points, because this is a Two-dimensional system you would need two
indexes. The index points work like a graph i.e. to print Adams name you would use the command:
‘print(NAMES[2][1])’.
Empty array spaces:
Because arrays are static you cannot add more data without having an empty field, but if there is an empty field you will be
able to add data, the advantage of this is that it means that you will still not take any more memory because it was
originally accounted for when the system was created.
Records:
A record is a set of data items all related to a single entity.
Unlike an array, a record may contain data items of more than one data type.
For example, the following data structure may be used to store the details of an organisation’s members:
Field Name Data type
Member ID Integer
Forename Strings
Surname String
Gender Character
D.O.B Date