5/4/2015 3:58 PM1. 2 Allen NewellCliff ShawHerbert Simon We Owe To These.

Post on 16-Dec-2015

214 views 1 download

Tags:

transcript

04/18/23 13:47 1

04/18/23 13:47 2

Allen Newell Cliff Shaw Herbert Simon

We Owe To These

04/18/23 13:47 3

Linked lists were developed in 1955-56 by Allen Newell, Cliff Shaw and Herbert Simon at RAND Corporation as the primary data structure for their Information Processing Language. IPL was used by the authors to develop several early artificial intelligence programs, including the Logic Theory Machine, the General Problem Solver, and a computer chess program. Reports on their work appeared in IRE Transactions on Information Theory in 1956, and several conference proceedings from 1957-1959, including Proceedings of the Western Joint Computer Conference in 1957 and 1958, and Information Processing (Proceedings of the first UNESCO International Conference on Information Processing) in 1959. The now-classic diagram consisting of blocks representing list nodes with arrows pointing to successive list nodes appears in "Programming the Logic Theory Machine" by Newell and Shaw in Proc. WJCC, February 1957. Newell and Simon were recognized with the ACM Turing Award in 1975 for having "made basic contributions to artificial intelligence, the psychology of human cognition, and list processing".

History

LINK LIST• Introduction .• Why we use Linked List ?• Overview of various Link Lists .• Implementation of Link List .• Operations . • Advantage and Disadvantages .• Applications .

04/18/23 13:47 4

IntroductionList : The term “List” refers to linear collection of data

items.Following figure shows a simple list of data items :

Linked List : Linked list is a linear data structure. Linked list are special list of some data elements linked to one another. The logical addressing is represented by having each element pointing to the next element. Each element is called a node which has two parts.

(i) Info i.e. information part(ii) Next i.e. the Address part

Milk

Eggs

Butter

Tomato

Apple

Orange

04/18/23 13:47 5

04/18/23 13:47 6

This stores the dataOf the user .

This stores the address of next node .

Information Next

Some Key Points :

1.NULL Pointer: The link field of the last node of the linked list contains

NULL rather than a valid address. It is a NULL pointer and indicates the end of the list.

2.External Pointer : It is a pointer to the very first node in the

linked list, it enables us to access the entire linked list.

04/18/23 13:47 7

04/18/23 13:47 8

3.Empty List :3.Empty List : If the nodes are not If the nodes are not present present in a linked list, then it is in a linked list, then it is called an empty linked list or simply called an empty linked list or simply emptyempty list. It list. It is also called the Null list.is also called the Null list.

The value of the external pointer will be The value of the external pointer will be zero for an empty link list. A linked list can be zero for an empty link list. A linked list can be made an empty linked list by assigning a NULL made an empty linked list by assigning a NULL value to the external pointer .That is for example value to the external pointer .That is for example

start=NULL;start=NULL;

Representation of a Node in a Linked list :

Struct node{ int a;

struct node* next;}typedef struct node Node;Node *start;

04/18/23 13:47 9

Why We Need Linked List Suppose we have a memory in fragmented form

i.e. although there is space is availabeIn the memory but It is not contigious, and we

have to allocate maximum of the memory. For example : Suppose if we have memory

of 256KB in fragmented form i.e. not conigious, and we have to store 10 records in which each of the record contain Name, Address, and Course of the Student.

04/18/23 13:47 10

04/18/23 13:47 11

128 K B

64 K B

32 K B

32 K B 0

256

Then we can use the Linked List to store these records with the help of Dynamic Memory Allocation schem.

DMA can be implemented by : Malloc()Calloc()Realloc()Free()

04/18/23 13:47 12

Overview Of various Link Lists

Singly Linked List

Doubly Linked List

Circular Linked List

Circular Doubly Linked List

04/18/23 13:47 13

1. Singly Linked List : Singly linked list is one in which all

nodes are linked together in some sequential manner. Hence, it is also called Linear Linked List. Clearly it has beginning and the end. The problem with this list is that we can not access the predecessor of nodes from the current node. i.e. we can not traverse back in this list. This problem can be overcome by using Doubly Linked List.

04/18/23 13:47 14

NStart

2. Doubly Linked List : Doubly Linked List is one in which all

nodes are linked together by multiple links which help in accessing both the successor node (next node) and predecessor node (previous node) for any arbitrary node in the list, that is we can traverse both the direction in the linked list.

04/18/23 13:47 15

N NStart

3. Circular Linked List : Circular linked list is one which has no

beginning and no end. A singly linked list can be made a circular linked list by simply attach the address of very first node in the link field of the last node.

04/18/23 13:47 16

Start

4. Circular Doubly Linked List : is one which has

both the successor pointer and predecessor pointer in circular manner. It is shown in the following figure :

04/18/23 13:47 17

N Start

Link List Operations

• Creation• Insertion• Deletion• Traversing• Searching• Concatenation• Display

04/18/23 13:47 18

First we are performed the operations on Singly Linked List

Creation of LinkList : Algorithm :Step 1. Create nodeStep 2. if node is NULL then memory can not

