Professional Documents
Culture Documents
UNIT – I
Introduction to Data Structures
1.1 Introduction
Pseudo code
One of the most common tools for defining algorithms in pseudo code, which is part English, part
structure code.
The pseudo code to represent both data structures and code
Data items need not be declared, the first time we use a data name in an algorithm, it is
automatically declared.
Ex: set count to o
This statement declares a numeric data item named count and sets its value to zero
But the structure of data to be declared as shown below
node
data
link
end node
here in the above declaration it describes node consisting of a nested structure data and a pointer to
the next node(link)
Algorithm: Example of Pseudo code
Algorithm sample(pageNumber)
This algorithm reads a file and prints a report.
Pre pageNumber passed by reference
Post Report Printed
pageNumber contains number of pages in report
Return Number of lines printed
1. loop(not end of file)
1. read file
2. if (full page)
1. increment page number
2. write page heading
3. end if
4. write report line
5. increment line count
2. end loop
3. return line count
end sample
the colored comments provide documentation clarification when required
Algorithm can also be defined as finite set of instructions that are used to accomplish a specific task.
Algorithm header
The header will have
o Name
o List of parameters
o Precondition and post conditions
1
Prepared by: G. B. Hima Bindu, Asst. Prof., Dept. of IT, SVCET, CTR
Data structures Lecture Notes Unit - I
2
Prepared by: G. B. Hima Bindu, Asst. Prof., Dept. of IT, SVCET, CTR
Data structures Lecture Notes Unit - I
1 If (condition)
1 action1
2 else
1 action2
3 end if
Loop
A Loop statement iterates a block of code. The loop that we use in our pseudo code closely
resembles the while loop. It is a pretest loop; that is, the condition is evaluated before the
body of the loop is executed. If the condition is true, the body is executed. If the condition is
false, the loop terminates.
In the above algorithm statement 1 is an example of a loop. The end of the loop is indicated
by end loop in statement 2
Algorithm Analysis
For selected algorithms, we give the analysis section which explains salient points.
That examines only the points need to be emphasized or that may require some clarification.
1.2 Definition
A data structure is an aggregation of atomic and composite data into a set with defined
relationships.
Structure means a set of rules that holds data together
Data structure can be nested
We can have a data structure that consists of other data structures for ex, we can define the two
structures array and record as shown in table:
Array Record
Homogeneous sequence of data or data types Heterogeneous combination of data into a
known as elements single structure with an identified key
Position associated among the elements No association
Fig: Data structure examples
Modern programming languages allow programmers to create new data structures for an
application.
Data structure
1. A combination of elements in which each is either a data type or another data structure
2. A set of associations or relationships (structure) involving the combined elements
3
Prepared by: G. B. Hima Bindu, Asst. Prof., Dept. of IT, SVCET, CTR
Data structures Lecture Notes Unit - I
4
Prepared by: G. B. Hima Bindu, Asst. Prof., Dept. of IT, SVCET, CTR
Data structures Lecture Notes Unit - I
List
List is basically the collection of elements arranged in a sequential manner.
In memory we can store the list in two ways –
o List of sequentially stored elements – using arrays
o List of elements with associated pointers – using linked lists
Stack
A stack is a last in – first out (LIFO) data structure in which all insertions and deletions
are restricted to one end, called the top.
Queue
A Queue is a list in which data can be inserted at one end, called the rear and deleted
from the other end, called the front. It is a first in first out(FIFO) restricted data structure.
Non Linear data structures:
Trees
A tree consists of a finite set of elements, called nodes, and a finite set of directed lines,
called branches that connect the nodes.
Graphs
A graph is a collection of nodes, called vertexes, and line segments , called arcs or edges,
that connect pairs of nodes.
5
Prepared by: G. B. Hima Bindu, Asst. Prof., Dept. of IT, SVCET, CTR