4.2.1

Arrays, Linked Lists & Queues

Test yourself

Arrays

Arrays are data structures which are of a fixed size and contain data of the same type stored in a contiguous block of memory.

Illustrative background for 1D arrayIllustrative background for 1D array ?? "content

1D array

  • A 1-dimensional array is a single set of data, which can be visualised in a single row. - For example: oneDArray = [A, B, C, D]
Illustrative background for 2D arrayIllustrative background for 2D array ?? "content

2D array

  • A 2-dimensional array is a set of data which can be visualised in rows and columns.
  • For example, array twoDArray = [[A, B, C, D], [E, F, G, H],[I, J, K, L]]
  • Items in a 2-dimensional array are referred to by their row number, followed by column number.
  • For example, twoDArray [1,2] = G
Illustrative background for 3D arrayIllustrative background for 3D array ?? "content

3D array

  • A 3-dimensional array is a collection of 2-dimensional arrays.
  • You can visualise each 2D array as being stored one behind the other.
    • For example, threeDArray = [[[A, B, C, D], [E, F, G, H],[I, J, K, L]], [[M, N, O, P], [Q, R, S, T],[U, V, W, X]],[[Y, Z, 0, 1], [2, 3, 4, 5], [6, 7, 8, 9]]]
Illustrative background for 3D array cont.Illustrative background for 3D array cont. ?? "content

3D array cont.

  • Items in a 3-dimensional array are referred to by their 2D array number, followed by the row number, and column number.
    • For example, threeDArray [1,2,2] = W

Linked List

Linked lists are commonly used data structures with benefits of flexibility and ease of use. They can be used to implement other data structures such as stacks and queues.

Illustrative background for Linked listIllustrative background for Linked list ?? "content

Linked list

  • Linked lists consist of nodes.
  • Each node contains a data item and a pointer to the next node in the sequence.
  • A null pointer is used to identify the last item of data.
  • The use of pointers means that unlike arrays, data in linked lists do not have to be stored contiguously in memory.
  • They are also referred to as being ‘dynamic’ in that they can grow or shrink in size as and when necessary.
Illustrative background for ExampleIllustrative background for Example ?? "content

Example

  • The diagram shown is graphical representation of a linked list containing the names of three animals in alphabetical order.
Illustrative background for Adding nodesIllustrative background for Adding nodes ?? "content

Adding nodes

  • To add ‘Tiger’ to the list alphabetically, the pointer of node 1 is updated to point to the new node, which in turn points to the next in the sequence (node 2).
Illustrative background for Deleting nodesIllustrative background for Deleting nodes ?? "content

Deleting nodes

  • To delete ‘Rhino’ from the list, the pointer of node 0 is updated to point to node 3.
  • The data of node 1 is deleted.
  • This node becomes the first of a separate list of empty nodes, ready to be filled again.

Queues

A queue is a data structure where data items are always added to the end and removed from the front. It is often referred to as a 'first in, first out’ data structure.

Illustrative background for QueuesIllustrative background for Queues ?? "content

Queues

  • Queues can be implemented using other data structures, such as arrays or linked lists.
  • In either case, two extra variables are required to identify the front and rear of the queue.
  • Queues can be ‘static’ (fixed in size) or ‘dynamic’ (able to grow in size as necessary)
Illustrative background for Queue operationsIllustrative background for Queue operations ?? "content

Queue operations

  • Several operations can be carried out on queues:
    • enQueue() - adds an item to the rear of a queue.
    • deQueue() - removes and displays the item at the front of a queue.
    • isEmpty() - checks to see if the queue is empty.
    • isFull() - checks to see if the queue is full.
Illustrative background for UsesIllustrative background for Uses ?? "content

Uses

  • Queues have a wide range of uses in computer science, including:
    • Storing print jobs until the printer is ready to print.
    • CPU scheduling.
    • Breadth-first traversal of a graph.
Illustrative background for Linear or circularIllustrative background for Linear or circular ?? "content

Linear or circular

  • Queues can also be ‘linear’ or ‘circular’.
  • When an item of data is removed from the front of a linear queue, all the other items move up one place.
    • This is only suitable in a small queue, otherwise data processing time can be excessive.
  • When an item of data is removed from the front of a circular queue, the only processing required is to update the two pointers identifying the new front and rear of the queue.

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Procedurally

6.3Thinking Logically

7Problem Solving & Programming

8Algorithms

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson