You are on page 1of 14

Lecture LinkedList

By: Saeed Ahmed


Singly Linked List Data Structure
Singly Linked list is a type of Linked List Data structure which behaves like a one way
list/chain. The reason it is called a one way list or one way chain is because we can only
traverse this list in one direction, start from the head node to the end.
Singly Linked List Data Structure:

Each node object has 1 data field & 1 pointer field. The data field contains the actual data
where as the pointer field(next pointer) points to the next node in the singly linked list. Since
the nodes are not stored in contiguous memory locations, this extra pointer field assists in
locating the next node in memory. As we have only one pointer pointing to the next node, we
can only traverse in one direction starting from the head node to the end.
Singly Linked List Data Structure
Following are the standard Singly Linked List Operations –
Traverse – Iterate through the nodes in the linked list starting from the head node.
Append – Attach a new node (to the end) of a list
Prepend – Attach a new node (to the beginning) of the list
Insert – attach a new node to a specific position on the list
Delete – Remove/Delink a node from the list
Count – Returns the no of nodes in linked list
Update – Update the existing node in linked list
Doubly Linked List Data Structure
Doubly Linked list is a type of Linked List Data structure which behaves like a two way
list/chain. The reason it is called a two way list or two way chain is because we can traverse
this list in two directions –

• start from the head node to the end.


• go back in the reverse direction.

#805- Node 0
#101 100 #706
Prev ptr Data Next ptr #805 #805
Doubly Linked List Data Structure
Each node object has 1 data field & 2 pointer fields. The data field contains the actual data
where as the pointer fields(next & previous pointers) points to the next node & previous node
in the doubly linked list. Since the nodes are not stored in contiguous memory locations, these
extra pointer fields assists in locating the next & previous nodes in memory. As we have 2
pointers: one pointing to the next node and one pointing to the previous node, we can traverse
in 2 directions starting from the head node to the end and vice versa.
Doubly Linked List Data Structure
Following are the standard Singly Linked List Operations –

 Traverse – Iterate through the nodes in the linked list starting from the head node.
 Append – Attach a new node (to the end) of a list
 Prepend – Attach a new node (to the beginning) of the list
 Insert – attach a new node to a specific position on the list
 Delete – Remove/Delink a node from the list
 Count – Returns the no of nodes in linked list
 Update - Change existing value of node.
Circular Linked List Data Structure
Circular linked list is a type of Linked List Data structure which behaves like a one way
list/chain. The reason it is called a one way list or one way chain is because we can only
traverse this list in one direction, start from the head node to the end. However unlike Singly
Linked List in this type of linked list we can traverse from the last node to the first in a
circular one directional pattern.
Circular Linked List Data Structure

each node object has 1 data field & 1 pointer field. The data field contains the actual data
where as the pointer field(next pointer) points to the next node in the singly linked list. Since
the nodes are not stored in contiguous memory locations, this extra pointer field assists in
locating the next node in memory. As we have only one pointer pointing to the next node, we
can only traverse in one direction starting from the head node to the end. However unlike
singly linked list, the last node in this circular linked list is storing address of the first head
node. Thus you can traverse back from the last node to the first node.
Circular Linked List Data Structure
Following are the standard Circular Linked List Operations –

 Traverse – Iterate through the nodes in the linked list starting from the head node.
 Append – Attach a new node (to the end) of a list
 Prepend – Attach a new node (to the beginning) of the list
 Insert – attach a new node to a specific position on the list
 Delete – Remove/Delink a node from the list
 Count – Returns the no of nodes in linked list
 Update – Update the node
What is Prefix, Infix & Postfix Expressions
What is an Expression?

An Expression is a combination of symbols that can be numbers (constants), variables,


operations, symbols of grouping and other punctuation written is a specific format/way.
What is Prefix, Infix & Postfix Expressions
Depending on how the expression is written, we can classify it into 3 categories –

Prefix –
An expression is called the prefix expression if the operator appears in the expression
before the operands. Simply of the form (operator operand1 operand2). E.g. +AB

Infix –
An expression is called the infix expression if the operator appears in the expression in
between the operands. Simply of the form (operand1 operator operand2). E.g. A+B

Postfix –
An expression is called the postfix expression if the operator appears in the expression
after the operands. Simply of the form (operand1 operand2 operator). E.g. AB+
What is Prefix, Infix & Postfix Expressions
Order of Operations(Operator Precedence) –

1) Parentheses – {}, [], ()


2) Exponents(Right to Left) – A^B, 2^3^4
3) Multiplication & Division(Left to Right) – A*B/C
4) Addition & Subtraction(Left to Right) – A + B – C

Associativity –

Associativity describes the rule where operators with the same precedence appear in an
expression. For example, in expression a + b − c, both + and – have the same precedence,
then which part of the expression will be evaluated first, is determined by associativity of
those operators.
What is Prefix, Infix & Postfix Expressions
Why do we need 3 different expressions ?

• Infix expressions are human readable but not efficient for machine reading

• Prefix and Postfix do not need the concept of precedence & associativity hence it
becomes highly efficient to parse expressions in prefix or postfix formats.

You might also like