SlideShare a Scribd company logo
PRESENTED BY:
AKSHAY WADALKAR
   An array is a collection of elements of similar
    datatype.

   Contiguous memory allocation takes place.

   An array is a DS in which we can access every
    element directly using position variable .

   It is rather an organizational concept.

   Array elements can be accessed individually.

   Syntax: datatype nameofarray [dimension];
 Two types of array-
1. Single dimensional




      single for loop.
2.   Multidimensional




      nesting of for loop.
   Array can be of integer ,character and string.

   Integer and character array can be
    implemented by same logic

   Implementation of string array is quiet
    different from the two.

   We can study the array implementation using
    integer array.
Creation of integer array
                 int
 7   a[0] i=0     a[10]={7,1,32,58,0,5,8,16,9,23}
14   a[1] i=1     ;

32   a[2] i=2    Integer array “a”.
58   a[3] i=3
                    It is of dimension 10 (from 0
 0   a[4] i=4       to 9).
 5   a[5] i=5      Take positing variable i.
 8   a[6] i=6
                   Its storage will be continuous
16   a[7] i=7       20 bytes(2 bytes each).
 9   a[8] i=8
23   a[9] i=9
1.   DECLARATION
     N     SIZE
2.   OPERATION
     Repeat for i= 0 to (size-1)
     arr[i]= num
     end repeat
3.   OUTPUT
     RETURN(arr[i])
 DECLARATION
i   rows
j   coloumn
 OPERATION
    ◦ Repeat for i=0 to (rows-1)
      Repeat for j=0 to (coloumn-1)
        Array[i][j]=num
      End repeat
    ◦ End repeat
   OUTPUT
    Return(Array[i][j])
   No need to declare large number of variables
    individually.

   Variables are not scattered in memory , they
    are stored in contiguous memory.

   Ease the handling of large no of variables of
    same datatype.
   Rigid structure.

   Can be hard to add/remove elements.

   Cannot be dynamically resized in most
    languages.

   Memory loss.
AS A DATA STRUCTURE
   Each element (node) inside a linked list is
    linked to the previous node and successor
    (next) node.
   This allows for more efficient insertion and
    deletion of nodes.



                5     3     14    2




                                             continued
   Each item has a data part (one or more data
    members), and a link that points to the next item.

   One natural way to implement the link is as a
    pointer; that is, the link is the address of the next
    item in the list.

   It makes good sense to view each item as an object,
    that is, as an instance of a class.

   We call that class: Node

   The last item does not point to anything. We set its
    link member to NULL. This is denoted graphically by
    a self-loop
   Insert a new item
    ◦ At the head of the list, or
    ◦ At the tail of the list, or
    ◦ Inside the list, in some designated position
   Search for an item in the list
    ◦ The item can be specified by position, or by some
      value
   Delete an item from the list
    ◦ Search for and locate the item, then remove the
      item, and finally adjust the surrounding pointers
   Suppose you want to find the item whose data
    value is A

   You have to search sequentially starting from the
    head item rightward until the first item whose data
    member is equal to A is found.

   At each item searched, a comparison between the
    data member and A is performed.
LOGIC FOR SEARCHING A LINKED
              LIST

•Since nodes in a linked list have no names, we use two
pointers, pre (for previous) and cur (for current).

•At the beginning of the search, the pre pointer is null and
the cur pointer points to the first node.

•The search algorithm moves the two pointers together
towards the end of the list.
   Declaration
    ◦ Current     0
   Searching
    ◦ for (current = first; current != NULL; current =
      current->next)
    ◦ if (searchItem == current(data))
    ◦ return (current);
    ◦ Break
   Output
    ◦ return (NULL);
Array implementation and linked list as datat structure
Insertion of an Element at the
Head :
  Before the insertion:

       head


                  next              next             next


    element       element           element
           Rome           Seattle          Toronto
Have a new node:

                    head

               next           next             next             next


  element       element       element          element
        Baltimore      Rome          Seattle          Toronto




  Node x = new Node();
  x.setElement(new String(“Baltimore”));
  The following statement is not correct:
  x.element = new String(“Baltimore”));
After the insertion:

     head

                 next          next             next             next


  element        element       element          element
         Baltimore      Rome          Seattle          Toronto




     x.setNext(head);
     head = x;
Deleting an Element at the
Head :
Before the deletion:

     head

                next          next             next             next


  element        element      element          element
         Baltimore     Rome          Seattle          Toronto
Remove the node from the list:

                     head

                next           next             next             next


  element        element       element          element
         Baltimore      Rome          Seattle          Toronto



     head = head.getNext();
After the deletion:

     head

                next             next             next


  element       element          element
         Rome          Seattle          Toronto
