Вы находитесь на странице: 1из 25

Department of Computer Science and Engineering (CSE)

Artificial Neural Networks


- Introduction -

DEPARTMENT OF COMPUTER SCIENCE AND


• Birinderjit Singh Kalyan
ENGG.
• EE UNIVERSITY INSTITUTE OF ENGINEERING
CHANDIGARH UNIVERSITY, MOHALI
• Assistant Professor

www. cuchd.in Campus :


10/23/2018
Gharaun, Mohali www.
University cuchd.in
Institute of Engineering (UIE)
1
Department of Computer Science and Engineering (CSE)

DATA STRUCURES

Session : July- Dec 2018

Abhishek Sharma- E6201


Asst.prof
Chandigarh University

www. cuchd.in University Institute of Engineering (UIE) Campus :


Department of Computer Science and Engineering (CSE)

COURSE OBJECTIVE
• Course objective is how to use link list data structures and their
applications.
• Student can easily create link list and able to perform all types of
operation on link list.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

LEARNING OUTCOMES
• Students will learn about the link list data structures, their
advantages over arrays and disadvantages.
• Students can able to do the distinctions between arrays and link
lists.
• Students will learn about Link lists creations , all types of
insertions and deletions in link lists.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Applications of Linked Lists


• Linked Lists can be used to implement Stacks , Queues.
• Linked Lists can also be used to implement Graphs. (Adjacency
list representation of Graph).
• Implementing Hash Tables
• A polynomial can be represented in an array or in a linked list by
simply storing the coefficient and exponent of each term.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Link Lists
• A list implemented by each item having a link to the next item.
• Each node consists of its own data and the address of the next
node and forms a chain.
• Linked Lists are used to create trees and graphs.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

REPRESENTATIONS

[1]

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

APPLICATION OF LINK LIST

• Pre-defined number of categories implies that we can use


a simple static structure like array to represent the
categories. Since we do not know the number of items in
each category, we can represent items in each category
using a linked list. So what we need is an array of linked
lists
• You can also think of representing a web index using an
array of linked lists, where array contains the keywords
and linked lists contains the web URL’s where that
keyword occurs.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

ARRAYS VS LINKLISTS
Arrays
• have a pre-determined fixed size
• easy access to any element a[i] in constant time
• no space overhead
• Size = n x sizeof(element)

Linked lists
• no fixed size, grow one element at a time.
• space overhead
• each element must store an additional reference
• Size = n x sizeof (element) + n x sizeof(reference)
• no easy access to i-th element wrt the head of the list • need to
hop through all previous elements

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

HOW TO CREATE A LINK LIST


Suppose START is the pointer having the first position in linked list. Let
data be the element to be inserted in the new node. POS is the
position where the new node is to be inserted.
TEMP is a temporary pointer to hold the node address.
1. Input data to be inserted
2. Create a NewNode
3. NewNode → DATA = data
4. NewNode → Next = NULL
5. If (START equal to NULL)
then START = NewNode

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

INSERT A NODE AT THE END


Begin
1. Input DATA to be inserted
2. Create a NewNode
3. NewNode → DATA = DATA
4. NewNode → Next = NULL
5. If (START equal to NULL)
(a) START = NewNode
6. Else
(a) TEMP = START
(b) While (TEMP → Next not equal to NULL)
(i) TEMP = TEMP → Next
7. TEMP → Next = NewNode
Exit

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

INSERTING AT BEGINNING OF THE LIST

We can use the following steps to insert a new node at beginning of


the single linked list...
Step 1: Create a newNode .
NewNode → DATA = DATA
Step 2: Check whether list is Empty (head == NULL)
Step 3: If it is Empty then,
set newNode→next = NULL and head = newNode.
Step 4: If it is Not Empty then,
set newNode→next = head and head = newNode.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Insertion at specific position


create newnode
newnode ->data=data;
temp=head
if(position==1)
newnode->next=head
head=newnode;

