S1 Algorithms Flashcards
What is an algorithm?
An algorithm is a sequence of steps that can be followed to complete a task.
What is the difference between an algorithm and a computer program?
An algorithm is a sequence of steps to solve a problem, while a computer program is an implementation of an algorithm.
What is decomposition?
Decomposition means breaking a problem into sub-problems, each with an identifiable task, which can be further subdivided if needed.
What is abstraction?
Abstraction is the process of removing unnecessary detail from a problem, focusing on the essential aspects.
How do you represent algorithms?
Algorithms can be represented using pseudo-code, program code, and flowcharts, and should be solved using a systematic approach.
How can you explain simple algorithms in terms of their components?
Simple algorithms can be explained by identifying their inputs, processing steps, and outputs.
How can you determine the purpose of simple algorithms?
Use trace tables and visual inspection to determine how simple algorithms work and what their purpose is.
Can more than one algorithm solve the same problem?
Yes, more than one algorithm can be used to solve the same problem, and some algorithms may be more efficient than others.
How do you compare the efficiency of algorithms?
Efficiency is compared by explaining how some algorithms are faster or more efficient in terms of time, but formal comparisons are not required.
How does the linear search algorithm work?
The linear search algorithm checks each element in a list sequentially until the target element is found or the end of the list is reached.
How does the binary search algorithm work?
The binary search algorithm repeatedly divides a sorted list in half, comparing the middle element to the target, narrowing down the search space.
Compare linear and binary search algorithms.
Linear search checks each element one by one, while binary search halves the search space with each step. Binary search is faster but requires a sorted list.
How does the merge sort algorithm work?
Merge sort divides a list into smaller sub-lists, sorts them, and then merges them back together in order.
How does the bubble sort algorithm work?
Bubble sort repeatedly compares adjacent elements in a list and swaps them if they are in the wrong order, bubbling the largest element to the end.
Compare merge sort and bubble sort algorithms.
Merge sort is more efficient, especially for large lists, but bubble sort is simpler. Merge sort divides and conquers, while bubble sort compares adjacent elements.