Insertion of an Element at the
Tail :
Before the insertion:

     head                                tail


                next              next             next


  element       element           element
         Rome           Seattle          Toronto
Have a new node:

    head                              tail


              next             next             next           next


  element     element          element            element
       Rome          Seattle          Toronto           Baltimore


    Node x = new Node( );
    x.setElement(new String(“Baltimore”));
    x.setNext(null);
    tail.setNext(x);
    tail = x;
After the insertion:

     head                                          tail

                next             next             next           next


   element      element          element      element
         Rome          Seattle          Toronto           Baltimore
Deleting an Element at the
Tail :
Deletion of an element at the tail of a singly linked list takes
more effort.

The difficulty is related with the fact that the last node does not
have a link to the previous node which will become the new
tail of the list.
Before the deletion:

     head                                          tail

                next             next             next           next


  element       element          element      element
         Rome          Seattle          Toronto           Baltimore
Remove the node: How can we find the new tail?

    head                                                tail ?

               next             next             next              next


  element      element          element            element
        Rome          Seattle          Toronto              Baltimore




                                                    should be removed
Singly Linked Lists and Arrays
        Singly linked list                   Array
 Elements are stored in linear   Elements are stored in linear
 order, accessible with links.   order, accessible with an
                                 index.

 Do not have a fixed size.       Have a fixed size.

 Cannot access the previous      Can access the previous
 element directly.               element easily.

 No binary search.               Binary search.
Advantages of linked lists
   Linked lists are dynamic, they can grow or
    shrink as necessary

   Linked lists are non-contiguous; the logical
    sequence of items in the structure is
    decoupled from any physical ordering in
    memory




CS314                   Linked Lists               31
Applications of linked lists

•A linked list is a very efficient data structure for sorted list
that will go through many insertions and deletions.

•A linked list is a dynamic data structure in which the list
can start with no nodes and then grow as new nodes are
needed. A node can be easily deleted without moving other
nodes, as would be the case with an array.

•For example, a linked list could be used to hold the
records of students in a school. Each quarter or semester,
new students enroll in the school and some students leave
or graduate.
Array implementation and linked list as datat structure

More Related Content

What's hot (20)

PDF
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
PPTX
linked list in data structure
shameen khan
 
PPTX
joins in database
Sultan Arshad
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Data structure & its types
Rameesha Sadaqat
 
PPT
Unit 1 introduction to data structure
kalyanineve
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
PPTX
Set data structure
Tech_MX
 
PPT
DATA STRUCTURES
bca2010
 
PPTX
B and B+ tree
Ashish Arun
 
PPTX
Data Structures : hashing (1)
Home
 
PPT
Queue Data Structure
Lovely Professional University
 
PPT
Arrays
SARITHA REDDY
 
PPTX
Binary Tree in Data Structure
Meghaj Mallick
 
PPTX
Tree - Data Structure
Ashim Lamichhane
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPTX
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
PPTX
Quick sort
Afaq Mansoor Khan
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
linked list in data structure
shameen khan
 
joins in database
Sultan Arshad
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Data structure & its types
Rameesha Sadaqat
 
Unit 1 introduction to data structure
kalyanineve
 
Linked list
KalaivaniKS1
 
heap Sort Algorithm
Lemia Algmri
 
Set data structure
Tech_MX
 
DATA STRUCTURES
bca2010
 
B and B+ tree
Ashish Arun
 
Data Structures : hashing (1)
Home
 
Queue Data Structure
Lovely Professional University
 
Binary Tree in Data Structure
Meghaj Mallick
 
Tree - Data Structure
Ashim Lamichhane
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Quick sort
Afaq Mansoor Khan
 
Binary Tree Traversal
Dhrumil Panchal
 

Viewers also liked (19)

PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Double linked list
raviahuja11
 
PPTX
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
John C. Havens
 
PPTX
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Lovelyn Rose
 
PDF
Cyber Crime
Abhishek L.R
 
PPT
Linked list
Trupti Agrawal
 
PPTX
6. Linked list - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
Data structure using c module 1
smruti sarangi
 
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPTX
7 Myths of AI
CrowdFlower
 
PPTX
Linked list
akshat360
 
PPT
linked list
Narendra Chauhan
 
PPTX
Trees data structure
Sumit Gupta
 
PPT
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
PPTX
Doubly linked list
Fahd Allebdi
 
PPTX
Binary Search Tree
Abhishek L.R
 
PPTX
Open Legal Data Workshop at Stanford
Harry Surden
 
PPTX
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden
 
PPTX
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Double linked list
raviahuja11
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
John C. Havens
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Lovelyn Rose
 
Cyber Crime
Abhishek L.R
 
