0% found this document useful (0 votes)
51 views27 pages

Institute:Chandigarh Universuity Department: Uic

The document discusses the data structure of a stack. A stack is a linear data structure that follows the LIFO (Last In First Out) principle. Elements can only be added or removed from one end, called the top. Common stack operations are push to add an element and pop to remove the top element. The document provides pseudocode for implementing these operations using an array to represent the stack. It first checks for empty or full conditions before pushing or popping.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views27 pages

Institute:Chandigarh Universuity Department: Uic

The document discusses the data structure of a stack. A stack is a linear data structure that follows the LIFO (Last In First Out) principle. Elements can only be added or removed from one end, called the top. Common stack operations are push to add an element and pop to remove the top element. The document provides pseudocode for implementing these operations using an array to represent the stack. It first checks for empty or full conditions before pushing or popping.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

INSTITUTE:CHANDIGARH UNIVERSUITY

DEPARTMENT: UIC
Bachelor of Computer Application
Subject Name: Data Structure
Code:CAT-201

Stack and Linked List DISCOVER . LEARN . EMPOWER


Font size 24
SCHEME

Bachelor of Computer Applications Semester – III (2018-21) 


Subject Code Title L T P S Credits
CAT-201 Data Structures 3 0 0 - 3
CAT-202 Database Management System 3 0 0 - 3

CAT-208 Probability & Statistics 3 1 0 - 4


CAT-209 System Software & Operating System 3 0 0 - 3
UCT-249 Introduction to Artificial Intelligence 1 0 0 - 1
TDP-205 Soft Skills 0 0 1 - 1
CAP-206 Data Structures Lab 0 0 4 - 2
CAP-207 Database Management System Lab 0 0 4 - 2

CAY-211 Summer Training/Institutional Training 0 0 0 - 3*


UCY-241 Social and Professional Ethics 2 0 0 - 2*
UCY- 247 Gender Equality and Woman 2 0 0 - 2*
Empowerment
Total 19

2
SYLLABUS
DATA STRUCTURES L T P C
Total Contact Hours:45
CAT- 201 Applicable to which 3 0 0 3
branch: BCA
Prerequisite: Knowledge of Programming in C
Marks
Internal: 40 External: 60
Course Objective
 To learn the systematic way of solving problems.
 To introduce various techniques for representation of the data in the real world
 To efficiently implement solutions for specific problems.
Unit Course Outcome
Student will be able to apply appropriate constructs of Programming language, coding standards for application
1.
development
2. Students will learn to Select and use appropriate data structures for problem solving and programming.
To implement Trees, Graphs and Select appropriate searching and/or sorting techniques for application development
3.
 

3
SYLLABUS
Unit-I
Introduction: Pointers and Dynamic memory allocation, Types of data structures, Mathematical
notation and functions.
Algorithm Analysis: Space Complexity, Time Complexity, Asymptotic Notation and Algorithmic
complexity. Abstract Data Type.
Arrays & Structure: Linear Search, Binary Search (Recursive & iterative, Evaluation of
Polynomial, Polynomial representation, Polynomial Addition).
Structures: Internal representation of structure, Self –referential structure 

4
SYLLABUS
Unit-II
Stack: Memory Representation of Stacks via arrays and Linked List, Stack Operations, Application
of Stack.
Evaluation of Expression: Evaluation of postfix expression, Infix to postfix and prefix forms for
expressions.
Queue: Representation using array and linked List, Queue Operations, Types of queues,
Applications of queue.
Linked List: Representation of linked list, linked list operations (Create, Insertion, Printing,
Deleting and Traversing), Circular Linked List, Double linked list.

5
SYLLABUS
Unit-III
Trees: Definition, Terminology, Representation, Binary tree: Representation and its types, Traversal
(In-order, Pre-order, Post-order). Binary Search Tree, Heap, AVL/Height Balanced Tree
Graphs: Representation of Graphs, Adjacency Matrix and List, In degree, out degree of graph.
Graph operation: Depth First Search and Breath First Search.
Sorting: Bubble sort, Selection sort, Insertion sort, Quick Sort and Merge Sort

6
• Stack representation
Stack and • Insertion into stack

Linked List • Deletion from stack


• Linked- list representation
Course Outcome
• Insertion into linked-list
CO Title Level
Number • Deletion from linked list
CO1 Explain the algorithm and it’s terms related to Understand
array
CO2 Explain the basic concepts of searching Understand

CO3 Explain the different types of Linear Data Understand


structure
CO4 Explain the stack data structure Understand

CO5 Analyse the algorithms Understand


7
STACK
• Stack is an Abstract Data Type (ADT). It is used in many programming languages. It works like a
real world stack so its name is stack. Example – a deck of cards or a pile of plates etc.

• In a real-world stack, operations are allowed at one end only. For example, we can put or remove a
plate or card only from the top of the stack. Stack also allows all data operations from one end
only. At a particular time, we can access only the top most element of a stack.

8
STACK
A stack implementation can be done by any of the Array, Structure, Pointer or Linked List. Stack can
be of fixed size or it can be of dynamic size. Here, below is given how to implement stack using
arrays, that means it is a fixed size implementation of satck.

Fig 1 stack operations


Reference: https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm

9
STACK OPERATION
Stack operations are initialization of stack, use of stack and then de-initialization of it. Apart from
these operations, a stack is used for the following operations −
• push() − Pushing or storing an element on stack.
• pop() − Removing or accessing an element from stack.

