Programming ‘theory’ Flashcards
1
Q
Define algorithm
A
- An algorithm is a sequence of steps that can be followed to complete a task
2
Q
Define Decomposition
A
- Decomposition means breaking a problem into a number of sub-problems, so that each sub- problem accomplishes an identifiable task, which might itself be further subdivided.
3
Q
Define Abstraction
A
- Abstraction is the process of removing unimportant detail from a problem
- so that attention can be given to the important parts of a problem
- to make the problem easier to solve
(so that the important details can be focused on. This can make solving the problem easier.)
4
Q
Efficiency is what
A
- Efficiency looks at how much time it takes to run a particular algorithm and how much space is needed
5
Q
Do you say more efficient when they ask for advantages ?
A
- say ‘faster’ not more efficient when they ask for advantages (e.g. of using a linear search vs a binary - faster for shorter lists)
6
Q
When linear search used
Vs binary
A
- Although linear and binary searching produces the same overall results, linear search is best used when the data is not in order, or for smaller lists. However, when the list is much longer and the data is in order, it is far more efficient to calculate the indexes needed to perform a binary search.
7
Q
- Linear search advantages (4)
A
- Performs well with small and medium-sized lists
- Fairly simple to code
- The data set does not need to be in any particular order (some algorithms need an ordered list)
- It doesn’t break if new items are inserted into the list.
8
Q
- Linear search disadvantages (2)
A
- May be too slow to process large lists or data sets
- If the search criteria only matches the last item in the list, the search has to go through the entire list to find it.
9
Q
- binary search advantages (2)
A
- Very good performance over large ordered lists.
- A binary search takes a maximum of 8 loops to find an item in a list of 1000 items, whilst a linear search worst case would have to search all 1000 items in the list.
10
Q
- Binary search disadvantages (3)
A
- Binary search can only work on an ordered list. If the list is random, then a linear search is the only way
- It is a bit more complicated than a linear search to code and so for small lists a linear search is just as good.
- If it is a constantly updated list with items added or removed, the list will need re-ordering every time which may slow down the overall performance compared to a linear search.
11
Q
When does bubble sort stop
A
- bubble sort stops when: Once the algorithm has completed a pass without swapping anything and it knows that the list is now ordered and can stop.
12
Q
When does merges sort stop
A
- Merge sort stops when: This process of merging and sorting lists continues until all of the individual lists are merged together and just one list remains. Within this list, all of the data items will be sorted into the correct order
13
Q
- Bubble sort pros (3)
A
- Simple to write the code for.
- Simple to understand.
- The data is sorted in the same memory location that it is held, so you don’t need much extra memory to run the algorithm.
14
Q
- Bubble sort con (1)
A
- One of the slowest ways to sort a list. For example, if the list becomes ten times larger than before, it takes almost a hundred times longer to sort. So this method of sorting is very sensitive to the length of the list.
15
Q
- Merge sort pros (2)
A
- It is the fastest of three types of sort (bubble, insert, merge)
- It is the best option to use for long lists of data (more than 1000 long)