1 Understanding Algorithms Flashcards
To understand what is algorithm, why algorithms are used, interpretations of algorithms, Purpose of arithmetic operators
What is an algorithm?
- Step-by-step instructions in how to solve a problem/ how to carry out a task
- A specific accurate solution to a problem
- A detailed design for a solution
Characteristics of an algorithm
- A solution to a problem
- Unambiguous
- Sequence of steps
- It can be used again
- It will provide the same result as long as the input is the same
Example:
Making coffee
* Pour 1 liter of coffee (Give clear, unambiguous instructions)
* Heat the water and turn off when appropriate (Unclear, ambiguous)
What is a successful algorithm?
A successful algorithm fulfills these three points.
* Accuracy - it leads to the expected outcome
* Consistency - it produces the same result each time it is run
* Efficiency - it solves problem in shortest possible time using fewest possible computer resources
Difference between algorithm and program
- Algorithm - a detailed design of a solution to a particular problem
- Program - A way of implementing that design
Implementations of algorithms
- Written description
- Pseudocode
- Flowchart
- Program code
What does a diamond shape represent in a flowchart?
*Selection
* indicates a decision to be made
* It produces True/False leading to two possible outcomes
What does a skew shape represent in a flowchart?
Input/output
What does an arrow shape represent in a flowchart?
- Logical flow of the algorithm
- It shows what steps to be taken next
What does a rounded rectangle shape represent in a flowchart?
- Start/end
- Terminal
What does a rectangle shape represent in a flowchart?
- Process
- Indicates a process to be carried out
Flowchart
- A diagram of implementation of algorithm
- Provides more visual display
Pseudocode
- A structed, code-like language that can be used to describe an algorithm
- Is relatively straightforward to translate into any high-level programming language
- helps to focus on the logic and efficiency of the algorithm (without having to bother about the rules of any particular programming language)
Variable
- A container that stores data(value)
- The value in a variable is not fixed
- Variable can store different values during the course of a program and each time a program is run
Constant
A container that holds a value that never changes
* Pi value
* Number of m in km
Identifier
- A unique name given to a variable or a constant
- Using descriptive names can improve readability
Types of naming convention
- snake_case
- camelCase/CamelCase
Variable and constant
- both hold/store a value
- both have unique identifier
- Value in variable is not fixed while value in constant is
Why is a variable useful?
- The value in variable can change as a program is running
- Variables let the same program to process different sets of data
Operator
A character that represents an action
Arithmetic operators
7 types
* Addition (+)
* Subtraction (-)
* Multiplication (*)
* Real division(/) - includes decimal places
* Quotient(DIV) - return whole number
* Modulus(MOD) - return the remainder
* Exponentiation(^) - power of