T7 - Arrays and Subroutines Flashcards
Arrays:
data structure that allows you to hold many items of data which is referenced by one identifier
To find an array length do
variable.len for python
variable.length in pseudocode
arrays and data types stored
All items of data in the array must be of the same data type
arrays works how
Information can be read from or added to the array using the index number
array indexes
Indexes in most languages start at 0 not 1
Arrays lengths
have fixed lengths
Linear search,
- each item is examined in sequence until the item is found or the end of the list is reached
Bubble sort:
- Each item in a list is compared to the one next to it, and if it is greater, they swap places
- At the end of one pass through the list, the largest item is at the end of the list
- this is repeated until the items are sorted
how to loop arrays
By using a FOR loop we can easily loop through an array.
Subroutines:
allow code that you intend to use a number of time to be grouped together under one name
eg of subroutines
Both functions and procedures are subroutines
features of subroutines
Values can be passed to both procedures and functions
functions and outputs
Functions will return a value after processing has taken place
procedures
Procedures - execute code in a subroutine, but they don’t return anything
arguements
Both functions and procedures have arguments = eg (“Hello”) or (1,6)