0% found this document useful (0 votes)
6 views

Data-Structures-notes

Uploaded by

paulknowlton74
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Data-Structures-notes

Uploaded by

paulknowlton74
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPILE NOTES FROM LECTURES – LECTURE ONE TO DATE (20th Feb)

DATA STRUCTURES AND ALGORITHMS

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.

An algorithm is a tool for solving a well specified computational problem.

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

1. INDENTATION: Indentation to the body structure to a given algorithm. Indentation also


indicates the block structure within an algorithm construction.

2. LOOPING STRUCTURES: it defines the conditional structure within an algorithm. Examples


are IF, WHILE, FOR, IF-THEN,REPEAT, REPEAT-UNTIL etc.

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.

ALGORITHM DESIGNING TECHNIQUES


i. Incremental Technique:
It is a designing method for an algorithm. This method is used in conjunction with other
designing methods. It is not used in isolation. It is a top-down approach.

ii. Divide and Conquer


This is also a top-down designing method. This technique consist of dividing a problem into
several sub-problems, and each of these sub problems should be identical to the original
problem. This approach is made up of 3 phases
a. Divide the original problem into several sub problems that are similar to the original problem
but smaller in size.
b. Solve each problem recursively , successfully and independently.
c. Combine the solutions to the various sub problems to produce or create the solution to the
original problem.
Some applications of the divide and conquer method Is the multiplication of large numbers,
binary search operations.

iii. Dynamic Programming


This is a bottom up approach , it is a special search method suitable for optimization problems
where a solution to a problem can be viewed based on sequence of decisions. This method also
uses three phases.
 Divide the problem into smaller sections.
 Solve each of these sub problems in increase size.
 Combine the solutions obtained in each sub problem until you arrive at a solution to the
problem.

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.

Read on Big O Notation.

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.

LINEAR DATA STRUCTURES.

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.

 All arrays hold elements of the same datatype( Homogenous in nature).


 Array elements are stored in subsequent locations.
 Every array should have an array name and the array name represents the address of the starting
element.
 The array size should be mentioned in the declaration (all arrays are finite in structure). The array
size must be a constant expression not a variable.
 For two dimensional arrays, elements are stored row by row in consecutive memory locations.
 When declaring a two dimensional array, the number of columns should be specified and it’s
mandatory, whereas there is no restriction on the number of rows.

The Addressing Structure of Arrays.


The number of indices needed to specify an element is called dimension or rank of the array. In a
standard array each index is restricted to a certain range of consecutive integers and the address of an
element is computed linearly among the indices.

ONE DIMENSIONAL ARRAYS/ 1D ARRAYS


A 1D, single or linear array is a type of array that uses only one index. Accessing an element involves
only one subscript which can either be represented in a row or a column.

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.

Multi Dimensional Array


For any multi dimensional array of the size K, the address of the element with the indices i1,i2,i3 ...ik,
then the addressing structure is B+C1i1+C2I2...CkIk(note the numbers and k are subscripts). The
coefficient ck must be chosen so that every valid index must address a distinct element.

Note that for all multi dimensional array, we have the row-major-order and column-major-order.

Read on abstract data types.

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.

Types of Linked List

SINGLY LINKED LIST


This is the simplest kind of liked list, it uses only one link per node. This pointer points to the next
node in the list, or to a null or empty list if it is a terminal or tail node. This type of linked list is the
most basic of all linked data structures.
DOUBLE LINKED LIST/DLL
This is also a linked list data structure that consist of a set of sequentially linked records called nodes.
Each node contains 3 fields.

 The LL always point to the previous record.


 The data item field
 RL always point to the successive record.

Advantages of DLL over SLL


 For all DLL we can always transverse in both directions, forward and backward.
 Deletion operation in the DLL Is more efficient than singly linked if the pointer to the node be
deleted is given.
 Insertion in the DLL is faster when a new node is to be inserted before a given node.

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

C.Circular Linked List.


Here T can be transverse to lambda sinced they are circular link.
Question

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

Application of Linked List


Data Item Head node
Tail node
They are used in solving polynomial equations
They are used in dynamic memory management
They are used in balancing parenthesis in symbol tables
They are used in representing sparce matrix

f(x) → 2x8+ 2x+1


Each term in the polynomial equation represents a node.

A representation of the question


fx→
2 3 0 2 1 -1 0 0
0

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.

You might also like