PPL Chapter 2
PPL Chapter 2
1. Integer
o Specification:
Stores whole numbers.
Size varies: typically 4 bytes (32 bits).
Range:
2. Float/Double
o Specification:
Represents real numbers with fractional parts.
Float: 4 bytes (single precision).
Double: 8 bytes (double precision).
o Specification:
Represents logical values: true or false.
Size: 1 bit or 1 byte (depending on the language).
o Implementation:
Stored as 0 (false) or 1 (true).
o Implementation:
Contiguous memory allocation.
Accessed via indices: arr[index].
2. Records (Structs)
o Specification:
o Specification:
Sequence of characters.
Fixed or variable length.
o Implementation:
Null-terminated arrays of characters (C-style) or dynamic objects (e.g., std::string in
C++).
4. Lists
o Specification:
Ordered collections that can grow/shrink dynamically.
o Implementation:
Linked list or dynamic arrays.
5. Sets
o Specification:
Unordered collection of unique elements.
o Implementation:
Hash tables or balanced binary trees.
Type Checking
Definition: Verifying the compatibility of data types during operations.
Types:
o Static Type Checking: Performed at compile-time (e.g., C, Java).
o Dynamic Type Checking: Performed at runtime (e.g., Python).
Type Conversion
Definition: Changing a value from one type to another.
Types:
1. Implicit Conversion (Type Coercion):
Automatically handled by the compiler/interpreter.
Example: int x = 5; float y = x;
2. Explicit Conversion (Type Casting):
Done manually by the programmer.
Example: (float) 10 / 3;
3. Vector Arrays
Definition: One-dimensional dynamic arrays, useful in numerical computations.
Specification:
o Elements are homogeneous.
o Allow operations like addition, scalar multiplication, dot product.
Implementation:
o Dynamically allocated arrays.
4. Records
Definition: A composite data structure grouping related fields of potentially different types.
Specification:
5. Character Strings
Examples:
o Dynamic Arrays (e.g., Python lists, Java ArrayList).
o Linked Lists: Use pointers to connect elements.
o Trees: Dynamic hierarchical structures.
o Graphs: Networks of nodes and edges.
Implementation:
o Uses dynamic memory allocation (e.g., malloc() in C, new in C++).
7. Sets
Definition: Unordered collections of unique elements.
Operations:
o Union, intersection, difference, membership checking.
Implementation:
o Hash tables (e.g., Python’s set).
o Balanced binary trees (e.g., C++ std::set).
Input Files
Definition: Used to read data into a program.
Operations:
o Open, read, close.
Implementation:
Output Files
Definition: Used to write data from a program.
Operations:
o Open, write, close.
Implementation: