Linear Data Structures and Algorithms Flashcards
(50 cards)
What is an algorithm?
A finite, well-defined sequence of computational steps to solve a specific problem.
List the five characteristics of an algorithm.
Finiteness, Definiteness, Input, Output, Effectiveness.
What is a computational problem?
A relationship between inputs and outputs, defined by preconditions and postconditions.
What is the difference between an algorithm and a program?
An algorithm is conceptual; a program is its implementation in a programming language.
What does it mean for an algorithm to be correct?
It is sound (valid results) and complete (guaranteed results for all valid inputs).
What is the RAM model?
A theoretical machine that assumes constant-time operations and infinite memory.
Why is the RAM model useful?
It simplifies algorithm analysis by abstracting hardware complexities.
Define the term “effective” in the context of algorithms.
Each operation is basic and executable in finite time.
What is the purpose of pointer arithmetic in arrays?
To enable operations like indirect addressing (A[A[i]]).
Describe the difference between zero-based and one-based indexing.
Zero-based indexing starts at 0 (e.g., Java), while one-based indexing starts at 1.
What is time complexity?
A measure of the number of operations an algorithm performs relative to input size.
What is the best-case complexity of insertion sort?
O(n), when the array is already sorted.
What is the worst-case complexity of insertion sort?
O(n^2), when the array is sorted in reverse order
What is mathematical induction?
A method of proving statements for all natural numbers by establishing a base case and an inductive step.
What is the invariant condition in insertion sort?
At each step, the subarray before the current element is sorted.
What does it mean for an algorithm to terminate?
It completes in a finite number of steps.
What is the role of preconditions in algorithm analysis?
They define valid input conditions for the algorithm to run correctly.
What are the steps of the insertion sort algorithm?
Pick an element, find its correct position, shift larger elements, and insert it.
What is the role of postconditions in algorithms?
They specify what must be true after the algorithm completes.
How can the runtime of an algorithm be analyzed?
By counting operations or steps in the RAM model.
What is an ADT?
Abstract Data Type - A specification of operations on data without detailing implementation.
What are creators, observers, and mutators in ADTs?
Creators initialize data, observers query data, and mutators modify data.
List the main operations of a stack.
push, pop, and peek.
What is a queue, and what are its main operations?
A FIFO data structure with enqueue and dequeue operations.