OCR A-Level Computer Science - Chapter 13: Data Structures

¡Supera tus tareas y exámenes ahora con Quizwiz!

List

-A list is an ordered data structure. -A list is accessed through an index. -The index indicates the position of the data in the list. -Lists have no pre-defined scope (number of elements) -Not needing to define attributes in advance makes the list easier to initialise than a record. -Accessing the data in order by index is straightforward to program.

Record

-A record is accessed through an attribute. -A record is unordered data structure. -Indices may be be programmed to provide the data ordered on a particular attribute. -The ability to access data through an attribute makes the record structure more user friendly. -The need to define all the attributes before use makes the record structure more complex to initialise.

Tuple

-A tuple is a list. -A tuple is immutable; that is, the data cannot be modified. -Tuples are useful for data that must be accessed by index but must not be changed.

Multi-dimensional arrays

-A two-dimensional array creates a structure that allows access to the data by two indices similar to (x,y) co-ordinates in a table, where x refers to the row and y the column in a two-dimensional table.

Linked Lists

A linked list is a list of data together with a set of links to sort the data on various factors. Data is stored in the order it is input and pointers are used to link the data in the desired order.

Queues

A queue is a first in, first out (FIFO) structure. This means that the first item to join the queue is the first to leave the queue. A queue can be implemented using an array (called a list in Python), or using OOP techniques. Think of an actual queue in a supermarket, the first person in the queue will be the first person to leave the supermarket.

Stack

A stack is a last in, first out (LIFO) structure. Items are stored in the stack, but if an item is taken from the stack, it is always the last one that was added. Think of a stack of books, the bottom of the pile has been there the longest and the top of the pile is the last in and will be first out.

Arrays Example

An array defined under the descriptor names with scope 5 will create five variables: names(0), names(1), names(2), names(3) and names(4) This array may contain the data: names(0) names(1) names(2) names(3) names(4) Frank Hameed Yin Hannah Marta Accessing names(2) will return Yin. Changing names(1) to Umar will modify the array to: names(0) names(1) names(2) names(3) names(4) Frank Umar Yin Hannah Marta

Arrays

Arrays are data structures that store data using indices. One dimensional arrays: - One-dimensional arrays are similar to a list but have a defined scope (number of elements) - A one-dimensional array defines a set of variables under a single descriptor with an index.

Implementing a Queue in Python

Check out these websites to look at how to implement a queue into Python and the websites include videos. Website 1: http://interactivepython.org/runestone/static/pythonds/BasicDS/ImplementingaQueueinPython.html Website 2: https://pythonschool.net/data-structures-algorithms/queues/

Implementing a Stack in Python

Check out these websites to look at how to implement a stack into Python and the websites include videos. Website 1: http://interactivepython.org/runestone/static/pythonds/BasicDS/ImplementingaStackinPython.html Website 2: https://pythonschool.net/data-structures-algorithms/stacks/

Linked Lists Example

Data Item Fruit 1 Strawberry 2 Banana 3 Apple 4 Damson 5 Cherry By adding pointers, these items can be sorted alphabetically. We need a start pointer to point to the first item.

Records, lists and tuples

Each of these structures contains data to be processed: records, lists and tuples.

List Example

In an address book organised as a list, data is found by its position in the list. address _ book(5) would return the data at position 5 in the list.

Record Example

In an address book the attributes may be: first _ name, last _ name, address1, address2, post_code, telephone, email, and so on. The data is accessible through each of these attributes. For example address _ book.last _ name.

Multi-dimensional arrays Example

Names() 0 1 2 3 4 0 Billy Johan Navdeep Graham Hua 1 Frank Hameed Yin Hannah Marta 2 Barry Wayne Tracey Kylie David 3 Irina Li Sundip Tomasz Dillip 4 Deborah James Michael Wendy Charles Accessing names (2,3) returns Kylie. - A three-dimensional array, for example, will allow access to data through three indices similar to co-ordinates in three dimensions (x,y,z)

Arrays definition

Structures that store data under a single identifier by index.


Conjuntos de estudio relacionados

Midterm Review: SPC 1017 Chapter 1

View Set

2.2: continuous random variables and probability distributions

View Set

Unit 11: Chapters 65, 66, 67, 68

View Set