Algorithm Basic
Algorithm Basic
1
What this course is about ?
• As applications are getting complex and data rich, there are three common
problems that applications face now-a-days.
• Data Search − Consider an inventory of 1 million(106) items of a store. If the
application is to search an item, it has to search an item in 1 million(106) items
every time slowing down the search. As data grows, search will become
slower.
• Processor speed − Processor speed although being very high, falls limited if
the data grows to billion records.
• Multiple requests − As thousands of users can search data simultaneously
on a web server, even the fast server fails while searching the data.
Data abstraction
• Data Type
A data type is a collection of objects and a set of
operations that act on those objects.
● For example, the data type int consists of the objects {0,
+1, -1, +2, -2, …, INT_MAX, INT_MIN} and the
operations +, -, *, /, and %.
• The data types of C
● The basic data types: char, int, float and double
● The group data types: array and struct
● The pointer data type
● The user-defined types
Data abstraction
• Abstract Data Type
● An abstract data type(ADT) is a data type
that is organized in such a way that
the specification of the objects and
the operations on the objects is separated from
the representation of the objects and
the implementation of the operations.
● We know what is does, but not necessarily how it will do it.
Data abstraction
• Specification vs. Implementation
● An ADT is implementation independent
● Operation specification
● function name
● the types of arguments
● the type of the results
● The functions of a data type can be classify into several categories:
● creator / constructor
● transformers
● observers / reporters
2.1 Model for an ADT
Interface - Operations
Data Structure
Implement ADTs
Abstract Data Types
• Abstract data type (ADT)
● An ADT is composed of
● A collection of data
● A set of operations on that data
● Specifications of an ADT indicate
● What the ADT operations do, not how to implement them
● Implementation of an ADT
● Includes choosing a particular data structure
12/04/22
Abstract Data Types
A wall of ADT operations isolates a data structure from the program that uses it
Array
Linked List
Stack
Queue
Non Linear Data Structures: This data structure does not form a sequence i.e. each item or element is connected
with two or more other items in a non-linear arrangement. The data elements are not arranged in sequential
structure.
Tree
Graph
12/04/22
Real Life Applications of Data Structures | Log2Base2 -
YouTube
14
ARRAY OPERATIONS-SEARCH
• In an unsorted array, the search operation can be performed by
linear traversal from the first element to the last element.
INSERTION
• In an unsorted array, the insert operation is faster as compared to a sorted array
because we don’t have to care about the position at which the element is to be placed.
Insert an element at a particular index in an array | Data
Structure Visualization - Bing video
•#include<stdio.h>
•int main(){
• int student[40],pos,i,size,value;
• printf("enter no of elements in array of students:");
• scanf("%d",&size);
• printf("enter %d elements are:\n",size);
• for(i=0;i<size;i++)
• scanf("%d",&student[i]);
• printf("enter the position where you want to insert the element:");
• scanf("%d",&pos);
• printf("enter the value into that position:");
• scanf("%d",&value);
• for(i=size-1;i>=pos-1;i--)
• student[i+1]=student[i];
• student[pos-1]= value;
• printf("final array after inserting the value is\n");
• for(i=0;i<=size;i++)
• printf("%d\n",student[i]);
• return 0;
•}
DELETION
• In the delete operation, the element to be deleted is searched using the linear
search, and then delete operation is performed followed by shifting the
elements.
Algorithms and Comlplexity I 12/04/22
20
REMOVING AN ELEMENT FROM AN ARRAY
12/04/22
int main()
{
int arr[size] = {1, 20, 5, 78, 30};
int key, i, index = -1;
}
return 0;
22
Q&A
Thank You