dsa
dsa
and Algorithms
N Radhakrishnan
Assistant Professor
Anna University, Chennai
Topics
Introduction
Definitions
Classification of Data Structures
Arrays and Linked Lists
Abstract Data Types [ADT]
• The List ADT
Array-based Implementation
Linked List Implementation
Cursor-based Implementation
Doubly Linked Lists
Definition:
• Is a set of operation
• Mathematical abstraction
• No implementation detail
Example:
• Lists, sets, graphs, stacks are examples of
ADT along with their operations
MakeEmpty
PrintList
Find
FindKth
Insert
Delete
Next
Previous
Syntax:
• ElementType arrayName [CAPACITY];
• ElementType arrayName [CAPACITY] =
{ initializer_list };
Example in C++:
• int b [5];
• int b [5] = {19, 68, 12, 45, 72};
LinearSearch (a,n,item,loc)
Here "a" is an array of the size n.
This algorithm finds the location of the
element "item" in the array "a".
If search item is found, it sets loc to the
index of the element; otherwise, it sets loc
to -1
index=linearsearch(array, num, key)
FindKth
Next O(1)
Previous
Pros
• Directly supported by C
• Provides random access
Cons
• Size determined at compile time
• Inserting and deleting elements is
time consuming
Pros
• Size determined during runtime
• Inserting and deleting elements is
quick
Cons
• No random access
• User must provide programming
support