Fundamental Array Algorithms: Summation, Decision, Selection, Linear Search, Counting, and Maximum Selection
Overview of Basic Algorithms and Pseudocode Notation
- Array Representation:
- The sequence or collection of elements is represented by array X, where X=to¨mb (array).
- The array elements are indexed starting at index 1, denoted as X(I) for element at index I
- General Variable Definitions:
- N: Total number of elements in array X
- I: Index counter used in iteration loops
- T(X(I)): A logical property or boolean predicate tested on array element X(I)
Sequence Calculation: Summation (Sorozatszámítás - Összegzés)
- Objective:
- Calculate the sum (S) of N numerical elements contained within array X
- Procedure Header:
- Input Parameters:
- N: Total number of elements
- X: Array containing the numbers to be summed
- Output Parameter:
- S: Accumulated total sum
- Detailed Algorithmic Steps:
- Initialization: Set the accumulator variable S:=0
- Loop Execution:
Ciklus I = 1-től N-ig (Loop variable I runs from 1 to N) - Accumulation Step: S:=S+X(I)
- Loop Termination:
Ciklus vége - Procedure Exit:
Eljárás vége
- Key Characteristics:
- Operates sequentially across every element in the array from index 1 to index N
Decision Algorithm (Eldöntés)

- Objective:
- Determine whether there exists (∃) at least one element in array X of size N that satisfies condition/property T(X(I))
- Procedure Header:
- Input Parameters:
- N: Total element count
- X: Array of elements
- Output Parameter:
- VAN: Logical boolean variable indicating existence (
true if at least one matching element exists, false otherwise)
- Detailed Algorithmic Steps:
- Initialization: Set starting index I:=1
- Loop Execution:
Ciklus amíg I <= N és nem T(X(I)) (Loop while I≤N and property T(X(I)) is not met) - Index Increment: I:=I+1
- Loop Termination:
Ciklus vége - Evaluation: VAN:=(I≤N)
- Procedure Exit:
Eljárás vége
- Logic Analysis:
- If a matching element is found, the loop terminates early with I≤N, yielding VAN=true
- If no element matches, the loop finishes with I=N+1, resulting in VAN=false
Selection Algorithm (Kiválasztás)
- Objective:
- Locate the exact ordinal index (SORSZ) of the first element satisfying property T(X(I)) under the specific precondition that such an element is guaranteed to exist (∃ element) in array X
- Procedure Header:
- Input Parameters:
- N: Total element count
- X: Array of elements
- Output Parameter:
- SORSZ: Index position of the first matching element
- Detailed Algorithmic Steps:
- Initialization: Set starting index I:=1
- Loop Execution:
Ciklus amíg nem T(X(I)) (Loop while property T(X(I)) is false) - Index Increment: I:=I+1
- Loop Termination:
Ciklus vége - Index Assignment: SORSZ:=I
- Procedure Exit:
Eljárás vége
- Precondition Caveat:
- Because existence is guaranteed beforehand, the loop condition does not require an explicit upper bound check I≤N
Linear Search Algorithm (Lineáris Keresés)

- Objective:
- Search array X of size N for an element satisfying property T(X(I)) when existence is unknown beforehand. It returns both an existence status (VAN) and the index position (SORSZ) if found
- Procedure Header:
Keresés(N, X, VAN, SORSZ)
- Input Parameters:
- N: Number of array elements
- X: Array of elements
- Output Parameters:
- VAN: Boolean indicating whether a matching element was found
- SORSZ: Ordinal index of the matching element (assigned conditionally)
- Detailed Algorithmic Steps:
- Initialization: Set starting index I:=1
- Loop Execution:
Ciklus amíg I <= N és nem T(X(I)) (Loop while index I≤N and property T(X(I)) is false) - Index Increment: I:=I+1
- Loop Termination:
Ciklus vége - Existence Check: VAN:=(I≤N)
- Conditional Assignment:
Ha VAN akkor SORSZ := I (If VAN is true, set SORSZ:=I) - Procedure Exit:
Eljárás vége
Counting Algorithm (Megszámolás)
- Objective:
- Count the total quantity (DB) of elements within an array X of size N that satisfy a specified property T(X(I))
- Procedure Header:
- Input Parameters:
- N: Total number of array elements
- X: Array of elements
- Output Parameter:
- DB: Count of elements satisfying property T(X(I))
- Detailed Algorithmic Steps:
- Initialization: Set counter variable DB:=0
- Loop Execution:
Ciklus I = 1-től N-ig (Loop index I runs from 1 to N) - Conditional Counter Increment:
Ha T(X(I)) akkor DB := DB + 1 (If element at I satisfies T, increment DB by 1) - Loop Termination:
Ciklus vége - Procedure Exit:
Eljárás vége
Maximum Selection Algorithm (Maximumkiválasztás)
- Objective:
- Identify both the position (MAX) and value (MAXEˊRT) of the maximum element in an array X containing N elements
- Procedure Header:
Maximumkiválasztás(N, X, MAX, MAXÉRT)
- Input Parameters:
- N: Number of array elements
- X: Array of elements
- Output Parameters:
- MAX: Ordinal index position of the largest element
- MAXEˊRT: Value of the largest element
- Detailed Algorithmic Steps:
- Initial Assumptions:
- Assume the first element is the maximum: MAX:=1
- Store first element's value: MAXEˊRT:=X(1)
- Loop Execution:
Ciklus I = 2-től N-ig (Loop index I iterates from 2 to N) - Comparison and Update:
Ha MAXÉRT < X(I) akkor MAX := I : MAXÉRT := X(I) (If element X(I) exceeds MAXEˊRT, update index MAX:=I and new max value MAXEˊRT:=X(I)) - Loop Termination:
Ciklus vége - Procedure Exit:
Eljárás vége