be allocated to the node. Step 3. else

if start is NULLthen start=node;

04/18/23 13:47 19

elseptr=start;while ptr->next is not equal to

NULLptr=ptr->next;

ptr->next=node;Step 4. Exit.

04/18/23 13:47 20

Insertion of node at the beginning

Algorithm :Step1. StartStep2. get node from the memoryStep3. Check overflow

if node is NULL then memory can not be allocated to the node.exit;

04/18/23 13:47 21

elsenode->info=item;node->next=start;start =node;

Step5. Exit

04/18/23 13:47 22

Insertion at the end of the Linked List :

Algorithm :Step1.StartStep2.Get node from the memory.Step3.Check Overflow

if node =NULL then overflowexit;

04/18/23 13:47 23

Else if start =NULL then start=node;

elsep=start;

while p->next is not equal to NULLp=p->next

p->next=item;Step 4. Exit04/18/23 13:47 24

Deletion a node from Linked List

Algorithm :

Step1. StartStep 2. Check Underflow

if start =NULL then underflow

Step3. else

04/18/23 13:47 25

if start->info=itemstart=start->nextelse

p=q=start;while p->next not equal to

NULL if p->next->info=itemdelitem=p->next->infop->next=p->next->next;

Step4. Exit.

04/18/23 13:47 26

Implementation

Linked List as a Stack

Linked List as a Queue

04/18/23 13:47 27

Doubly Link ListSo far we have studied singly link list .One of the most striking disadvantages of it is that the inability to traverse the list in the backward direction .In most of real world applications it is necessary to traverse the list in both the direction .The most appropriate data structure for such an application is a DOUBLY LINK LIST . A doubly link list is one in which all nodes are linked together by multiple number of links which help in accessing both the successor node and predecessor node .It provides bi-directional traversing .

Each node in doubly link list has two link fields . These are used to point to the successor and

predecessor nodes. It can be illustrated by the following figure :

04/18/23 13:47 29

prev Data next

The LEFT link points to the predecessor node and RIGHT link points to the successor node .

Inserting node at beginning

• Allocate memory for the new node .• Assign value to the data field of the node .• Assign LEFT and RIGHT links to NULL .• Make the RIGHT link of the new node to point

to the head node of list and make left link of head node to point to new node .

• Finally reset the head pointer .That is make it to point to new node which has inserter at the beginning .

04/18/23 13:47 30

Inserting node at the end

• Allocate memory for the new node .• Assign values to the data field of the new

node .• If the list is not empty then traverse the list till

the last and make the RIGHT link of the last node to point the new node and LEFT link of the new node to point the last node.

04/18/23 13:47 31

Deleting node from beginning

• If the list is empty then display the message “Empty list-No deletion” .

• Otherwise make the head pointer to point to the second node and if the second node is not null then make its LEFT link to point to NULL .

• Free the first node .

04/18/23 13:47 32

Deleting node from the end

• If the list is empty then display the message “Empty list-No deletion” .

• Otherwise traverse the list till the last but one node and make the Right link of the last but one node to point to NULL .

• Free the last node .

04/18/23 13:47 33

Circular Link List

It is just a singly link list in which the link field of the last node contains the address of first node of the list .That is the link field of the last node does not point to NULL rather it points back to the beginning of the link list .

A circular link list has no end.Therefore it is necessary to establish the FIRST and LAST nodes in such a link list .It is useful if we set the external pointer to point the last node .From this conversion we can easily locate the FIRST node of the list .

Inserting node at beginning

• Allocate memory for new node .• Assign values to its data field .• Make the link part of new node point to the

head node .• Finally reset the head pointer. That is make it

to point to the inserted node .

04/18/23 13:47 35

Inserting node at the end

• Allocate memory for the new node .• Assign values to the data field of the node .• If the list is not empty then traverse the list till

the last and make the link of the last node to point the new node and link of new node should point to the head node .

04/18/23 13:47 36

Deleting node from beginning

• If the list is empty then display the message Empty list-No deletion .

• Otherwise make the head pointer to point to second node .

• Free the first node .

04/18/23 13:47 37

Deleting node from the end

• If the list is empty then display the message Empty list-No deletion .

• Otherwise traverse the list till the last but one node and make the link to point to head node .

• Free the last node .

04/18/23 13:47 38

Operations . . .

• Traversing• Searching• Concatenation• Display

04/18/23 13:47 39

Advantages

• Dynamic data structures .

• Efficient memory utilization .

• Easier and efficient insertion , deletion .

• Use in complex applications .

04/18/23 13:47 40

Disadvantages

• More memory required .

• Cumbersome data access .

04/18/23 13:47 41

Applications

• Polynomial operations .

• Dynamic programming .

• Base of other data structures .

04/18/23 13:47 42

Applications

O.S maintain a link list of free and used memory

To solve complex applications

04/18/23 13:47 43

04/18/23 13:47 44

datadata

data

data

data

data

data data data

data data

datadata

data data

data

data

data

datadata

data

data

data

data

data

data

data

data