Data structures

From Schoolcoders wiki
Jump to: navigation, search
Level: A Level Computing


Most computer languages support various data types.

Elementary data types, such as integers, floats, booleans and chars can represent a single value (such as a number or a letter).

Composite data types such as arrays and lists can store more than one value, for example this list contains three numbers:

[10, 20, 30]

Composite data types can be either static or dynamic. Static structures have a fixed size that is determined when the structure is created (arrays are static). Dynamic structures can grow to accommodate more data after they have been created (lists are usually dynamic).

Storing composite data types in memory can be quite complicated. For example, if you wanted to store a list, you would need to store:

  • The elements of the list (each in its own memory location).
  • The length of the list (the number of elements).
  • Probably a memory pointer to tell you where to find the elements.

The collection of all these values is called a data structure.

Data structures can be quite complicated. For example with a list you have to worry about what happens if you add extra elements to the list - will there be enough memory to store all the data, and what do you do if you need more? In fact there are several different ways to create a list, such as array lists or linked lists.

Fortunately, you don't usually need to create your own data structures. Most languages provide a set of abstract data types that you can use without needing to worry about how they work.

See also