OBJECTIVES:
• To understand the ADTs and its implementation.
• To apply sorting and searching techniques
• To learn and understand the design techniques in algorithms.
• To understand the efficiency of the algorithmic techniques.
TEXT BOOK:
1. Mark Allen Weiss, “Data structures and Algorithm Analysis in
C”,Addison Wesley, Second Edition,2007.
2. Anany Levitin,“Introduction to the Design and Analysis of
Algorithms”,Pearson Education,Third Edition,2012.
CS4301 DATA STRUCTURES AND ALGORITHMS I
UNIT I- INTRODUCTION TO DATA
STRUCTURES
Abstract Data Types (ADTs) – List ADT – array-
based implementation – linked list
implementation –– singly linked lists- doubly-
linked lists –circularly linked lists- applications
of lists –Polynomial Manipulation.
DATA STRUCTURE
Definition
• A data structure is a particular way of storing and
organizing data either in computer’s memory or on the
disk storage so that it can be used efficiently.
Applications of Data Structures
❖ Compiler design
❖ Operating system
❖ Statistical analysis package
❖ DBMS
❖ Numerical analysis
❖ Simulation
❖ Artificial Intelligence
CLASSIFICATION OF DATA STRUCTURES
LINEAR DATA STRUCTURES
• If the elements of a data structure are stored in a linear
or sequential order, then it is a linear data structure.
– Examples include arrays, linked lists, stacks, and queues.
• Linear data structures can be represented in memory in
two different ways.
– linear relationship between elements by means of
sequential memory locationsarray
– linear relationship between elements by means of
linkslinked list.
NON-LINEAR DATA STRUCTURES
• If the elements of a data structure are not stored in a
sequential order, then it is a non-linear data structure.
The relationship of adjacency is not maintained
between elements of a non-linear data structure.
– Examples include trees and graphs.
ABSTRACT DATA TYPE
An abstract data type (ADT) is the way we look at a data
structure, focusing on what it does and ignoring how it does its job.
• Abstract data type operations are
– Create, Display, Insertion, deletion, Modification
• Advantage of using ADTs
– It is reusable, robust
– It can be re-used at several places and it reduces coding efforts
– Encapsulation ensures that data cannot be corrupted
– The Working of various integrated operation cannot be tampered
with by the application program
– ADT ensures a robust data structure
List ADT
• List is an ordered set of elements.
• The general form of the list is A1, A2, A3, ..... ,AN
A1 - First element of the list
AN - Last element of the list
N - Size of the list
• If the element at position i is Ai then its successor is Ai+1
and its predecessor is Ai-1.
Various operations performed on List
• create -create a list
• printList() – prints all elements in the list
• find(x) – returns the position of the first occurrence of x
• insert(x, position) – inserts x into the list at the specified position
• delete (X) - The element X is deleted
• isEmpty( ) – returns true if the list has no elements
• makeEmpty( ) – Makes the list empty
• Next (i) - Returns the position of its successor element i+1.
• Previous (i)- Returns the position of its predecessor i-1
Implementation of list ADT:
• 1. Array based Implementation
• 2. Linked List based implementation
Array Implementation of list:
• Array is a collection of specific number of
same type of data stored in consecutive
memory locations.
• The basic operations performed on a list of
elements are
– 1. Creation of List.
– 2. Insertion of data in the List
– 3. Deletion of data from the List
– 4. Display all data in the List
– 5. Searching for a data in the list
Declaration of Array:
#define maxsize 10
int list[maxsize], n ;
Creation of Array
Insert Operation: Insert operation is used to insert an element at
particular position in the existing list.
void Insert( )
{
int i,data,pos;
printf("nEnter the data to be inserted:t");scanf("%d",&data);
printf("nEnter the position at which element to be inserted:t");
scanf("%d",&pos);
if (pos>=n)
printf (“Array overflow”);
for (i = n-1; i >= pos-1 ; i--)
{
list[i+1] = list[i];
}
list[pos-1] = data;
n=n+1;
Display();
}
Deletion
void Delete( )
{
int i, pos ;
printf("nEnter the position of the data to be deleted:t");
scanf("%d",&pos);
printf("nThe data deleted is:t %d", list[pos-1]);
for(i=pos-1;i<n-1;i++)
{
list[i]=list[i+1];
}
n=n-1;
Display();
}
Search Operation:
Routine to search an element in the array:
void Search( )
{
int search,i;
printf("nEnter the element to be searched:t");
scanf("%d",&search);
for(i=0;i<n;i++)
{
if(list[i]==search)
{
printf("Value is in the %d Position", i);
}
else
{
printf("Value %d is not in the list::", search);
continue;
}

unit 1_Linked list.pptx

  • 1.
    OBJECTIVES: • To understandthe ADTs and its implementation. • To apply sorting and searching techniques • To learn and understand the design techniques in algorithms. • To understand the efficiency of the algorithmic techniques. TEXT BOOK: 1. Mark Allen Weiss, “Data structures and Algorithm Analysis in C”,Addison Wesley, Second Edition,2007. 2. Anany Levitin,“Introduction to the Design and Analysis of Algorithms”,Pearson Education,Third Edition,2012. CS4301 DATA STRUCTURES AND ALGORITHMS I
  • 2.
    UNIT I- INTRODUCTIONTO DATA STRUCTURES Abstract Data Types (ADTs) – List ADT – array- based implementation – linked list implementation –– singly linked lists- doubly- linked lists –circularly linked lists- applications of lists –Polynomial Manipulation.
  • 3.
    DATA STRUCTURE Definition • Adata structure is a particular way of storing and organizing data either in computer’s memory or on the disk storage so that it can be used efficiently. Applications of Data Structures ❖ Compiler design ❖ Operating system ❖ Statistical analysis package ❖ DBMS ❖ Numerical analysis ❖ Simulation ❖ Artificial Intelligence
  • 4.
  • 5.
    LINEAR DATA STRUCTURES •If the elements of a data structure are stored in a linear or sequential order, then it is a linear data structure. – Examples include arrays, linked lists, stacks, and queues. • Linear data structures can be represented in memory in two different ways. – linear relationship between elements by means of sequential memory locationsarray – linear relationship between elements by means of linkslinked list. NON-LINEAR DATA STRUCTURES • If the elements of a data structure are not stored in a sequential order, then it is a non-linear data structure. The relationship of adjacency is not maintained between elements of a non-linear data structure. – Examples include trees and graphs.
  • 6.
    ABSTRACT DATA TYPE Anabstract data type (ADT) is the way we look at a data structure, focusing on what it does and ignoring how it does its job. • Abstract data type operations are – Create, Display, Insertion, deletion, Modification • Advantage of using ADTs – It is reusable, robust – It can be re-used at several places and it reduces coding efforts – Encapsulation ensures that data cannot be corrupted – The Working of various integrated operation cannot be tampered with by the application program – ADT ensures a robust data structure
  • 7.
    List ADT • Listis an ordered set of elements. • The general form of the list is A1, A2, A3, ..... ,AN A1 - First element of the list AN - Last element of the list N - Size of the list • If the element at position i is Ai then its successor is Ai+1 and its predecessor is Ai-1.
  • 8.
    Various operations performedon List • create -create a list • printList() – prints all elements in the list • find(x) – returns the position of the first occurrence of x • insert(x, position) – inserts x into the list at the specified position • delete (X) - The element X is deleted • isEmpty( ) – returns true if the list has no elements • makeEmpty( ) – Makes the list empty • Next (i) - Returns the position of its successor element i+1. • Previous (i)- Returns the position of its predecessor i-1
  • 10.
    Implementation of listADT: • 1. Array based Implementation • 2. Linked List based implementation
  • 11.
    Array Implementation oflist: • Array is a collection of specific number of same type of data stored in consecutive memory locations. • The basic operations performed on a list of elements are – 1. Creation of List. – 2. Insertion of data in the List – 3. Deletion of data from the List – 4. Display all data in the List – 5. Searching for a data in the list
  • 12.
    Declaration of Array: #definemaxsize 10 int list[maxsize], n ; Creation of Array
  • 14.
    Insert Operation: Insertoperation is used to insert an element at particular position in the existing list. void Insert( ) { int i,data,pos; printf("nEnter the data to be inserted:t");scanf("%d",&data); printf("nEnter the position at which element to be inserted:t"); scanf("%d",&pos); if (pos>=n) printf (“Array overflow”); for (i = n-1; i >= pos-1 ; i--) { list[i+1] = list[i]; } list[pos-1] = data; n=n+1; Display(); }
  • 16.
    Deletion void Delete( ) { inti, pos ; printf("nEnter the position of the data to be deleted:t"); scanf("%d",&pos); printf("nThe data deleted is:t %d", list[pos-1]); for(i=pos-1;i<n-1;i++) { list[i]=list[i+1]; } n=n-1; Display(); }
  • 18.
    Search Operation: Routine tosearch an element in the array: void Search( ) { int search,i; printf("nEnter the element to be searched:t"); scanf("%d",&search); for(i=0;i<n;i++) { if(list[i]==search) { printf("Value is in the %d Position", i); } else { printf("Value %d is not in the list::", search); continue; }

Editor's Notes

  • #2 application: https://www.youtube.com/watch?v=d_XvFOkQz5k https://www.youtube.com/watch?v=PoxdkCSsD3A