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