Definition of Function: A function is a relation where each element in the domain is mapped to a unique element in the codomain.
One-to-One Function: A specific type of function where every element in the domain maps to a distinct element in the codomain.
Important Terminology: Besides one-to-one, functions may also be identified as onto functions, depending on how they operate.
Definition: A sequence is an ordered list of numbers where the order of elements is critical.
Notation: Sequences may be represented in various notational formats, which can affect their interpretation.
Example Sequence: For example, the sequences 1, 2, 3, 5, 8, and 13 must retain their order to be considered the same.
Array Index Analogy: Sequences are similar to arrays where each element has a specific index, which cannot be altered without changing the structure of the sequence.
Comparing Sequences: Two sequences are considered different if the order of their elements differs, even if they contain the same numbers.
General Term: The nth term of a sequence can often be defined using a formula that depends on previous terms. For example, in a Fibonacci-like sequence, a_n could be defined using a recursive formula.
Direct Definition: For sequences where the nth term does not depend on previous terms, such as a geometric sequence, it can be expressed more simplistically (e.g., a_n = r^n for some constant r).
Definition of String: In computer science, a string is defined as a sequence of characters.
Substrings: A substring consists of consecutive characters from a given string, and this order must be maintained.
Example: "must" is a substring of "mustafa"; "mufasa" is not a substring as it skips characters.
Counting Substrings: Finding the number of possible substrings involves analyzing combinations of characters, leading to the formula of 2^n for n characters in a string.
Definition of Subsequence: A subsequence is derived from a sequence by removing zero or more elements without changing the order of the remaining elements. Unlike substrings, subsequences do not require consecutive elements.
Properties of Subsequences: They can skip elements but must maintain an increasing index order (e.g., from "mustafa", the subsequence {m, s, a} is valid, while {m, a, s} is not).
Comparison Between Substrings and Subsequences:
Subsequences are usually greater in number than substrings because they allow for skipping and do not require consecutive positions.
Example of Subsequence: "m", "u", "a" from "mustafa" forms a valid subsequence but not a substring.
Understanding the differences between functions, sequences, substrings, and subsequences is crucial for grasping advanced computer science concepts. Keep these distinctions clear when analyzing data structures and algorithms.