Algorithms Flashcards
(36 cards)
Is there a difference between a Problem and an Algorithm?
Yes
Problem
description which associates inputs to output states
Problems include 2 things
precondition + postcondition
Does a problem statement itself indicate how to solve the problem?
No; just pre and post
Algorithm
describes a possible sequence of steps which when carried out solves a problem by meeting post conditions upon completion.
Do algorithms have to meet a problems’ post conditions upon completion?
yes
Function details can be hidden T or F?
True
Pseudocode
english-like representation of algorithm logic
and is independent of implementation language
in pseudocode, do we explicitly declare primitive data items? (eg. int number)
no.
Conventions for variable names:
- meaningful names
- no single-char names except for loops
- Do not use generic names : count sum row
- use descriptive names
- use abbreviations
Is this a valid Psuedocode variable name?
count
NO
Is this a valid Psuedocode variable name?
add
NO
Is this a valid Psuedocode variable name?
thisPointer
Yes
Is this a valid Psuedocode variable name?
a :: character
NO
Is this a valid Psuedocode variable name?
pow
NO
Psuedocode algorithm headers include:
Name Description Preconditions Postconditions return
Psuedocode has 3 kinds of statements:
sequence of statements [blocks]
loop statement
conditional statement [if/else]
Psuedocode: sequences
dont alter execution path within the algorithm
- assignment
- input
- output
- Arithmetic expressions
- higher-level english descriptions
another name for guarded loop?
while loop
How do we measure running time?
in steps
Implementation-independent Method
running time as a relationship between size of the input n, and the number of time units t needed to execute the algorithm
primitive operations
all take the same amount of time; assigning a value to variable calling another algorithm performing an arithmetic operation indexing into an array comparing two values following an object reference returning from a method
asymptotic complexity or time complexity
only consider the term that grows the fastest to characterize algorithms
what is the lowest big Oh?
log log n