Data Structures and Algorithms Notes 1
Data Structures and Algorithms Notes 1
What is an algorithm?
In mathematics and computer science, an algorithm is a step-by-step procedure for
calculations. Algorithms are used for calculation, data processing and automated reasoning.
Is a finite set of instructions that specify a sequence of operations to be carried out in order
to solve a specific problem or class of problems.
Representation of Algorithms
1. Pseudocode – is an English-like representation of the code required for an algorithm. It is
part English, part structured code. The English part provides a related syntax that is easy to
read. The code part consists of an extended version of the basic algorithmic constructs –
sequence, selection and iteration.
Page 1 of 3
Cup_of_Coffee()
{
Fill kettle with water
Turn stove on
Put kettle on stove
While (water is not boiling)
{
*/Do nothing. Repeat loop until water has boiled. */
}
Turn stove off
Fill mug with boiled water
Put one (1) teaspoon of coffee in mug
If (coffee with sugar) then
{
Put two (2) teaspoons of sugar in mug
}
If (coffee with milk) then
{
Pour one (1) tablespoon of milk in mug
}
Stir contents of mug
}
2. Flowchart – graphical representation of the algorithm
Page 2 of 3
Data Structure - In computer science, a data structure is a data organization, management,
and storage format that enables efficient access and modification. More precisely, a data
structure is a collection of data values, the relationships among them, and the functions or
operations that can be applied to the data.
1. Arrays - is a data structure, which can store a fixed-size collection of elements of the
same data type
2. Linked Lists - A linked list is a linear data structure where each element is a
separate object. Each element (we will call it a node) of a list is comprising of two
items - the data and a reference to the next node. The last node has a reference to
null. The entry point into a linked list is called the head of the list.
3. Queues (FIFO) - Queue is an abstract data structure, somewhat similar to Stacks.
Unlike stacks, a queue is open at both its ends. One end is always used to insert data
(enqueue) and the other is used to remove data (dequeue). Queue follows First-In-
First-Out methodology, i.e., the data item stored first will be accessed first.
4. Stacks (LIFO) - A stack is a basic data structure that can be logically thought of as a
linear structure represented by a real physical stack or pile, a structure where
insertion and deletion of items takes place at one end called top of the stack. The
basic concept can be illustrated by thinking of your data set as a stack of plates or
books where you can only take the top item off the stack in order to remove things
from it.
5. Trees - A tree is a collection of nodes connected by directed (or undirected) edges. A
tree is a nonlinear data structure, compared to arrays, linked lists, stacks and queues
which are linear data structures. A tree can be empty with no nodes or a tree is a
structure consisting of one node called the root and zero or one or more subtrees.
Page 3 of 3