Linked list
Trupti Agrawal
 
6. Linked list - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Data structure using c module 1
smruti sarangi
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
7 Myths of AI
CrowdFlower
 
Linked list
akshat360
 
linked list
Narendra Chauhan
 
Trees data structure
Sumit Gupta
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
Doubly linked list
Fahd Allebdi
 
Binary Search Tree
Abhishek L.R
 
Open Legal Data Workshop at Stanford
Harry Surden
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Ad

Similar to Array implementation and linked list as datat structure (20)

PPT
Funddamentals of data structures
Globalidiots
 
PPT
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
PPTX
Insertion into linked lists
MrDavinderSingh
 
PPTX
link listgyyfghhchgfvgggfshiskabaji.pptx
zainshahid3040
 
PPT
3.ppt
ArifKamal36
 
PPT
3.ppt
ArifKamal36
 
PPTX
Arrays and linked lists
AfriyieCharles
 
PPT
linked list (c#)
swajahatr
 
PPT
Linked lists
SARITHA REDDY
 
PPT
Data structure lecture 5
Kumar
 
PPT
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
PPT
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
PPT
Operations Running Times 1DSA EE 2204.ppt
hacene2448
 
PPT
Data Structure lec#2
University of Gujrat, Pakistan
 
PPT
Data structure lecture 1
Kumar
 
PDF
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
PPTX
DS_LinkedList.pptx
msohail37
 
PPT
Operations on linked list
Sumathi Kv
 
PPT
List data structure
Mahmoud Abuwarda
 
PPT
List Data Structure
Zidny Nafan
 
Funddamentals of data structures
Globalidiots
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
Insertion into linked lists
MrDavinderSingh
 
link listgyyfghhchgfvgggfshiskabaji.pptx
zainshahid3040
 
Arrays and linked lists
AfriyieCharles
 
linked list (c#)
swajahatr
 
Linked lists
SARITHA REDDY
 
Data structure lecture 5
Kumar
 
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Operations Running Times 1DSA EE 2204.ppt
hacene2448
 
Data Structure lec#2
University of Gujrat, Pakistan
 
Data structure lecture 1
Kumar
 
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
DS_LinkedList.pptx
msohail37
 
Operations on linked list
Sumathi Kv
 
List data structure
Mahmoud Abuwarda
 
List Data Structure
Zidny Nafan
 
Ad

More from Tushar Aneyrao (7)

PPTX
Varaiational formulation fem
Tushar Aneyrao
 
PPTX
General purpose simulation System (GPSS)
Tushar Aneyrao
 
PPTX
Safety of vehicles
Tushar Aneyrao
 
PPT
Seminar on cim 02
Tushar Aneyrao
 
PPTX
Presentation on robotics
Tushar Aneyrao
 
PPTX
Seminar o nm aterial enginering
Tushar Aneyrao
 
PPTX
Seminar on fatigue
Tushar Aneyrao
 
Varaiational formulation fem
Tushar Aneyrao
 
General purpose simulation System (GPSS)
Tushar Aneyrao
 
Safety of vehicles
Tushar Aneyrao
 
Seminar on cim 02
Tushar Aneyrao
 
Presentation on robotics
Tushar Aneyrao
 
Seminar o nm aterial enginering
Tushar Aneyrao
 
Seminar on fatigue
Tushar Aneyrao
 

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
July Patch Tuesday
Ivanti
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 

Array implementation and linked list as datat structure

  • 2. An array is a collection of elements of similar datatype.  Contiguous memory allocation takes place.  An array is a DS in which we can access every element directly using position variable .  It is rather an organizational concept.  Array elements can be accessed individually.  Syntax: datatype nameofarray [dimension];
  • 3.  Two types of array- 1. Single dimensional single for loop. 2. Multidimensional nesting of for loop.
  • 4. Array can be of integer ,character and string.  Integer and character array can be implemented by same logic  Implementation of string array is quiet different from the two.  We can study the array implementation using integer array.
  • 5. Creation of integer array  int 7 a[0] i=0 a[10]={7,1,32,58,0,5,8,16,9,23} 14 a[1] i=1 ; 32 a[2] i=2  Integer array “a”. 58 a[3] i=3  It is of dimension 10 (from 0 0 a[4] i=4 to 9). 5 a[5] i=5  Take positing variable i. 8 a[6] i=6  Its storage will be continuous 16 a[7] i=7 20 bytes(2 bytes each). 9 a[8] i=8 23 a[9] i=9
  • 6. 1. DECLARATION N SIZE 2. OPERATION Repeat for i= 0 to (size-1) arr[i]= num end repeat 3. OUTPUT RETURN(arr[i])
  • 7.  DECLARATION i rows j coloumn  OPERATION ◦ Repeat for i=0 to (rows-1)  Repeat for j=0 to (coloumn-1)  Array[i][j]=num  End repeat ◦ End repeat  OUTPUT Return(Array[i][j])
  • 8. No need to declare large number of variables individually.  Variables are not scattered in memory , they are stored in contiguous memory.  Ease the handling of large no of variables of same datatype.
  • 9. Rigid structure.  Can be hard to add/remove elements.  Cannot be dynamically resized in most languages.  Memory loss.
  • 10. AS A DATA STRUCTURE
  • 11. Each element (node) inside a linked list is linked to the previous node and successor (next) node.  This allows for more efficient insertion and deletion of nodes. 5 3 14 2 continued
  • 12. Each item has a data part (one or more data members), and a link that points to the next item.  One natural way to implement the link is as a pointer; that is, the link is the address of the next item in the list.  It makes good sense to view each item as an object, that is, as an instance of a class.  We call that class: Node  The last item does not point to anything. We set its link member to NULL. This is denoted graphically by a self-loop
  • 13. Insert a new item ◦ At the head of the list, or ◦ At the tail of the list, or ◦ Inside the list, in some designated position  Search for an item in the list ◦ The item can be specified by position, or by some value  Delete an item from the list ◦ Search for and locate the item, then remove the item, and finally adjust the surrounding pointers
  • 14. Suppose you want to find the item whose data value is A  You have to search sequentially starting from the head item rightward until the first item whose data member is equal to A is found.  At each item searched, a comparison between the data member and A is performed.
  • 15. LOGIC FOR SEARCHING A LINKED LIST •Since nodes in a linked list have no names, we use two pointers, pre (for previous) and cur (for current). •At the beginning of the search, the pre pointer is null and the cur pointer points to the first node. •The search algorithm moves the two pointers together towards the end of the list.
  • 16. Declaration ◦ Current 0  Searching ◦ for (current = first; current != NULL; current = current->next) ◦ if (searchItem == current(data)) ◦ return (current); ◦ Break  Output ◦ return (NULL);
  • 18. Insertion of an Element at the Head : Before the insertion: head next next next element element element Rome Seattle Toronto
  • 19. Have a new node: head next next next next element element element element Baltimore Rome Seattle Toronto Node x = new Node(); x.setElement(new String(“Baltimore”)); The following statement is not correct: x.element = new String(“Baltimore”));
  • 20. After the insertion: head next next next next element element element element Baltimore Rome Seattle Toronto x.setNext(head); head = x;
  • 21. Deleting an Element at the Head : Before the deletion: head next next next next element element element element Baltimore Rome Seattle Toronto
  • 22. Remove the node from the list: head next next next next element element element element Baltimore Rome Seattle Toronto head = head.getNext();
  • 23. After the deletion: head next next next element element element Rome Seattle Toronto
  • 24. Insertion of an Element at the Tail : Before the insertion: head tail next next next element element element Rome Seattle Toronto
  • 25. Have a new node: head tail next next next next element element element element Rome Seattle Toronto Baltimore Node x = new Node( ); x.setElement(new String(“Baltimore”)); x.setNext(null); tail.setNext(x); tail = x;
  • 26. After the insertion: head tail next next next next element element element element Rome Seattle Toronto Baltimore
  • 27. Deleting an Element at the Tail : Deletion of an element at the tail of a singly linked list takes more effort. The difficulty is related with the fact that the last node does not have a link to the previous node which will become the new tail of the list.
  • 28. Before the deletion: head tail next next next next element element element element Rome Seattle Toronto Baltimore
  • 29. Remove the node: How can we find the new tail? head tail ? next next next next element element element element Rome Seattle Toronto Baltimore should be removed
  • 30. Singly Linked Lists and Arrays Singly linked list Array Elements are stored in linear Elements are stored in linear order, accessible with links. order, accessible with an index. Do not have a fixed size. Have a fixed size. Cannot access the previous Can access the previous element directly. element easily. No binary search. Binary search.
  • 31. Advantages of linked lists  Linked lists are dynamic, they can grow or shrink as necessary  Linked lists are non-contiguous; the logical sequence of items in the structure is decoupled from any physical ordering in memory CS314 Linked Lists 31
  • 32. Applications of linked lists •A linked list is a very efficient data structure for sorted list that will go through many insertions and deletions. •A linked list is a dynamic data structure in which the list can start with no nodes and then grow as new nodes are needed. A node can be easily deleted without moving other nodes, as would be the case with an array. •For example, a linked list could be used to hold the records of students in a school. Each quarter or semester, new students enroll in the school and some students leave or graduate.