DS 1
DS 1
UNIT II:
Algorithms and Linear Data Structure: Linked List (LL) Linked List:
Features, Representation of Linked List in memory using array, Types
of LL, Algorithms and operations onto LL: traversing, insertion,
deletion, searching & their implementation, Applications (5 Hrs)
UNIT III:
Linear Data Structure: Stack and Queue Stack: Definition, Memory
representation of Stacks using array and Linked List. Operations on to
Stack: Push and Pop. Stack Applications: Recursion, Solve arithmetic
expressions, tower of Hanoi etc. Queue: Definition, Memory
representation of Queue using array and Linked List, Types of queue,
Operations on queues: Traversing, Insertion, Deletion, Searching.
Applications (6 Hrs)
SYLLABUS
UNIT IV:
Sorting, Sorting Methods and its Algorithms Simple Sorting
Algorithms, Bubble Sort, Quick Sort, Insertion Sort, Selection
Sort, Heap Sort, Merge Sort, Bucket Sort and their Applications.
(6 Hrs)
UNIT V:
Non-Linear Data Structure: Tree Trees: Terminology, Types,
Binary trees and their representation in memory, traversing in
binary trees using stacks. Binary Search Trees, searching,
inserting and deleting nodes in binary trees, Heap tree, Path
length & Huffman’s algorithm, Spanning Trees, Basic concepts of
Kruskal’s and Prim’s Algorithm, B+ tree. (6 Hrs)
UNIT VI:
Non-Linear Data Structure: Graph Graph: Definitions,
Sequential and Linked-list representation of Graphs, Warshalls’
algorithm, Bridges in graph, Johnsons algorithm. Graph
Traversals: Breadth First Search, Depth First Search, Topological
Sort, Shortest Path Algorithms: Unweighted Shortest Paths,
Basic concepts of Dijkstra’s Algorithm.
Text Books:
1. Mark Allen Weiss, ‘Data Structures and Algorithm
Analysis in C++’, 3/e, Florida International
University, ISBN 0-321-37531-9
2. Seymour Lipschutz, ‘Theory & Problems of Data
Structures’, Schaum’s Outline Series (Mc Graw-Hill)
International Editions
Reference Books:
1.John Hubbard: ‘Schaum’s Outline DataStructure
with C++’, ISBN-13: 978-0071353458
2.Jean-Paul Tremblay, Paul G. Sorenson, P. G.
Sorenson, ‘An Introduction to Data Structures With
Applications’, (McGraw-Hill Computer Science
Series), ISBN-13: 978-0070651579
3.Ellis Horowitz, Sartaj Sahni, Rajasekaran ,
‘Computer Algorithms/C++’, 2nd edition, 2019.
COURSE OBJECTIVES
To understand the role of Data Structure in memory
management
To acquire knowledge of different types of data structures like:
array, types of array, linked list, stacks, queues, trees, and their
memory representation
To learn the fundamental concept of data structure and
emphasize the importance of it in developing and implementing
efficient algorithms
To analyze complexity of algorithms in terms of time and
memory space
To Understand data structure, types of data structure and their
common applications
To study the use of algorithms to perform the operations on data
structure such as traversing, insertion, deletion, searching,
sorting and merging
To understand importance and applications of linear and non-
linear data structure
To obtained knowledge and skill of Sorting Methods such as:
Bubble Sort, Quick Sort, Merge Sort, Selection Sort and Bucket
Sort
To Learn and acquire knowledge about the use of Tree and
Graph in applications
COURSE OUTCOMES
Define fundamental features of array, linked-list, stack,
queue, tree and graph
Write the algorithms to perform various operations such
as: Search, Insertion, Deletion, Sort etc
Implement algorithms for various operations on linear
and non-linear data structure
Classify the linear data structures such as Array, Linked-
List, Stack, Queue and non-linear data Structures such
as Tree and Graph with their applications
Implement linear data structures: Array, Linked-list,
Stack, Queue using suitable language C,C++
Implement non-linear data structure: Tree, Graph using
C or C++
know different types of sorting methods and their
algorithms
Choose appropriate algorithm for Searching
Perform operations of traverse, insertion, deletion
UNIT I
➢Time-Space Tradeoff:
• Each of algorithms will involve a particular data structure.
Accordingly, we may not always be able to use the most efficient
algorithm, since the choice of data structure depends on many things,
including the type of data structure and the frequency with which
various data operations are applied.
Steps, Control, Exit: The steps of the algorithm are executed one after
other, beginning with step 1, unless indicated otherwise. Control may be
transferred to step n of the algorithm by the statement “Go to step n”.
Generally Go to statements may be practically eliminated by using certain
control structures. The algorithm is completed when statement Exit is
encountered.
Variable Names: Variable names will use capital letters, as in MAX and
DATA.
Ex. Max: =DATA [1] Assigns the value in DATA [1] to MAX.
Input and Output: Data may be input and assigned to variables by
means of a Read statement with following form:
Read: Variable names.
Suppose f(n) and g(n) are functions defined on the positive integers with
the property that f(n) is bounded by some multiple of g(n) for almost all n.
this is, suppose there exist a positive integer n0 and a positive number M
such that, for all n> n0, we have |f(n)|<=M|g(n)| Then we may write
f(n)=O(g(n))
which is read “f(n) is of order g(n).”
LINEAR ARRAYS
A Linear array is a list of a finite number n of homogeneous data elements
such that:
❑ The elements of the array are referenced respectively by an index set
consisting of n consecutive numbers.
❑ The elements of the array are stored respectively in successive memory
locations.
The number n of elements is called the length or size of the array
If not explicitly stated, we will assume the index set consists of the integers
1,2,…n.
In general, the length or the number of elements of the array can be obtained
from the index set by the formula.
Length = UB-LB+1
Where,
▪ UB- Largest Index
▪ LB- Smallest Index
The elements of an array A may be denoted by the subscript notation
A1,A2,A3,…………An Or by the bracket notation
A[1],A[2],A[3],…………..A[N]
REPRESENTATION OF LINEAR ARRAYS IN MEMORY
Let LA be a linear array in the memory of the computer.
Memory of the computer is simply a sequence of addressed locations as follows:
Notation:
LOC (LA [K]) =address of the element LA [K] of the array LA
Computer does not need to keep track of the address of every element of LA, but needs
to keep track only of the address of the first element of LA, denoted by
Base (LA) Called base address of LA
Using Base(LA), the computer calculates the address of any element of LA by the
following formula:
Using Base(LA), the computer calculates the address of any
element of LA by the following formula:
LOC (LA [K]) =Base (LA) + w (K-lower bound)
Where,
w is the number of words per memory cell for the array LA
Given any subscript K, one can locate and access the content
of LA[K] without scanning any other element of LA.
TRAVERSING LINEAR ARRAY
characters respectively.
Variables: Each programming language has its own rules for forming character
before the program is executed and cannot change throughout the program.
❑ Semistatic: By semistatic character variable, we mean a variable whose length
may vary during the execution of the program as long as the length does not
exceed a maximum value determined by the program before the program is
executed.
❑ Dynamic: By dynamic character variable, we mean a variable whose length can
Substring:
Accessing a substring from a given string requires three pieces of
information:
1. The name of the string or the string itself
2. The position of the first character of the substring in the given
string
3. The length of the substring or the position of the last character of
the substring.
We call this operation SUBSTRING. Specifically, we write
SUBSTRING (string, initial, length)
To denote the substring of a string S beginning in a position K
having a length L.
Ex. SUBSTRING (‘TO BE OR NOT BE’, 4, 7) =’BE OR N’
SUBSTRING (‘THE END’, 4, 4) =’□END’
INDEXING
If the pattern P does not appear in the text T, then INDEX is
assigned the value 0. the arguments “text” and “pattern” can
be either string constants or string variables.
Ex: INSERT(‘ABCDEFG’,3,’XYZ’)=’ABXYZCDEFG’
INSERT (‘ABCDEFG’,6,’XYZ’)=’ABCDEXYZFG’
Wk=SUBSTRING(T,K,LENGTH(P))
3. P=abc T=(ab)5
SECOND PATTERN MATCHING ALGORITHM
: Second pattern matching algorithm uses a table which is derived from a
particular pattern P but is independent of the text T.
Ex. Suppose P = aaba
Suppose T = T1, T2, T3 . . . . , where T1 denotes the ith character of T; and
suppose the first two characters of T match those of P; i.e. , suppose T = aa.
. . . Then T has one of the following three forms:
1.T = aab . . . . ,
2.T = aaa . . . . ,
3.T = aax
a b x
Q0 Q1 Q0 Q0
Q1 Q2 Q0 Q0
Q2 Q2 Q3 Q0
Q3 P Q0 Q0
a b x
Q0 Q 1 Q0 Q0
Q1 Q 2 Q0 Q0
Q2 Q 2 Q3 Q0
Q3 P Q0 Q0
SECOND PATTERN MATCHING/FAST PATTERN MATCHING ALGORITHM
SEARCHING: LINEAR SEARCH:
Let DATA be a collection of data elements in
memory, and suppose a specific ITEM of information
is given.
Searching refers to the operation of finding the
location LOC of ITEM in DATA, or printing some
message that ITEM does not appear there.
The search is said to be successful if ITEM does
appear in DATA and unsuccessful otherwise.
Linear Search: The method of searching, which
traverses DATA sequentially to locate ITEM, is called
linear search or sequential search.
LINEAR SEARCH
Algorithm:
(Linear search) LINEAR (DATA, N, ITEM, LOC),
here DATA is a linear array with N elements, and
ITEM is a given item of information. This algorithm
finds the location LOC of ITEM in DATA, or sets
LOC: =0 if the search is unsuccessful.
1. [Insert ITEM at the end of DATA.] Set DATA
[N+1]:= ITEM.
2. [Initialize counter.] Set LOC: =1.
3. [Search for ITEM.]
Repeat while DATA [LOC]! =ITEM:
Set LOC: =LOC+1
[End of loop]
4. [Successful?] If LOC= N+1, then: Set LOC: =0.
5. Exit.
COMPLEXITY OF THE LINEAR SEARCH ALGORITHM
The computer does not keep track of the address LOC(LA[K]) of every
element LA[K], but does keep track of Base(LA), the address of the first
element of LA. The computer uses the formula
The computer keeps track of Base (A)- the address of the first element A[1, 1] of
A-and computes the address LOC(A[J, K]) of A[J, K] using the formula.
Base(C) Denotes the address of the first element of C, and w denotes the
number of words per memory location.