2. What is data
structure?
A data structure is a particular way of
organizing data in a computer so that it
can be used effectively.
For example, we can store a list of
items having the same data-type using
the array data structure.
3. In some cases, a data structure can become the underlying implementation for a
particular data type.
For example, composite data types are data structures that are composed of primitive
data types and/or other composite types, whereas an abstract data type will define a
set of behaviours (almost like an ‘interface’ in a sense) for which a particular data
structure can be used as the concrete implementation for that data type.
We can categorize the data structures into two categories
linear and non linear data structures
5. In linear data structures, the elements are arranged in
sequence one after the other. Since elements are
arranged in particular order, they are easy to implement.
However, when the complexity of the program
increases, the linear data structures might not be the
best choice because of operational complexities.
Unlike linear data structures, elements in non-linear
data structures are not in any sequence. Instead, they
are arranged in a hierarchical manner where one
element will be connected to one or more elements.
6. Linear Data Structures Non-Linear Data Structures
The data items are arranged in sequential order,
one after the other.
The data items are arranged in non-sequential
order (hierarchical manner).
All the items are present on the single layer. The data items are present at different layers.
It can be traversed on a single run. That is, if we
start from the first element, we can traverse all
the elements sequentially in a single pass.
It requires multiple runs. That is, if we start from
the first element it might not be possible to
traverse all the elements in a single pass.
The memory utilization is not efficient.
Different structures utilize memory in different
efficient ways depending on the need.
The time complexity increase with the data size. Time complexity remains the same.
Example: Arrays, Stack, Queue Example: Tree, Graph, Map
7. What is an
Algorithm????
The word algorithm comes from the name of
Persian author “Abu Jafar Mohammad ibn Musa al
Khawarizmi ”.
Outline , An essence of a computational procedure,
step by step process.
An Algorithm is a finite sequence of instructions,
each of which has a clear meaning and can be
performed with a finite amount of effort in a finite
length of time.
No matter what the input values may be, an
algorithm terminates after executing a finite
number of instructions.
Algorithm describes the actions on input instances.
8.
9. Characteristics of An Algorithm
Unambiguous :Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their inputs/outputs should be clear and must lead
to only one meaning.
Input :An algorithm should have 1 or more well-defined outputs and
should match the desired output.
Output :An algorithm should have 1 or more well-defined outputs and
should match the desired output.
Finiteness :Algorithms must terminate after a finite number of steps.
Feasibility :Should be feasible with the available resources.
Independent :An algorithm should have step-by-step directions, which
should be independent of any programming code.
10. Qualities of Good
Algorithms
Input and output should be defined
precisely.
Each step in the algorithm should
be clear and unambiguous.
Algorithms should be most effective
among many different ways to solve
a problem.
An algorithm shouldn't include
computer code. Instead, the
algorithm should be written in
such a way that it can be used in
different programming languages.
11. An algorithm to add two numbers and
display the result.
step 1 − START ADD
step 2 − get values of a & b
step 3 − c ← a + b
step 4 − display c
step 5 − STOP
An Example of a
Simple Algorithm
13. Pseudocode
Pseudocode is a notation system for
writing algorithms.
The pseudocode notation specifies
operations that a machine can
perform in as human-friendly (e.g.,
easy to read) way as possible, while
avoiding ambiguity.
14. A mixture of natural language and high-level programming
concepts that describes the main ideas behind a general
implementation of a data structure or algorithm.
It is more structured than usual prose but less formal than
programming language
15. PSEUDOCODE
CONVENTIONS
:
1. Give a valid name for the pseudo-code procedure. (See
sample code for insertion sort at the end)
2. Use proper Indentation for every statement in a block
structure.
3.Use the line numbers for each line of code.
4. For a flow control statements use if else. Always end an if
statement with an end-if. Both if, else and end-if should be
aligned vertically in same line.
Ex:
If (conditional expression)
statements (see the indentation)
else
statements
end-if
16. 5. Use “=” or “← ” operator for assignment statements.
Ex:
i = j or I ← j
n = 2 to length[A] or
n ← 2 to length[A] .
6. Array elements can be represented by specifying the
array name followed by the index in square brackets.
For example,
A[i] indicates the ith element of the array A.
7. For looping or iteration use for or while statements.
Always end a for loop with end for and a while with end-
while.
8. The conditional expression of for or while can be written
as shown in rule (4).
PSEUDOCODE
CONVENTIONS
17. Sample pseudo-code for insertion sort using
the above conventions:
• INSERTION-SORT(A)
1. for j ← 2 to length[A]
2. key ← A[j]
3. I ← j – 1
4. while i > 0 and A[i] < key // If
required, use this convention for a
comment
5. A[i+1] ← A[i] // Swap two elements of
array.
6. i ← i –1
7. end-while
8. A[i+1] ← key
9. end-for