Algorithm Design Flashcards

1
Q

What are algorithms?

A

They are step-by-step procedures or methods used to solve specific problems or perform tasks.

It’s a problem solution that can be easily translated into a
programming language and then run on a computer

This requires careful planning and consideration
to ensure efficiency and accuracy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 9 steps involved in constructing an algorithm?

A
  1. DEFINE THE PROBLEM:
    - understand what you want to solve
    - identify inputs, outputs & constraints/limitations
  2. ANALYZE THE PROBLEM:
    - examine the problems requirements/constraints in detail
    - determine spec goals & objectives of the algorithm
    - consider existing knowledge or solutions
  3. DESIGN THE ALGORITHM:
    - develop high-level plan to solve problem
    - choose appropriate structures & algorithms
  4. BREAK DOWN THE ALGORITHM:
    - divide it into smaller, interconnected problems
    - identify main steps required to solve each sub problem
    - ensure each step is well-defined
  5. SPECIFY INPUTS & OUTPUTS:
    - define types and formats of inputs
    - specify the expected outputs and formats
    - consider exceptional scenarios
  6. WRITE PSEUDOCODE OR FLOWCHART:
    - visual representation (flowchart = show logical flow of a program)
    - language-like representation (pseudocode = natural language and programming, simplified)
    - express steps in a language-independent matter
    - clearly communicate sequence
  7. TEST & REFINE:
    - implement the program in language of choice
    - debug & test each stage
    - test it with different inputs
    - add print statements to track problems
    - identify any issues/bugs
  8. ANALYZER COMPLEXITY & OPTIMIZE:
    - analyze the time & space complexity
    - identify bottlenecks/inefficiencies
    - optimize algorithm by revising/rethinking
  9. DOCUMENT & MAINTAIN:
    - document the algorithms design, implementation and usage instructions
    - maintain clear/concise documentation for future reference
    - consider version & collab tools to maintain algorithm updates
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example for designing and writing a simple program for converting decimal numbers to binary…

A
  1. UNDERSTAND THE PROBLEM:
    - first divide the decimal number by 2 & record the remainder (0 or 1)
    - second continue dividing quotient by 2 and recording remainders until quotient becomes 0
    - lastly reverse order of the remainders to obtain binary number

DO EXAMPLE OF DECIMAL NUMBER 19 TO BINARY

  1. INPUTS, OUTPUTS, CONSTRAINTS?
    - INPUTS: user inputs number to be converted to binary
    - do we need to check if the input is valid? Input could be non-numeric.
    - is there a valid range of input that the program is supposed to handle? Negative numbers?
    = In our case, let’s keep it SIMPLE
    - OUTPUTS: print a message & the resulting string to the screen
    - what if the string is empty, “0” or negative? Do we need to consider this?
    = In our case, let’s keep it SIMPLE
  2. BREAK IT DOWN:
    - break down complex into smaller, manageable components
    = In our case = the algorithm is SIMPLE
  3. WRITE PSEUDOCODE OR FLOWCHART:
    - can be used as in-code documentation
    Ex.
    Input decimal from from user

Set binary to an empty string
while decimal is greater than 0:
Get the remainder of decimal divided by 2
Convert the remainder to a string
Prepend the remainder string to the left of binary
Divide decimal by 2 and assign the result back to decimal

Print binary as the binary representation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

N

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly