3.2 Writing and Following algorithms Flashcards
Algorithm
An algorithm is a set of instructions so solve a problem or complete some well-defined task in a finite number of steps
Different types of problems solve by algorithms
- Routing
- Timetabling
- Searching
- Encrypting
- Sorting
- Writing a compiler
Features of good algorithms
- Has clear and precisely stated steps that produce the correct output for any set of valid inputs
- Should allow for invalid inputs
- Must always terminate at some point
- Should perform the task efficiently, in as few steps as possible
- Should be designed in such a way that other people will be able to understand it and modify if it necessary
Pseudocode
Halfway house between english statements and a program code
Bubble sort
Swaps items in different passes
Binary search
Must be sorted (divide and conquer)
Features of a good program
Comments to document
What are some good ways to follow an algorithm?
Create a trace table with columns for each variable in the order in which they appear in the program and a column for the output, follow through the algorithm line by line and fill in the value of a variable whenever it changes
Internet related algorithms
Algorithms that are used to manage and manipulate huge amounts of data stored on the internet
Route-finding algorithms
Used to determine the best possible route to transmit packets of data from point A to point B over a network
Compression algorithms
Used to compress data files so that they can be transmitted faster or held in a smaller amount of storage space
Encryption algorithms
Encrypts client to user data connections