Data-Structures-notes
Data-Structures-notes
ALGORITHMS
An algorithm is a well defined computation procedure that takes some values as input and produces a
value or a set or values as output.
An algorithm can also be a sequence of computational steps for solving computational problems.
Lastly an algorithm can be defined as a logical sequence of computational steps used in solving
computational problems.
ALGORITHM CONVERSIONS
The following are some conventional structures that one needs to uphold in writing algorithms
3. COMMENTS/REMARKS: They are the internal documentation within an algorithm. They are
normally preceded by a symbol or a special character. //, */ . Note that all comments are non
executable.
4. ASSIGNMENT STATEMENT: They are used to assign values to variables. Both single and
multiple assignment statements within an algorithm should be explicitly defied, eg (a=b
meaning b should be contained in a).
5. VARIABLES: Variables within an algorithm or any given procedure should have initial values
defined both both local and global variables.
6. COMPOUND DATA: They are used in object oriented languages and are organized in a form
of an object with well defined attributes and fields.
7. PARAMETERS: All parameters that are passed on from a passing procedure to a receiving
procedure should have initial variables.
ANALYSES OF ALGORITHM
After designing an algorithm we need to evaluate to see if the algorithm can stand the test of time based
on the performance of the algorithm.
In trying to analyze an algorithm, the following resources are evaluated to check the performance of
the algorithm.
The following factors can affect the efficiency of an algorithm.
Memory of the system
Communication bandwidth.
Logic gates of the system.
Complexity of the underlying instruction.
Input data size of the algorithm
Input data types used in the algorithm.
DATA STRUCTURES
It is the way we organize, arrange or group data items to the various algorithms..
Data structures are categorized into two.
1. Linear data structures
2. Non-linear data structure.
ARRAYS
An array is a linear data structure where data items are arranged in consecutive memory locations or in
subsequent memory locations. Arrays have the following characteristics.
For a vector with a linear addressing, the element with the index ‘I’ is always located at the address
‘B+CI’, where B is a fixed base address and C a fixed constant sometimes referred to as an address
increment or strides.
2D ARRAY.
For a 2D array, it uses pointers/ indices . The addressing structure of any element in this 2D array is
B+Ci+Dj where the coefficient C are the row and column address increment.
Note that for all multi dimensional array, we have the row-major-order and column-major-order.
LIST/LINKED LIST.
It is a linear data structure where data items are represented by a rectangular symbol. Each of these
rectangular symbols are divided into at least 2 fields. The first field is the data item field and the second
is the link field or pointer field, that points to the next successive data item or record.
The pointer is what does the linking, it points to the successive element. All pointers are addresses that
help you locate the next record.
Disadvantages
Every node of DLL comes with two pointers, the extra pointers or links require extra memory
space and thus consume more mempry.
All operators in the DLL require extra pointer or link
Assuming that each node has two fields (data and linked field). Write an algorithm to create a linked
list with two nodes whose data fields are ‘mat’ and ‘pat’ respectively. If T is the beginning pointer to
the first node in the list.
Solution
CALL GETNODE( I )
T← DATA( I )← MAT
GETNODE ( I )
LINK ( T ) ← I
LINK ( T ) ← Lambda(i can’t find the symbol)
DATA ( I ) ← (PAT)
END CALL
THE END
midsem is two theory questions from what he said.
Disclaimer : This work is not the lectures slides although it has been approved b the FDA.
Typed with Love ( Aliko ❤️)
bye bye.