Problem Solving Flashcards
what is an algorithm
- a step by step procedure needed to solve a problem
define sequence
- the specific order which instructions are performed in an algorithm.
define iteration
- repeating code for a certain amount of times or until a condition is met
define selection
- decisions are made and a course of action is selected
give some examples of sequence (programming construct) in an algorithm for authenticating a users logon details
- enter password
- increase number of attempts by 1
give some examples of iteration (programming construct) in an algorithm for authenticating a users logon details
- return to step 1
- return to step 4
give some examples of selection (programming construct) in an algorithm for authenticating a users logon details
- if username is recognised, set number of attempts to 1
- if p/word doesnt match stored p/word and attempt number is 3 tell user p/word is incorrect
why is sequencing important when coding
- the algorithm will not work correctly
state 2 other ways of displaying algorithms
- pseudo-code
- flowcharts
what is meant by the term pseudo-code
a way of expressing an instruction in structured english that resembles computer language
desbribe how a linear search algorithm works
- starts at the begginning of the list & moves through item by item until it finds the matching item or reaches end of the list
- it is sequential and an example of a brute force algorithm
- not efficient (smaller the list more efficient the search)
describe the stages of a binary search on a list of items sorted in ascending order
- yh7
list:
ahmed ann claire david mary matt peter stephen zoe
show the stages of a binary search to find the name stephen
-
1 6 9 13 15 21 22 33 36 42 69 76 85
show the stages of a binary search to find the number 9
- the median item is 22. this is higher than the search item therefore the all numbers ahead of 22 are discarded
- the sublist to the left is used 1, 6, 9, 13, 15, 21
- the median of the sublist is 9 which is the search item
when searching a list of 100 items, the largest number of comparisons a linear search would have ti make would be 100
show the max number of comparisons using a binary search of the same list wouldbe 7
-