4.2.1
Arrays, Linked Lists & Queues
Arrays
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.
1D array
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]
2D array
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
3D array
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]]]
3D array cont.
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 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.
Linked list
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.
Example
Example
- The diagram shown is graphical representation of a linked list containing the names of three animals in alphabetical order.
Adding nodes
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).
Deleting nodes
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
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.
Queues
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)
Queue operations
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.
Uses
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.
Linear or circular
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.
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction
Jump to other topics
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction
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