Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

UNIVERSAL PUBLIC SCHOOL

Class XII Subject – Computer Science

LINKED LISTS, STACKS & QUEUES

Linked List is a linear collection of data elements, called nodes pointing to the next nodes by means
of pointers.

Advantages : They overcome the drawbacks of arrays as in linked lists number of elements need not
be predetermined, more memory can be allocated or released during the processing as and when
required, making insertions and deletions much easier and simple.

Avail List : It is a special list which is maintained in the memory consisting of used memory cells from
the heap. The allocation of memory from this list follows the LIFO or last in first out order. Any
memory released with the delete operator is added as a node to the AVAIL list and allocation of new
memory using the new operator results in deletion of a node from the Avail list.

The method of adding free nodes to the avail list is called garbage collection.

Memory Overflow : If no memory is available in heap and the program tries to allocate memory
dynamically using the new operator it is called “memory overflow”

Memory Underflow : If no memory is has been allocated in heap and the program tries to deallocate
memory dynamically using the delete operator it is called “memory underflow”

Singly linked lists : Basic Operations

• Creating / Addition
• Traversal
• Insertion – in sorted / Unsorted List
 At the beginning
 In the middle
 At the end
• Deletion
 At the beginning
 In the middle
 At the end
• Modification
• Searching
• Concatenation of two linked lists
• Splitting of a linked list into two.
• Reversal of a linked list

Stacks : It is a LIFO structure ( Last in First out) i.e. the last element to be inserted is the first to
come out. Stacks can physically be implemented as an array or a linked list. Insertions and deletions
in a stack are both made at the top. Insertion of an element is known as Pushing and deletion is
known as Popping

• Stack as an array
• Stack as a linked list
• Application of Stacks
 Reversing a string
 Polish Strings

Infix Notation Prefix Notation Postfix Notation

UNIVERSAL PUBLIC SCHOOL, A-Block, Preet Vihar, Delhi – 110 092.


A+B + AB AB +
(A – C) * B * - ACB AC – B *
A + (B * C) + A * BC ABC * +

 Conversion of infix expression to Postfix expression


 C++ implementation of infix to postfix conversion showing stack status.
 Advantage of Postfix over Infix Expression : In an infix expression it is difficult for the
machine to know and keep a track of the precedence of operators, whereas in a
postfix expression the precedence of operators is self determined thereby making it
easier to carry out the evaluation of a postfix expression.
 Evaluation of a Postfix Expression

Queue : It is a FIFO structure ( First in First out) i.e. the first element to be inserted is the first to come
out. Queues can physically be implemented as an array or a linked list. Insertions take place at the
end (rear) and deletions in a queue are made in the beginning (front) or at the start.

• Queue as an array
• Queue as a linked list
• Types of Queues
 Circular Queues : are queues implemented in a circular form rather than a linear
form. They overcome the problem of unutilised space in linear queues implemented as
arrays.
 Deque : (double ended queue) are refined queue in which the elements can be added
or removed at either end but not in the middle.
 Input restricted deque : allows insertions at only one end but allows deletions at
both ends of the list.
 Output restricted deque : allows deletions at only one end but allows insertions
at both ends of the list.

Assignment

 Practical exercises for all the operations on the linked lists would be done.
 Questions will be done and discussed from the back of the book.

1. Differentiate between Stacks and Queues


2. Explain the following terms
a) Avail List
b) Garbage collection
c) Memory Overflow
d) Deque
e) Free Store Memory
3. What are the advantages of linked lists over arrays ?
4. What is the advantage of implementing arrays as circular queue rather than linear queue ?

UNIVERSAL PUBLIC SCHOOL, A-Block, Preet Vihar, Delhi – 110 092.


UNIVERSAL PUBLIC SCHOOL, A-Block, Preet Vihar, Delhi – 110 092.
UNIVERSAL PUBLIC SCHOOL
Class XII Subject – Computer Science

POINTERS

ASSIGNMENT

Assignment & Discussions

1. Differentiate between:
a) Static & Dynamic memory allocation
b) Pointer to an int and pointer to a char
c) Array of pointers and a pointer to an array
d) A pointer to a const and a const pointer
e) int *ptr=new int(5) and int *ptr = new int[5]

2. Write short notes on


a) Memory Leaks and the possible reasons for memory leaks
b) Self referential structures
c) new and the delete operator
d) The this pointer
e) Pointer Arithmetic

3. Why is it faster to use element pointer rather than an index when scanning arrays?
4. Why is an array of characters preferred over two dimensional array of characters ?

Questions given at the back of the chapter would be discussed and given as assigment.

Books referred : Computer Science by Sumita Arora


Together with by Reeta Sahoo

UNIVERSAL PUBLIC SCHOOL, A-Block, Preet Vihar, Delhi – 110 092.

You might also like