else
position--
while(position)
prev=temp;
temp=temp->next;
position=position-1
prev->next=newnode;
newnode->next=temp;

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

DELETION
• In order to delete FIRST node from linked list we have to
consider three possibilities:
(1) List is Empty (START = NULL). In this case we can not delete node
from linked list.
(2) There is only one node in the linked list
• (START->LINK=NULL). In this case we can delete the first node and
then linked list becomes empty (START=NULL).
(3) There are more then one nodes in the linked list. In this case we
can delete the first node. After deleting the first node we have to move
FIRST pointer to next node so that it can points to the newly first node
in the linked list.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

ALGO TO DELETE FIRST NODE


• Step 1: If START = NULL then
Write “Linked List is Empty”
Step 2: If ( START->NEXT = NULL) then

START=NULL
Else
TEMP=START

START=START->NEXT
FREE TEMP
Step 3: Exit

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Algorithm to delete a node from last


• In order to delete LAST node from linked list we have to consider three
possibilities:
(1) List is Empty (START = NULL). In this case we can not delete node
from linked list.
(2) There is only one node in the linked list
• (START->LINK=NULL). In this case we can delete the node and then
linked list becomes empty (START=NULL).
(3) There are more then one nodes in the linked list. In this case we
have to traverse from first node to last node and then delete the last
node. After deleting the last node we have to set NULL value in the
LINK part of the previous node.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)
ALGORITHM

• 1: If START = NULL then


2: Write “Linked List is Empty”
3: If START->NEXT = NULL then perform 4 and 5 steps
4:
5: START=NULL
6: Else perform 7 to 12
7: TEMP=START
8: Repeat while (TEMP->NEXT ≠ NULL) repeat 9 and 10
9: PRED=TEMP
10: TEMP=TEMP->NEXT
11: free(TEMP)
12: PRED->NEXT=NULL
13: Exit

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Algorithm if deletion to be done by searching data

if(head== NULL)
Empty Linked List. Deletion not possible
else
Enter the data of the node to be deleted in key
temp = head
while (temp->next != NULL) && (temp->data != key)
ptr1 = temp
temp = temp->next
if(temp->data == key)
ptr1->next = temp->next;
free(temp);
else
Value not found. Deletion not possible.\n", key

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Merging of link list


• Node *merge(Node *h1, Node *h2)
• {
• if (!h1)
• return h2;
• if (!h2)
• return h1;

• // start with the linked list
• // whose head data is the least
• if (h1->data < h2->data)
• {
• h1->next = merge(h1->next, h2);
• return h1;
• }
• else
• {
• h2->next = merge(h1, h2->next);
• return h2;
• }
• }

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Reverse of link list


• void recursiveReverse(struct Node** head_ref)
• {
• struct Node* first;
• struct Node* rest;
• if (*head_ref == NULL)
• return;
• first = *head_ref;
• rest = first->next;
• if (rest == NULL)
• return;
• recursiveReverse(&rest);
• first->next->next = first;
• first->next = NULL;
• *head_ref = rest;
• }

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

FAQ
1. What is the complexity of search operation in linked list?
2. How linked list is better than array?
3. In what cases link lists give worst results?

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

REFERENCES
• https://www.cs.cmu.edu/~adamchik/15-
121/lectures/Linked%20Lists/linked%20lists.html
• https://www.geeksforgeeks.org/data-structures/linked-list/
• https://www.tutorialspoint.com/data_structures_algorithms/lin
ked_list_algorithms.htm
• https://www.geeksforgeeks.org/merge-two-sorted-lists-place/
• https://www.geeksforgeeks.org/reverse-a-linked-list/

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Books Recommended
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series,
Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures
using C and C++”, Prentice Hall of India.
• Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data
Structures and Algorithms”, Addison Wesley.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Queries??

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Advanced Topics

• Graphs
• Hash Tables
• Linked list of states
• Polynomial operation
• Dynamic memory allocation

University Institute of Engineering (UIE)

Вам также может понравиться