Before using a stack firstly we need to check the status of that stack .To check the status there
are following operations:
• peek() − It will get the top data element of the stack, without removing it.
• isFull() − It will check if stack is full or not.
• isEmpty() − It will check if stack is empty or not.

10
STACK(INSERTION)
Push Operation
• The process of inserting or putting a new data element onto stack is known as a Push Operation.
There are following operations to perform push operation−
• Step 1 − We need to check if the stack is full or not.
• Step 2 − If the stack is full, it will produces an error and exit.
• Step 3 − If the stack is not full, it increments top to point next empty space of stack.
• Step 4 −Then adds data element to the top of the stack.
• Step 5 − Returns success

11
STACK(DELETION)
To remove the top most element from the stack, is called as Pop Operation. During an array
implementation of the pop() operation, the top most data element is not removed, instead top is
decremented to the next lower position in the stack to point to the next element.
• A Pop operation includes the following steps −
• Step 1 − It will checks if the stack is empty or not.
• Step 2 − If the stack is empty, then it produces an error and exit.
• Step 3 − If the stack is not empty, then it accesses the data element
• at which top is pointing.
• Step 4 − Then decreases the value of top by 1.
• Step 5 − Returns success.
Reference:https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm

12
STACK PUSH PROCDURE

• begin procedure push: stack, data


• if stack is full
• return null
• endif
• top ← top + 1
• stack[top] ← data
• end procedure

13
STACK POP PROCEDURE
• begin procedure POP: stack, data
• if stack is EMPTY
• return null
• endif
• DATA ← stack[top]
• TOP← TOP-1
• RETURN DATA
• end procedure

14
Linked list
• A linked list is a collection of nodes in data structure, which are connected through links.
• Linked List is a collection of nodes and sequence of links which contains items. Every link is
connected to another link. Linked list is the second most-used data structure after array. Following
are the important terms of Linked List.

• Link − Each node of a linked list can store a value called an element.

• Next − Each node of a linked list contains a link to the next node called Next.

• Linked List − A Linked List has the connection link to the first node called First.

15
Linked list
A Linked list can be considered as a sequence of nodes, where each node points to the next node.
• Here are the some important points to be considered.
• Linked List is having a link element called Head.
• Each node is having two parts, one is a data field(s) and another is pointer field called next which
contains the address of next node.
• Each node is linked to its next node using its next link.
• Last link has a link as null to show the end of the list.

Fig 4 linked list representation


Reference: https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm

16
Linked list Types

Following are the some types of linked list.


• Simple Linked List − In this type of list , Item navigation is forward only.

• Doubly Linked List − In this type, Item navigation is forward and backward.

• Circular Linked List − In circular link list, Last item contains address of the first element in next
and the first element contains the address of the last element as previous field.

17
Linked list Operation
Following are some basic operations of a link list.
• Insertion − It adds an element at the beginning of the list.
• Deletion − It deletes an element at the end of the list.
• Display − It displays the complete list.
• Search − It searches an element with the help of given key.
• Delete − It deletes an element with the help of given key

18
Linked list(Insertion)

• To add a new node in linked list more than one steps are included. We scan go with diagrams
here. Create a node with the node structure and search the location to be inserted.

Fig 5 insertion into linked list

Reference: https://www.tutorialspoint.com/data_structures_algorithms/graph_data_structure.htm

19
Linked list(Insertion)

Fig 6 insertion into linked list


Reference: https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm

20
Linked list(deletion)
Deletion is also a multi-step process. We can through this pictorial representation. Search the target
node which is to be removed, by using various searching algorithms.

The left (previous) node of the removed node now should point to the next node of the removed
node −

Fig 7 deletion from linked list

Reference:
https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm
21
Linked list(deletion)

Fig 8 deletion from linked list

Reference:
https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm
22
Doubly Linked list
As per the above description, here are some important points to be considered.
•Doubly Linked List contains a link element called first node and last node.
•Each node is having a data field(s) and two pointer fields called next and prev.
•Each node is linked with its next node using its next pointer.
•Each node is linked with its previous node using its previous pointer.
•The last node carries a field as null to mark the end of the list.

Fig 9 doubly linked list

Reference:
https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm
23
Circular Linked list
• Circular Linked List is another type of Linked list in which the first node points to the last element
and the last node points to the first element. Both Singly Linked List and Doubly Linked List can
be made in circular linked list
• In singly circular linked list, the next pointer of the last node points to the first node.

Fig 9 doubly linked list


Fig 10 circular linked list

Reference:
https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm
24
STACK & LINKED LIST
APPLICATIONS
• Stack is used for parenthesis checking. Stack is used to reverse a string. We push the characters of
string one by one into stack and then pop character from top of the stack. Stack is used to keep
information about the active functions or subroutines.
• Linked Lists can be used to implement Stacks , Queues.
• Linked Lists can also be used to implement Graphs. ...
• Implementing Hash Tables :- Each Bucket of the hash table can itself be a linked list.

25
REFERENCES
Reference Books:
• Seymour Lipschutz, Schaum's Outlines Series Data structures TMH
• Introduction to Data Structures Applications, Trembley&Soreson, Second Edition, Pearson
Education

Reference websites:
• https://www.tutorialspoint.com/data_structures_algorithms

26
THANK YOU

For queries
Email:

You might also like