Big Idea 3 Flashcards
Algorithm
set of steps to solve a problem (recipe). can be used over an over again
Pseudocode
used to map out a program’s structure before actually writing in the programming language
Flowchart symbols
Oval - start/end
Arrow - relationship between shapes
Parallelogram - input/output
Rectangle - result
Diamond - decision/conditional
Clarity
how easy program is to understand
Readability
help programers understand the program
How many algorithms can solve a problem
many algorithms can be used to solve a problem. different algorithms may have different efficiencies
Variable
placeholders for values a program needs to use. a good name is necessary. are data abstractions because we don’t need to knowhow the values are stored.
Value
Number
“String”
String
text fields donated with quotation marks. CANNOT be used in calculations
Concatenating Strings
putting strings together
Substring
a section of a string. each character given an index number if need to be references (starts at 1). Spaces HAVE an index value.
Integer
whole number
Fractional Numbers
number with a decimal point (even if .0)
Math Symbols
+ add
- minus
/ divide
* multiple
MOD # (remainder after dividing)
how to assign a value to a variable
= or <–
Boolean Values
True or False (equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to)
Compound Conditional Statements
boolean expressions using AND, OR, NOT
AND - both must be true to evaluate to true
OR - only 1 must be true to evaluate to true
NOT - evaluates to true if condition is false
Types of Statements
Sequential - statements executed in order one at a time
Selection - using if statements, therefore, not all the code is run if an if statement evaluates to false (ELSE IF)
Iterative - repetitive statements or loops (repeat N times, repeat until condition is met)
Common Algorithms
Maximum: compare numbers, store larger number as max
Minimum: compare numbers, store smaller number as min
Sum and Average: set counter and sum = 0, get current number, add it to sum, add 1 to counter, repeat until all numbers are counted, divide sum by counter to get average, display sum and average
Find if Number is Divisible by another: # MOD # = 0 is true
Largest/Smallest Number in List: repeat until the length of the list = index, if the number is greater/less than the current greatest/smallest, that value at that index number is replaced in the largest/smallest
Sum and Average of List: for each element in list, sum = number + sum, divide sum by list length
List
collection of items. allow many values in one variable. use [ ].
To reference an item, refer to its index (it is numbered starting at 1). listName[1];
Where does the index start at
1
Manipulating Lists
INSERT - causes elements to the right of the index position to shift right 1 position. (INSERT(listName, i, value)
APPEND - adds item to the end of the list (APPEND(listName, value)
REMOVE - removes the element at the index position and shifts the rest (REMOVE(listName, i)
LENGTH - number of elements in a list (LENGTH(listName)
Checking Items in a List
FOR EACH - repeats the code for each element in the list (traversal)
Searching
finding the needed element from everything in the dataset or determining that it is not there.
Types of Searches:
Linear - sequential searches. check each value one by one and determines if the value is equal to the value you’re searching for
Binary - only works for SORTED numbered lists. more efficient. looks at the number in the middle and compares it to number you’re searching for, goes to left/right side of list based on if its higher or lower, keeps splitting it in half until the number is found
Procedures
aka functions. sections of code that will only be executed when they are called by the program. after a procedure is executed, it goes back to where it was left off an continues.
Parameter
makes procedures more flexible. when you call the program, you can send specific values to the program known as arguments.
Return
a feature in some procedures, which returns an output
ex.
DISPLAY - prints the value
INPUT - accepts data from user
Libraries
when writing code, you can import already made code to reuse in your program. looking at the API can help determine what each part does
API
Application Programming Interface - documentation which provides how to use the parts of the program such as what values can be plugged into parameters
RANDOM (a, b)
start and end value are defined and a random number is chosen between them (INCLUDING the start and end values)
Simulations
designed to represent and mirror the real world for testing. an example of abstraction as details are removed to evaluate the impact without causing real-world impact. helps evaluate hypothesis without risk. saves time and money.
Problem
task that can or cannot be solved with an algorithm
Instance of a problem
specific example
Decision Problem
has a yes or no answr
Optimization Problem
one that should find the best solution for the problem
Efficiency of an Algorithm
how long it takes and how much memory will be needed
Decidable Problem
one where an algorithm can be written resulting in correct output
Undecidable problem
doesn’t have an algorithm that can give an answer for all cases. a heuristic may have to be used
Heuristic
approach that may not be the best but it is close enough to use as a solution
Iteration
when the program requires specific code to be run more than once
Procedural Abstraction
using procedures (functions) to reuse code
Modularity
The separation of a program into independent modules that are each responsible for one aspect of the program’s functionality