0% found this document useful (0 votes)
29 views

Algorithm Basic

The document discusses algorithms and complexity using data structures as an example. It begins with an introduction to data structures and their importance for organizing data efficiently. It then covers key concepts like abstract data types and their specification versus implementation. Various types of data structures are presented, including linear structures like arrays, linked lists, stacks and queues, as well as non-linear structures like trees and graphs. Array operations like search, insertion and deletion are demonstrated with code examples. The document concludes with opportunities for questions.

Uploaded by

AARON ALEX X
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Algorithm Basic

The document discusses algorithms and complexity using data structures as an example. It begins with an introduction to data structures and their importance for organizing data efficiently. It then covers key concepts like abstract data types and their specification versus implementation. Various types of data structures are presented, including linear structures like arrays, linked lists, stacks and queues, as well as non-linear structures like trees and graphs. Array operations like search, insertion and deletion are demonstrated with code examples. The document concludes with opportunities for questions.

Uploaded by

AARON ALEX X
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

12/04/22

SRI RAMAKRISHNA ENGINEERING COLLEGE


[Educational Service : SNR Sons Charitable Trust]
[Autonomous Institution, Accredited by NAAC with ‘A’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all Eligible Programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.

Department of Computer Science and Engineering

20CS205 Algorithms and Complexity I


Topics to be Covered: Data Structures – Types – Abstract Data Types

Algorithms and Comlplexity I


Mrs.S.Prince Sahaya Brighty,
Assistant Professor/CSE,
Sri Ramakrishna Engineering College,
Coimbatore

1
What this course is about ?

• Data structures: conceptual and concrete ways to organize


data for efficient storage and efficient manipulation
-How to organize the data in computer memory

• Employment of this data structures in the design of


efficient algorithms
https://youtu.be/-q-3b_093do
Need for Data Structure

• 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

System design with ADTs


Identification of ADTs
Problem definiton (identify data or attributes)

Specify ADT interactions Specify ADT operations

Identify object hierarchy (if using OOP)

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

Algorithms and Comlplexity I


3-9
10 Algorithms and Comlplexity
12/04/22I
TYPES OF DATA STRUCTURE
TYPES OF DATA STRUCTURE
Linear Data Structures: A data structure is called linear if all of its elements are arranged in the linear order. In
linear data structures, the elements are stored in non-hierarchical way where each element has the successors and
predecessors except the first and last element.

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

Algorithms and Comlplexity I


13
12/04/22
Data Structures
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.

Algorithms and Comlplexity I


An array is a collection of items stored at contiguous memory locations. The idea
is to store multiple items of the same type together. This makes it easier to
calculate the position of each element by simply adding an offset to a base value,
i.e., the memory location of the first element of the array

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

Algorithms and Comlplexity I 12/04/22


21
#include<stdio.h>
#define size 5

12/04/22
int main()
{
int arr[size] = {1, 20, 5, 78, 30};
int key, i, index = -1;

printf("Enter element to delete\n");


scanf("%d",&key);
for(i = 0; i < size; i++)
{
if(arr[i] == key)
{
index = i;
break;
}
}
if(index != -1)
{
//shift all the element from index+1 by one position to the left

Algorithms and Comlplexity I


for(i = index; i < size - 1; i++)
arr[i] = arr[i+1];

printf("New Array : ");


for(i = 0; i < size - 1; i++)
printf("%d ",arr[i]);
}
else
printf("Element Not Found\n");

}
return 0;
22
Q&A
Thank You

Algorithms and Comlplexity I 12/04/22


23

You might also like