Topic 6 -Algorithms Flashcards
What are 3 key techniques for computational thinking?
- decomposition
- abstracton
- algorithmic thinking
What is decomposition?
breaking a complex problem down into smaller problems and solving each one individually
What is abstraction?
picking out the important bits of information from the problem, ignoring the specific details that dont matter
What is alghorithmic thinking?
a logical way of getting from the problem to the solution
What is an algorithm?
A set of instructions for solving a problem
What does START do in pseudocode?
Marks the beginning of the pseudocode.
Example: START
What does END do in pseudocode?
Marks the end of the pseudocode.
Example: END
What does INPUT do in pseudocode?
Requests data from the user or another source (like a file)
Example: INPUT age
What does OUTPUT do in pseudocode?
Displays information to the user.
Example: OUTPUT "Hello, World!"
What does IF…THEN…ELSE do in pseudocode?
A conditional structure used to make decisions.
Example:
~~~
IF number > 10 THEN
OUTPUT “Greater than 10”
ELSE
OUTPUT “10 or less”
END IF
~~~
What does WHILE…DO do in pseudocode?
A loop that repeats while a condition is true.
Example:
~~~
WHILE number > 0 DO
OUTPUT “Positive number”
number = number - 1
END WHILE
~~~
What does FOR…TO do in pseudocode?
A loop that runs a specific number of times.
Example:
FOR i = 1 TO 10 DO OUTPUT i END FOR
What does REPEAT…UNTIL do in pseudocode?
Similar to WHILE, but it checks the condition after the loop, meaning the loop runs at least once.
Example:
REPEAT OUTPUT "Enter a number" INPUT number UNTIL number > 0
What does END IF do in pseudocode?
Marks the end of an IF statement
Example:
IF number > 10 THEN OUTPUT "Greater than 10" ELSE OUTPUT "10 or less" END IF
What does RETURN do in pseudocode?
Returns a value from a function or procedure.
Example:RETURN sum
How is a start/stop represented in a flow chart?
A rounded rectangle and the beginning and the end of the algorithm
How is a input/output represented in a flow chart?
Anything that is put into or displayed in the algorithm is shown as a parallelogram
How is a process represented in a flow chart?
General instructions, processes and calculations are shown as normal rectangular boxes
How is a decision represented in a flow chart?
Decisions, often a yes or no question is shown as a diamond box
How is a subroutine represented in a flow chart?
They are like sub programs- referencing other flow diagrams- shown as a rectangle with a verticle line on both sides
What connects each shape in a flowchart and show the direction to go?
Arrows
What does a binary search do?
looks for items in an ordered list
Whats the steps of binary search?
divide and conquer
- find the middle item (n+1)/2 and round down if needed
- compare it with the target:
- if it’s the target, you’re done
- if the target is smaller, repeat with the left half
- if the target is larger, repeat with the right half
- repeat steps until the item is found
What does a linear search do?
look for items in an unordered list