unit 3: algorithms and programming

0.0(0)
studied byStudied by 4 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/45

flashcard set

Earn XP

Description and Tags

35% of ap exam

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

46 Terms

1
New cards

variable

a placeholder for a value in a program

usually represented by letters or words

can only hold one data value at a time, which can be reassigned

2
New cards

global variables

defined outside of all functions and events

can be accessed anywhere in the program

3
New cards

local variables

defined within a specific function or event

can only be accessed in that function or event

variable’s data is deleted once its event is done

should be avoided — limited scope and can cause redundancy

4
New cards

data types

different categories of data a computer can represent

ex. integers, lists, strings, booleans

5
New cards

strings

data type that represents text instead of numbers (holds the characters in a specific sequence)

must be closed by quotation marks

6
New cards

substrings

a string of characters inside of a larger string

+ operator can be used to join two substrings

Slice operator can be used to split a string into substrings

7
New cards

lists

aka arrays

an ordered sequence of elements / values

8
New cards

boolean

can only represent two values: “true” and “false”

used by computers to make decisions inside if/then statements

“true” = execute next code segments

9
New cards

NOT operator

denoted by !

used to reverse what the condition evaluates to

condition is true: operator evaluates to false

condition is false: operator evaluates to true

10
New cards

AND operator

denoted by &&

used to combine two conditions (operator only evaluates if both conditions are met)

condition is true and false: false

condition is false and false: false

condition is true and true: true

11
New cards

OR operator

denoted by ||

operator will evaluate to true if one condition or the other is met

condition is true and false: true

condition is true and true: true

condition is false and false: false

12
New cards

nested conditionals

conditional statements found inside conditional statements

<p>conditional statements found inside conditional statements</p>
13
New cards

if/else statements

the code in the if statement is executed if the operator evaluates to true

if the operator evaluates to false, the code in the else statement is executed

14
New cards

element

an individual value in a list

each are assigned an index value (a number representing the order in which they are listed)

15
New cards

operations you can do using a list

accessing an element by index

assigning the a variable to a certain element within a list

assigning a value to an element outright

assigning the value of one element in the list to another

determine the length of a list

16
New cards

insert elements in a list

at a given index: increases the length of a list and shifts every index number after that element

to the end of a list: increases the length of a list and assigns a new index only to the new element(s)

17
New cards

removing elements from a list

decreases the length of the list and changes the index number of every element after the removal

18
New cards

looping through lists

used to transverse through a list (complete or partial)

assigns a variable to each element of a list, then the next statements are executed once for each assignment

19
New cards

filtering a list

creates a subset of elements from the original list

ex. linear search, binary search

20
New cards

linear search algorithm

aka sequential search algorithm

checks each value of a list in other until the desired result is found

21
New cards

binary search algorithm

starts in the middle of a data set and eliminates either half (including the middle value) based on what it is looking for

continues until the result is found or all values in the list have been checked

**list has to be in order

more efficient than linear search

22
New cards

procedures

aka methods, functions

a group of programming instructions

can reuse the same procedure without having to rewrite it

often require parameters

23
New cards

parameters

the input variables of a procedure

24
New cards

arguments

values passed into the procedure in place of parameters

25
New cards

return statements

specify what value should be outputted when a function is called

terminate the program and return control to the calling function

26
New cards

procedural abstraction

generalizes an action

a procedure is called to perform an action, then is finished

eliminates the need to write redundant code segments—improves readability

allow you to solve a large problem based on the solution to smaller subproblems

27
New cards

algorithm

a set of instructions used to accomplish a specific task or solve a problem

sequencing, selection, iteration

28
New cards

sequencing algorithm

consists of steps that are performed in order

29
New cards

selection algorithms

if/else statements

makes a decision based on criteria and a condition

allows the program to choose between different paths of execution

30
New cards

iteration algorithm

loops

the repetition of a set of instructions until a specific condition is met

allows programs to perform tasks repeatedly without having to write repetitive code

31
New cards

while loops

run repeatedly while a condition is met and end when that condition is no longer true

unsure how many times the code will run

32
New cards

n loops

loops that run a specified number of times (n)

know how many times the loop will run

33
New cards

for loops

aka repeat until condition loop

will continue to run until a specific condition is met

know how many times the loop will run

34
New cards

3 parts of a while loop

  1. initializing counter variable i to 0

  2. boolean expression: checks condition of a variable

    1. statment to increase or decrease the variable i++

35
New cards

infinite loops

loops that repeat indefinitely

the condition controlling the loop is always true or there is no condition

36
New cards

expressions

arithmetic operators: +, -, *, /

MOD operator: divides two values and returns the remainder

37
New cards

examples of existing algorithms

determining max/min

solving math problems

determining a robot’s path through a maze (route-finding algorithm)

compressing data

sorting a list

38
New cards

simulations

the process of creating a model or representation of a real world system or phenomenon on a computer

used to predict and plan

an example of abstraction

may include bias (based on what the creator chose to include) or be out of scale

39
New cards

problem vs. instance

problem: a task an algorithm is trying to solve

instance: a problem with a specific input

40
New cards

decision problems

aka a decidable problem

return a “yes” or “no”

41
New cards

optimization problem

wants the best answer

ex. finding the shortest path between two cities

42
New cards

algorithm efficiency

an estimate of how many computational resources an algorithm uses

power, memory, time, etc.

43
New cards

polynomial efficiency

an algorithm that has a time complexity that can be represented by a polynomial equation

the running time of the algorithm grows proportionally to some power of the input size

said to run at a reasonable amount of time

44
New cards

exponential efficiency

aka factorial efficiency

an algorithm whose running time grows exponentially to its input size

considered inefficient

45
New cards

heutistic

an approximate solution returned when a problem can’t be solved in a reasonable amount of time

46
New cards

undecidable problem

an algorithm that isn’t always capable of providing a correct “yes” or “no” answer

solvable in some cases, but no algorithm will solve it in all cases