1/40
key concepts and definitions in DSA
Phases of Software Development
Specification, Design, Implementation, Analysis, Testing/Debugging, Maintenance, and Obsolescence
Algorithm
A set of instructions for solving a problem
Pseudocode
A mixture of English and a programming language, used to design algorithms without being distracted by language syntax.
Decomposing the Problem
Break a task into a few subtasks, then decompose each subtask into smaller ones, and so on, until each piece is trivial to implement as a separate C++ function. Good subtasks favor code reuse and produce code that is easy to modify (information hiding: each function should know only as much about the others as necessary)
Procedural Abstraction
using a function (or any function call) without needing to know how it is implemented — only what it does. Achieve through precondition/postcondition contracts.
Precondition
A statement of the condition that must be true when a function is called. The function is not guaranteed to work correctly unless the precondition holds.
Postconditon
A statement describing what will be true when the function call completes, provided the precondition was true when it was called.
const <Data type> <Variable name> = <Value>;
A declared constant’s value cannot change while the program runs. Style convention: use ALL_CAPITALS for constant names
Time Analysis
Reasoning about how many operations an algorithm requires, generally as a function of the size of the input n, rather than measuring actual elapsed time (which depends on irrelevant factors like processor speed).
Big-O Notation
Expresses the order of an algorithm by keeping only the fastest-growing term of the operation-count formula and dropping multiplicative constants (e.g. both 2n and 42n are O(n)). The order of an algorithm generally matters more than processor speed.
Worst-Case Analysis
Counts the maximum number of operations required for any input of a given size n.
Average-Case/Best-Case Analysis
Counts the maximum number of operations required for any input of a given size n.
Linear Pattern
A loop that performs a fixed amount of work n times requires O(n) time.
Program Testing
Running a program and observing its behavior/timing on specific inputs.
Properties of Good Test Data
You must know what output a correct program should produce for each test input. The test inputs should include those most likely to cause errors.
Boundary Value
An input that is “one step away” from different program behavior (e.g. the lowest/highest legal value of a range). Consider 0, 1, and -1 as boundary values whenever they are legal inputs.
Fully Exercising Code
Ensure every line of code executes at least once by some test input. If part of the code can be skipped, endure at least one test input actually skips it. A profiler tool helps verify this by reporting how often each statement executed.
Debugger
A software tool that executes code one line at a time (or until a specified condition), letting you watch variable values and pause execution to track down bugs.
Object-Oriented Programming
An approach in which data is packaged into objects; objects are manipulated by member functions that belong to them.
Class
The C++ mechanism for creating a new data type made of data (member variables) and member functions. A class supports information hiding.
Abstract Data Type
A mathematical data type presented to programmers purely through its behavior (information hiding) — in practice, the term is often used interchangeably with “class” when information hiding is emphasized.
bool type
built-in true/false type (C++ Standard). Relational operators (==, !=, <, <=, >, >=) produce bool values; && (and) || (or), !(not) combine them.
Modification Member Function
A public member function that can change an object’s value
Constant Member Function
A member function, marked with trailing const, that may only examine — never modify — the object.
Private Member Variable
Data stored inside the class but accessible only to the class’s own member functions, not to outside code.
Scope Resolution Operator (::)
Used before a member of a function’s name in its full definition to tell the compiler which class the function belongs to.
Constructor
A special member function is automatically called whenever an object of the class is declared. Rules: same name as the class; no return type — not even void; may take parameters, whose arguments are given after the variable name at declaration.
Default Constructor
A constructor with no parameters (or with default arguments for all parameters). Calle automatically when an object is declared with no argument list.
Inline Member Functions
An inline member function’s full body is placed directly in the class definition (no trailing semicolon issues; no separate implementation needed). Best used only for very short, simple functions.
Namespace
A name a programmer chooses to group their own work and avoid name conflicts with other programmer’s code. Should include part of the programmer’s real name/email to stay unique
Macro Guard
A compiler directive block (#ifndef / #define / #endif) that prevents a header file’s contents (especially a class definition) from being compiled twice if the header is included more than once.
Assignment Operator
For objects x and y, y = x; copies x’s value into y. By default (“automatic assignment operator”), C++ copies each member variable individually.
Copy Constructor
A constructor with exactly one parameter of the same class type, used to initialize a new object as a copy of an existing one. C++ provides an automatic copy constructor that copies all member variables.
Three Kinds of Parameters
Value, Reference, and Const
Value parameter (point p)
Argument is copied into a local variable; changes inside the function do NOT affect the caller’s argument.
Reference parameter (point& p)
Refers directly to the caller’s argument; changes inside the function DO affect the argument.
Const reference parameter (const point& p)
efficient like a reference (no copy) but guaranteed no to be modified by the function
Operator Overloading
Defining the meaning of a built-in C++ operator (such as ==, +, << ) for a new class, by writing a function named operator followed by the operator symbol
Friend Function
A function that is not a member function but is granted access to a class’s private members by listing its prototype inside the class definition, preceded by the keyword friend. Should be limited to functions written by the class’s own implementor.
Standard Template Library
a collection of ready-made, reusable C++ container classes (like pair) available in every C++ program, so common data structures don’t need to be built from scratch
Pair
The two data types are specified in angle brackets —- pair <int, double> — called a template instantiation. first and second are public member variables and may hold different (or the same) data types.