This document provides information about the vision, mission, and course outcomes of the Data Structures and Algorithms department at JECRC Engineering College.
The vision of the department is to become a renowned center of excellence in computer science and engineering and produce competent engineers with strong ethical values prepared for lifelong learning. The mission includes imparting outcome-based education on emerging technologies, providing opportunities for academia-industry interaction, and developing social responsibilities.
The course aims to teach students how to apply data structure concepts, implement searching and sorting algorithms, choose appropriate data structures, and analyze algorithm time complexity. Topics to be covered include stacks, queues, trees, graphs, and recursion.
The document provides information about stacks and their implementation and applications. It discusses representing stacks using static and dynamic arrays. It describes basic stack operations like push, pop, peek, isEmpty and size. It discusses multiple stack implementation using a single array and provides pseudocode. It also discusses applications of stacks like reversing a list, calculating factorials recursively, infix to postfix conversion, evaluating arithmetic expressions and the Towers of Hanoi problem.
1. The document discusses stacks and queues as linear data structures. It describes stack operations like push and pop and provides algorithms for implementing these operations.
2. An example program for implementing a stack using an array is presented, with functions defined for push, pop, and display operations on the stack.
3. Applications of stacks discussed include reversing a list or string by pushing characters onto a stack and popping them off in reverse order, and converting infix expressions to postfix using a stack.
The document discusses data structures and algorithms including stacks, queues, and their implementations using arrays and linked lists. Key points:
1. Stacks follow LIFO principle and allow insertion/removal at one end only. Queues follow FIFO principle. Both can be implemented using arrays or linked lists.
2. Common stack operations like push, pop, and peek have O(1) time complexity. Queue operations like enqueue and dequeue also have O(1) time complexity.
3. Linked list implementations of stacks and queues allocate memory dynamically and don't have size limits like arrays.
4. A circular queue treats the last node as connected to the first, forming a ring. This allows insertion
A stack is a last-in, first-out data structure where elements can only be added (pushed) or removed (popped) from one end, called the top. Common applications include reversing words, implementing undo functions, backtracking in algorithms, and managing function calls and memory allocation using a call stack. Stacks are often implemented using arrays, where an index tracks the top element and elements are added or removed by changing the top index and relevant array values.
A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items take place at one end called the top of the stack.
Concept of stack ,stack of aaray stack by linked list , application of stac...muskankumari7360
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle, meaning the last element added to the stack is the first one to be removed. Elements can only be added or removed from the top of the stack. This structure resembles a stack of plates, where you can only add or remove plates from the top of the pile. Stacks are commonly used in computer science for tasks such as function call management, expression evaluation, and undo functionality in applications.
The document discusses the stack data structure. A stack is a collection of elements that follow the LIFO (last-in, first-out) principle. Elements can be inserted and removed from the top of the stack only. Stacks have common applications like undo functions in text editors and web browser history. Formally, a stack is an abstract data type that supports push, pop, top, is_empty and length operations. The document provides examples and explanations of stack operations and applications like infix to postfix conversion, expression evaluation, balancing symbols, function calls and reversing a string.
The document provides information about stacks and their implementation and applications. It discusses representing stacks using static and dynamic arrays. It describes basic stack operations like push, pop, peek, isEmpty and size. It discusses multiple stack implementation using a single array and provides pseudocode. It also discusses applications of stacks like reversing a list, calculating factorials recursively, infix to postfix conversion, evaluating arithmetic expressions and the Towers of Hanoi problem.
1. The document discusses stacks and queues as linear data structures. It describes stack operations like push and pop and provides algorithms for implementing these operations.
2. An example program for implementing a stack using an array is presented, with functions defined for push, pop, and display operations on the stack.
3. Applications of stacks discussed include reversing a list or string by pushing characters onto a stack and popping them off in reverse order, and converting infix expressions to postfix using a stack.
The document discusses data structures and algorithms including stacks, queues, and their implementations using arrays and linked lists. Key points:
1. Stacks follow LIFO principle and allow insertion/removal at one end only. Queues follow FIFO principle. Both can be implemented using arrays or linked lists.
2. Common stack operations like push, pop, and peek have O(1) time complexity. Queue operations like enqueue and dequeue also have O(1) time complexity.
3. Linked list implementations of stacks and queues allocate memory dynamically and don't have size limits like arrays.
4. A circular queue treats the last node as connected to the first, forming a ring. This allows insertion
A stack is a last-in, first-out data structure where elements can only be added (pushed) or removed (popped) from one end, called the top. Common applications include reversing words, implementing undo functions, backtracking in algorithms, and managing function calls and memory allocation using a call stack. Stacks are often implemented using arrays, where an index tracks the top element and elements are added or removed by changing the top index and relevant array values.
A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items take place at one end called the top of the stack.
Concept of stack ,stack of aaray stack by linked list , application of stac...muskankumari7360
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle, meaning the last element added to the stack is the first one to be removed. Elements can only be added or removed from the top of the stack. This structure resembles a stack of plates, where you can only add or remove plates from the top of the pile. Stacks are commonly used in computer science for tasks such as function call management, expression evaluation, and undo functionality in applications.
The document discusses the stack data structure. A stack is a collection of elements that follow the LIFO (last-in, first-out) principle. Elements can be inserted and removed from the top of the stack only. Stacks have common applications like undo functions in text editors and web browser history. Formally, a stack is an abstract data type that supports push, pop, top, is_empty and length operations. The document provides examples and explanations of stack operations and applications like infix to postfix conversion, expression evaluation, balancing symbols, function calls and reversing a string.
Stack and its Applications : Data Structures ADTSoumen Santra
Stacks are a data structure that follow the last-in, first-out (LIFO) principle. Elements are inserted and removed from the same end called the top of the stack. Common stack operations include push to add an element, pop to remove an element, peek to view the top element, and isEmpty to check if the stack is empty. Stacks have various applications like representing function call stacks, evaluating mathematical expressions, and solving puzzles like the Towers of Hanoi. They can be implemented using arrays or linked lists.
The document discusses stacks, which are a fundamental data structure used in programs. It defines a stack as a linear list of items where additions and deletions are restricted to one end, called the top. Common stack operations include push, which adds an element to the top, and pop, which removes an element from the top. Stacks have applications in parsing expressions, reversing strings, implementing depth-first search algorithms, and calculating arithmetic expressions in prefix and postfix notation. Stacks can be implemented using static arrays or dynamic arrays/linked lists.
The document discusses stacks, which are linear data structures that follow the LIFO (last-in, first-out) principle. A stack has two main operations - push, which adds an element to the top of the stack, and pop, which removes the top element. Some key applications of stacks include implementing undo/redo features, converting infix expressions to postfix notation, and solving recursive backtracking problems. The document also describes how to evaluate expressions in postfix notation using a stack. Elements are pushed onto the stack as they are encountered, and when an operator is reached, elements are popped off to perform the operation before pushing the result back on.
This document discusses stacks and queues as data structures. It begins by defining a stack as a linear collection where elements are added and removed from the top in a last-in, first-out (LIFO) manner. Common stack operations like push, pop, and peek are described. It then discusses applications of stacks like undo sequences and method calls. The document also defines queues as collections where elements are added to the rear and removed from the front in a first-in, first-out (FIFO) manner. Common queue operations and applications like waiting lists and printer access are also covered. Finally, it discusses implementations of stacks and queues using arrays and how to handle overflow and underflow cases.
The document discusses stacks and queues as data structures. It begins by providing an introduction to stacks, describing them as linear data structures that follow the LIFO (last in, first out) principle. It then discusses various stack operations like push, pop, and peep using both array-based and linked implementations. The document also covers topics like multiple stacks, infix/postfix/prefix notation, and algorithms for converting infix to postfix notation and evaluating postfix expressions.
The document discusses stacks and queues as data structures. It defines a stack as a linear data structure that follows the LIFO principle with insertion and deletion occurring at one end. Key stack operations are described as push, pop, peek, isEmpty and isFull. Queue is defined as a linear structure that follows the FIFO principle with insertion at the rear and deletion at the front. Common queue operations are enqueue, dequeue, peek, isEmpty and isFull. Array and linked list implementations of stacks and queues are also covered.
This document discusses stacks and queues as data structures. It defines a stack as a LIFO data structure where items can only be inserted and removed from one end. Examples of stack applications include program execution, parsing, and evaluating postfix expressions. The key stack operations are push, peek, and pop. It also defines a queue as a FIFO data structure where items are inserted at one end and removed from the other. Example queue applications include scheduling and networking. The key queue operations are enqueue and dequeue. It discusses implementing both stacks and queues using arrays and linked lists.
This document discusses stacks as a linear data structure. Stacks follow the LIFO (last-in, first-out) principle, where elements can only be added or removed from one end called the top. Stacks have operations like push, pop and peek. Push adds an element to the top, pop removes from the top, and peek returns the top element without removing it. Stacks can be implemented using arrays or linked lists. The document provides algorithms for push, pop and peek operations on both array-based and linked stacks. It also lists some applications of stacks like reversing lists, parentheses checking, expression conversions, recursion and Tower of Hanoi problem.
This document discusses stacks and queues as data structures. It begins by introducing stacks and their LIFO (last-in, first-out) operation. Common applications of stacks are then described, such as function calls, calculators, mazes, and undo functions. Static and dynamic stack implementations using arrays and linked lists are covered. The document then introduces queues and their FIFO (first-in, first-out) operation. Example applications of queues like print jobs and round robin scheduling are provided. Finally, the operations and implementations of queues are discussed at a high level.
This document discusses linear data structures, specifically stacks and queues. It defines a stack as a linear data structure that follows the LIFO principle and can be implemented using arrays or linked lists. Queue is defined as another linear data structure that follows the FIFO principle and supports enqueue and dequeue operations. Various queue implementations like array-based queues, linked list queues, circular queues, and priority queues are described along with their operations. Common applications of stacks and queues in areas like function calls, CPU scheduling, and page replacement algorithms are also mentioned.
The document discusses stacks and stack operations in C. It defines a stack as a linear data structure that follows the LIFO principle, where elements are added and removed from one end called the top. The key stack operations are PUSH to add an element, POP to remove an element, and DISPLAY to output the stack. It provides algorithms for implementing PUSH and POP and handling exceptions like stack overflow. The document also covers postfix notation, where operators follow operands, and the postfix evaluation algorithm using a stack.
A stack is a linear data structure that follows the LIFO (last in, first out) principle. Elements can only be inserted or removed from one end, called the top. Common stack operations include push, which adds an element, and pop, which removes the top element. Stacks have applications in expression evaluation, parenthesis matching, and undo operations. A queue follows the FIFO (first in, first out) principle, with elements being inserted at the rear and removed from the front. Common queue operations are enqueue and dequeue. Queues are used in scheduling, printing, and resource allocation.
The document discusses stacks and their implementation and applications. It describes stacks as linear data structures that follow the LIFO principle, and how they can be implemented using arrays. Key stack operations like push and pop are explained along with the concepts of overflow and underflow. Applications of stacks include evaluating postfix expressions, converting infix to postfix notation, and recursion. Algorithms for infix to postfix conversion and evaluating postfix expressions are provided with examples.
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
This document discusses stacks as a data structure. It defines a stack as a Last In First Out (LIFO) structure where the last item inserted is the first out. Key stack operations like push, pop, peek and isEmpty are described. Examples of stack applications include checking for balanced brackets, converting infix to postfix notation, implementing an undo/redo feature and recursion. The document also provides pseudocode for converting an infix expression to postfix using a stack and describes how a postfix calculator evaluates expressions.
This document discusses stacks and their implementation in Python. It begins with an introduction to stacks and their LIFO (last-in, first-out) principle. Key operations on a stack like PUSH and POP are explained. The document then presents an implementation of a stack in Python using a list and defines functions for common stack operations. It also discusses applications of stacks, conversion between infix and postfix notation using a stack, and evaluating postfix expressions.
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
Stack and its Applications : Data Structures ADTSoumen Santra
Stacks are a data structure that follow the last-in, first-out (LIFO) principle. Elements are inserted and removed from the same end called the top of the stack. Common stack operations include push to add an element, pop to remove an element, peek to view the top element, and isEmpty to check if the stack is empty. Stacks have various applications like representing function call stacks, evaluating mathematical expressions, and solving puzzles like the Towers of Hanoi. They can be implemented using arrays or linked lists.
The document discusses stacks, which are a fundamental data structure used in programs. It defines a stack as a linear list of items where additions and deletions are restricted to one end, called the top. Common stack operations include push, which adds an element to the top, and pop, which removes an element from the top. Stacks have applications in parsing expressions, reversing strings, implementing depth-first search algorithms, and calculating arithmetic expressions in prefix and postfix notation. Stacks can be implemented using static arrays or dynamic arrays/linked lists.
The document discusses stacks, which are linear data structures that follow the LIFO (last-in, first-out) principle. A stack has two main operations - push, which adds an element to the top of the stack, and pop, which removes the top element. Some key applications of stacks include implementing undo/redo features, converting infix expressions to postfix notation, and solving recursive backtracking problems. The document also describes how to evaluate expressions in postfix notation using a stack. Elements are pushed onto the stack as they are encountered, and when an operator is reached, elements are popped off to perform the operation before pushing the result back on.
This document discusses stacks and queues as data structures. It begins by defining a stack as a linear collection where elements are added and removed from the top in a last-in, first-out (LIFO) manner. Common stack operations like push, pop, and peek are described. It then discusses applications of stacks like undo sequences and method calls. The document also defines queues as collections where elements are added to the rear and removed from the front in a first-in, first-out (FIFO) manner. Common queue operations and applications like waiting lists and printer access are also covered. Finally, it discusses implementations of stacks and queues using arrays and how to handle overflow and underflow cases.
The document discusses stacks and queues as data structures. It begins by providing an introduction to stacks, describing them as linear data structures that follow the LIFO (last in, first out) principle. It then discusses various stack operations like push, pop, and peep using both array-based and linked implementations. The document also covers topics like multiple stacks, infix/postfix/prefix notation, and algorithms for converting infix to postfix notation and evaluating postfix expressions.
The document discusses stacks and queues as data structures. It defines a stack as a linear data structure that follows the LIFO principle with insertion and deletion occurring at one end. Key stack operations are described as push, pop, peek, isEmpty and isFull. Queue is defined as a linear structure that follows the FIFO principle with insertion at the rear and deletion at the front. Common queue operations are enqueue, dequeue, peek, isEmpty and isFull. Array and linked list implementations of stacks and queues are also covered.
This document discusses stacks and queues as data structures. It defines a stack as a LIFO data structure where items can only be inserted and removed from one end. Examples of stack applications include program execution, parsing, and evaluating postfix expressions. The key stack operations are push, peek, and pop. It also defines a queue as a FIFO data structure where items are inserted at one end and removed from the other. Example queue applications include scheduling and networking. The key queue operations are enqueue and dequeue. It discusses implementing both stacks and queues using arrays and linked lists.
This document discusses stacks as a linear data structure. Stacks follow the LIFO (last-in, first-out) principle, where elements can only be added or removed from one end called the top. Stacks have operations like push, pop and peek. Push adds an element to the top, pop removes from the top, and peek returns the top element without removing it. Stacks can be implemented using arrays or linked lists. The document provides algorithms for push, pop and peek operations on both array-based and linked stacks. It also lists some applications of stacks like reversing lists, parentheses checking, expression conversions, recursion and Tower of Hanoi problem.
This document discusses stacks and queues as data structures. It begins by introducing stacks and their LIFO (last-in, first-out) operation. Common applications of stacks are then described, such as function calls, calculators, mazes, and undo functions. Static and dynamic stack implementations using arrays and linked lists are covered. The document then introduces queues and their FIFO (first-in, first-out) operation. Example applications of queues like print jobs and round robin scheduling are provided. Finally, the operations and implementations of queues are discussed at a high level.
This document discusses linear data structures, specifically stacks and queues. It defines a stack as a linear data structure that follows the LIFO principle and can be implemented using arrays or linked lists. Queue is defined as another linear data structure that follows the FIFO principle and supports enqueue and dequeue operations. Various queue implementations like array-based queues, linked list queues, circular queues, and priority queues are described along with their operations. Common applications of stacks and queues in areas like function calls, CPU scheduling, and page replacement algorithms are also mentioned.
The document discusses stacks and stack operations in C. It defines a stack as a linear data structure that follows the LIFO principle, where elements are added and removed from one end called the top. The key stack operations are PUSH to add an element, POP to remove an element, and DISPLAY to output the stack. It provides algorithms for implementing PUSH and POP and handling exceptions like stack overflow. The document also covers postfix notation, where operators follow operands, and the postfix evaluation algorithm using a stack.
A stack is a linear data structure that follows the LIFO (last in, first out) principle. Elements can only be inserted or removed from one end, called the top. Common stack operations include push, which adds an element, and pop, which removes the top element. Stacks have applications in expression evaluation, parenthesis matching, and undo operations. A queue follows the FIFO (first in, first out) principle, with elements being inserted at the rear and removed from the front. Common queue operations are enqueue and dequeue. Queues are used in scheduling, printing, and resource allocation.
The document discusses stacks and their implementation and applications. It describes stacks as linear data structures that follow the LIFO principle, and how they can be implemented using arrays. Key stack operations like push and pop are explained along with the concepts of overflow and underflow. Applications of stacks include evaluating postfix expressions, converting infix to postfix notation, and recursion. Algorithms for infix to postfix conversion and evaluating postfix expressions are provided with examples.
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
This document discusses stacks as a data structure. It defines a stack as a Last In First Out (LIFO) structure where the last item inserted is the first out. Key stack operations like push, pop, peek and isEmpty are described. Examples of stack applications include checking for balanced brackets, converting infix to postfix notation, implementing an undo/redo feature and recursion. The document also provides pseudocode for converting an infix expression to postfix using a stack and describes how a postfix calculator evaluates expressions.
This document discusses stacks and their implementation in Python. It begins with an introduction to stacks and their LIFO (last-in, first-out) principle. Key operations on a stack like PUSH and POP are explained. The document then presents an implementation of a stack in Python using a list and defines functions for common stack operations. It also discusses applications of stacks, conversion between infix and postfix notation using a stack, and evaluating postfix expressions.
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
E-commerce Development Services- Hornet DynamicsHornet Dynamics
For any business hoping to succeed in the digital age, having a strong online presence is crucial. We offer Ecommerce Development Services that are customized according to your business requirements and client preferences, enabling you to create a dynamic, safe, and user-friendly online store.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
Microservice Teams - How the cloud changes the way we workSven Peters
A lot of technical challenges and complexity come with building a cloud-native and distributed architecture. The way we develop backend software has fundamentally changed in the last ten years. Managing a microservices architecture demands a lot of us to ensure observability and operational resiliency. But did you also change the way you run your development teams?
Sven will talk about Atlassian’s journey from a monolith to a multi-tenanted architecture and how it affected the way the engineering teams work. You will learn how we shifted to service ownership, moved to more autonomous teams (and its challenges), and established platform and enablement teams.
WhatsApp offers simple, reliable, and private messaging and calling services for free worldwide. With end-to-end encryption, your personal messages and calls are secure, ensuring only you and the recipient can access them. Enjoy voice and video calls to stay connected with loved ones or colleagues. Express yourself using stickers, GIFs, or by sharing moments on Status. WhatsApp Business enables global customer outreach, facilitating sales growth and relationship building through showcasing products and services. Stay connected effortlessly with group chats for planning outings with friends or staying updated on family conversations.
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfUndress Baby
The quest for the best AI face swap solution is marked by an amalgamation of technological prowess and artistic finesse, where cutting-edge algorithms seamlessly replace faces in images or videos with striking realism. Leveraging advanced deep learning techniques, the best AI face swap tools meticulously analyze facial features, lighting conditions, and expressions to execute flawless transformations, ensuring natural-looking results that blur the line between reality and illusion, captivating users with their ingenuity and sophistication.
Web:- https://undressbaby.com/
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
DDS Security Version 1.2 was adopted in 2024. This revision strengthens support for long runnings systems adding new cryptographic algorithms, certificate revocation, and hardness against DoS attacks.
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
1. 1
Year & Sem – II & III
Section - A,B,C,D
Subject – Data Structures & Algorithms
Unit – I
JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE
2. 1
VISSION AND MISSION OF INSTITUTE
Vision of the Institute
To become a renowned Centre of higher learning, and work towards academic, professional,
cultural and social enrichment of the lives of individuals and communities.
Mission of the Institute
• To Focus on research and spirit of innovation that will drive academic orientation and
pursuit at JECRC University.
• To Identify, based on informed perception of Indian, regional and global needs, areas of
focus and specialization on which the University can concentrate.
• To Undertake collaborative projects that offer opportunities for long-term interaction
between academia and industry.
• To Develop human potential to its fullest extent so that intellectually capable and
imaginatively gifted leaders can emerge in a range of professions.
3. 1
VISSION AND MISSION OF DEPARTMENT
3
Vision of the Department
To become renowned Centre of excellence in computer science and engineering and
make competent engineers & professionals with high ethical values prepared for
lifelong learning.
Mission of the Department
M1- To impart outcome based education for emerging technologies in the field of
computer science and engineering.
M2 - To provide opportunities for interaction between academia and industry.
M3 - To provide platform for lifelong learning by accepting the change in technologies
M4 - To develop aptitude of fulfilling social responsibilities.
4. 1
COURSE OUTCOME
4
CO1: Apply the concepts of data structure, data type and array data
structure and analyze the algorithms and determine their time complexity.
CO2: Apply various data structure such as stacks, Linked List, queues, trees
and graphs to solve various computing problems using C-programming
language.
CO3: Implement standard algorithms for searching & sorting and identify
when to choose which technique.
CO4: Apply the data structure that efficiently models the information in a
problem.
5. 1
CONTENTS (TO BE COVERED)
❑ Introduction of Data Structures and Algorithms
❑ Stack
❑ Basic Operations (PUSH, POP)
❑ Array Representation of Stack (Static & Dynamic)
❑ Applications of Stack
❑ Tower of Hanoi
❑ Multiple Stack representation using Single Array
6. 1
LECTURE CONTENTS WITH A BLEND OF NPTEL
CONTENTS
❑ Introduction of Data Structures and Algorithms
❑ Stack
❑ Array Representation of Stack (Static & Dynamic)
❑ Applications of Stack
❑ Tower of Hanoi
❑ Multiple Stack representation using Single Array
7. What is Data Structure?
• A data structure is a way of organizing data in a computer so that it can be used
data effectively.
• For example, we can store a list of items having the same data-type using
the array data structure.
8. Types of Data Structures
Based on the organizing method of data structure, data structures are divided into two
types.
• Linear Data Structures
• Non - Linear Data Structures
Linear Data Structures Non-Linear Data Structures
• if a data structure organizes the data in sequential
order, then that data structure is called a linear data
structure
• Example
Arrays
List (Linked List)
Stack
Queue
• If a data structure organizes the data in
random order then that data structure is called
as Non-linear data structure.
• Example
Tree
Graph
Dictionaries
Heaps
Tries, Etc.,
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
10. Stack (Last in First Out)
• A stack is called a last-in-first-out (LIFO) collection. This means that
the last thing we added (pushed) is the first thing that gets pulled
(popped) off.
• A stack is a sequence of items that are accessible at only one end
of the sequence
15. PUSH Operation
• In a stack, push() is a function used to insert an element into the stack. In a stack,
the new element is always inserted at top position. Push function takes one
integer value as parameter and inserts that value into the stack. We can use the
following steps to push an element on to the stack...
✔ Step 1 - Check whether stack is FULL. (top == SIZE-1)
✔ Step 2 - If it is FULL, then display "Stack is FULL!!! Insertion is not
possible!!!" and terminate the function.
✔ Step 3 - If it is NOT FULL, then increment top value by one (top++) and set
stack[top] to value (stack[top] = value).
16. POP Operation
• In a stack, pop() is a function used to delete an element from the stack. In a stack,
the element is always deleted from top position. Pop function does not take any
value as parameter. We can use the following steps to pop an element from the
stack...
✔ Step 1 - Check whether stack is EMPTY. (top == -1)
✔ Step 2 - If it is EMPTY, then display "Stack is EMPTY!!! Deletion is not
possible!!!" and terminate the function.
✔ Step 3 - If it is NOT EMPTY, then delete stack[top] and decrement top value
by one (top--).
17. Display Stack items:
• The steps to display the elements of a stack...
✔ Step 1 - Check whether stack is EMPTY. (top == -1)
✔ Step 2 - If it is EMPTY, then display "Stack is EMPTY!!!" and terminate the
function.
✔ Step 3 - If it is NOT EMPTY, then define a variable 'i' and initialize with top.
Display stack[i] value and decrement i value by one (i--).
✔ Step 3 - Repeat above step until i value becomes '0'.
18. Applications
1. Reversing Strings:
• A simple application of stack is reversing strings.
• To reverse a string , the characters of string are pushed
onto the stack one by one as the string is read from left
to right.
• Once all the characters of string are pushed onto stack,
they are popped one by one. Since the character last
pushed in comes out first, subsequent pop operation
results in the reversal of the string.
19. Example
•To reverse the string ‘REVERSE’ the string is read from left to right and
its characters are pushed .
LIKE: onto a stack.
20. Applications
2. Checking the validity of an expression containing
nested parenthesis:
• Stacks are also used to check whether a given arithmetic expressions containing
nested parenthesis is properly parenthesized.
• The program for checking the validity of an expression verifies that for each left
parenthesis braces or bracket ,there is a corresponding closing symbol and symbols
are appropriately nested.
22. Applications
3. Evaluating arithmetic expressions
–INFIX notation:
–The general way of writing arithmetic expressions is known as infix
notation. e.g, (a+b)
•PREFIX notation: e.g, +AB
•POSTFIX notation: e.g: AB+
23. Conversion of Infix to Postfix
1. Scan the Infix expressionfrom left to right for tokens (Operators,
Operands & Parentheses) and perform the steps 2 to 5 for each token in the
Expression.
2. If token is operand, Append it in postfix expression
3. If token is a left parentheses “(“, push it in stack
4. If token is an operator,
– Pop all the operators which are of higher or equal precedence (e.g: -,+,%,/,*)
then the incoming token and append them (in the same order) to the output
Expression.
– After popping out all such operators, push the new token on stack.
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
24. Conversion of Infix to Postfix
5. If “)” right parentheses is found,
• Pop all the operators from the Stack and append them to Output String, till you
encounter the Opening Parenthesis “(“.
• Pop the left parenthesis but don’t append it to the output string (Postfix notation
does not have brackets).
6. When all tokens of Infix expression have been scanned. Pop all the elements from
the stack and append them to the Output String.
The Output string is the Corresponding Postfix Notation.
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
26. CURRENT
SYMBOL
ACTION
PERFORMED
STACK STATUS POSTFIX
EXPRESSION
( PUSH ( ( 2
2 2
+ PUSH + (+ 2
( PUSH ( (+( 24
4 24
- PUSH - (+(- 241
1 241-
) POP - (+ 241-
* PUSH * (+* 241-
3 241-3
POP * 241-3*
POP + 241-3*+
)
CONVERSION OF INFIX INTO POSTFIX
{2+(4-1)*3into 241-3*+}
27. Tower of Hanoi
• The Tower of Hanoi puzzle was invented by the French mathematician Edouard
Lucas in 1883.
• Tower Of Hanoi is a Puzzle involving the usage of Stacks.
• Shifting of discs from source tower to target tower.
• Rules for solving puzzle:
1. One disc can be shifted at once.
2. Only top disc can be shifted.
3. Large disc cannot be placed on smaller disc.
4. Only 3 stacks can be used for solving the puzzle.
•Source Tower having N discs can be solved using (2^N)-1 moves.
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
28. Usage of Stacks in Tower of Hanoi
Real life analogy of Stack is Access single disc, Single Access location.
Steps:
1. Move 1 from A to C
2. Move 2 from A to B
3. Move 1 from C to B
4. Move 3 from A to C
5. Move 1 from B to A
6. Move 2 from B to C
7. Move 1 from A to C
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
29. Use of Recursion for algorithm
:
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
30. Explanation
• The recursion used before
"movedisk" is to move all but the
bottom disk on the initial tower to
an intermediate pole.
• The next line simply moves the
bottom disk to its final resting
place.
• Then on line we move the tower
from the intermediate pole to the
top of the largest disk.
• The base case is detected when
the tower height is 0 and the base
of the tower is moved Use of recursion is again use of stack
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
31. Application
▪ Used as Backup rotation Scheme (Backups of Computers
having multiple tapes/media)
✔A backup rotation scheme is a system for managing your
backup storage media (tapes/DVDs/HDDs).
▪ Used by neuropsychologists trying to evaluate frontal lobe
deficits.
▪ Used to Solve mathematical problems related to Hamilton
Cycle.
Neha Solanki(Assistant Professor, CSE) , JECRC, JAIPUR
32. Representation of Stack
• Stack can be represented in two ways
1. Using array
2. Using linked lists
Both the representations are having their own advantages and disadvantages. So
to select the representation of stack is application dependent.
33. Stack representation using static array
• Stack data structure can be implemented using a one-dimensional array.
• Size of array is fixed.
34. • Basic steps to create an empty stack.
1. Include all the header files which are used in the program and define a
constant 'SIZE' with specific value.
2. Declare all the functions used in stack implementation.
3. Create a one dimensional array with fixed size.
4. Define a integer variable 'top' and initialize with '-1'. (int top = -1)
5. In main method, display menu with list of operations and make suitable function
calls to perform operation selected by the user on the stack.
36. push(value) - Inserting value into the
stack
• Step 1 - Check whether stack is FULL. (top == SIZE-1)
• Step 2 - If it is FULL, then display "Stack is FULL!!! Insertion is not possible!!!" and
terminate the function.
• Step 3 - If it is NOT FULL, then increment top value by one (top++) and set
stack[top] to value (stack[top] = value).
38. pop() - Delete a value from the Stack
• Step 1 - Check whether stack is EMPTY. (top == -1)
• Step 2 - If it is EMPTY, then display "Stack is EMPTY!!! Deletion is not
possible!!!" and terminate the function.
• Step 3 - If it is NOT EMPTY, then delete stack[top] and decrement top value by
one (top--).
40. display() - Displays the elements of a
Stack
• Step 1 - Check whether stack is EMPTY. (top == -1)
• Step 2 - If it is EMPTY, then display "Stack is
EMPTY!!!" and terminate the function.
• Step 3 - If it is NOT EMPTY, then define a variable 'i' and
initialize with top. Display stack[i] value and
decrement i value by one (i--).
• Step 3 - Repeat above step until i value becomes '0'.
41. void display()
{
if(top == -1)
printf("nStack is Empty!!!");
else{
int i;
printf("nStack elements are:n");
for(i=top; i>=0; i--)
printf("%dn",stack[i]);
}
}
42. void main()
{
int value, choice;
clrscr();
while(1){
printf("nn***** MENU *****n");
printf("1. Pushn2. Popn3.
Displayn4. Exit");
printf("nEnter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the value to be
insert: ");
scanf("%d",&value); push(value);
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("nWrong selection!!!
Try again!!!");
} } }
42
43. • In the implementation of stack using static array, size is always predefined or
fixed.
• Once stack is created its size cannot be changed hence a condition called “stack
full”
arises.
• To overcome this problem we will use dynamic array/ growable stack.
• So a dynamic array can change its capacity.
44. • Growable stack is the concept of allocating more memory such that stack full
condition does not arises easily.
• A growable array base stack can be implemented by allocating new memory
larger than previous stack memory and copying elements from old stack to new
stack.
• And then at last the name of the new stack as the name given to the previous
stack.
45. Strategy for growable stack
• There are two strategies:
1. Tight Strategy : Add a constant amount to the old stack (N+c)
2. Growth Strategy : Double the size of old stack (2N)
46.
47. • Following steps should be done
1. Allocate new space
2. Copy data to new space
3. Free old space
48. Implement Stack Operations using Dynamic
Memory Allocation
Problem Solution
1. Use malloc function to allocate memory.
2. Define separate functions for the operations like push, pop and display.
3. Use switch statement to access these functions.
49. Program
#include<stdio.h>
#include<stdlib.h>
struct stack
{
int * a;
int top;
int maxSize;
};
void initstack(struct stack * p, int maxSize);
void push(struct stack * p, int item);
void display(struct stack p);
int pop(struct stack * p);
void printMenu();
int main()
{
struct stack p;
int data,ch, data1, m;
50. printf("Enter the maximum size of the stackn");
scanf("%d",&m);
initstack(&p,m);
do
{
printMenu();
printf("Enter your choicen");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter the element to be pushedn");
scanf("%d",&data);
push(&p, data);
break;
case 2:
data1 = pop(&p);
if(data1 != -1000)
printf("The popped element is %dn",data1);
break;
51. case 3: printf("The contents of the stack are");
display(p);
printf("n");
break;
default:
return 0;
}
}
while(1);
return 0;
}
void printMenu()
{
printf("Choice 1 : Pushn");
printf("Choice 2 : Popn");
printf("Choice 3 : Displayn");
printf("Any other choice : Exitn");
}
void initstack(struct stack * p, int maxSize)
{
p->top=-1;
p->maxSize=maxSize;
}
void push(struct stack * p, int item)
{
if (p->top == p->maxSize-1)
{
printf("Stack is fulln");
return;
}
p->a = (int *)malloc(sizeof(int));
p->top++;
p->a[p->top] =item;
p->maxSize--;
}
void display(struct stack p)
{
struct stack *p1;
p1=&p;
int a[30],n=0,i;
for (i = p1->top ; i >= 0; i--)
{
printf("n%d", p1->a[i]);
}
}
52. int pop(struct stack * p)
{
int num;
if(p->top == -1)
{
printf("Stack is emptyn");
return -1000;
}
num = p->a[p->top];
p->top--;
return num;
}
54. Linked List in Data Structure
• A linked list is a linear data structure, in which the elements are not
stored at contiguous memory locations. The elements in a linked list
are linked using pointers as shown in the below image:
A linked list is represented by a pointer to the first node of the linked list. The first node is called the
head. If the linked list is empty, then the value of the head is NULL.
Each node in a list consists of at least two parts:
1) data
2) Pointer (Or Reference) to the next node
55. Why Linked List?
• Arrays can be used to store linear data of similar types, but
arrays have the following limitations.
1) The size of the arrays is fixed: So we must know the upper
limit on the number of elements in advance. Also, generally, the
allocated memory is equal to the upper limit irrespective of the
usage.
2) Inserting a new element in an array of elements is expensive
because the room has to be created for the new elements and
to create room existing elements have to be shifted.
56. For example, in a system, if we maintain a sorted list of IDs in
an array id[].
• id[] = [1000, 1010, 1050, 2000, 2040].
• And if we want to insert a new ID 1005, then to maintain the
sorted order, we have to move all the elements after 1000
(excluding 1000).
Deletion is also expensive with arrays until unless some
special techniques are used. For example, to delete 1010 in
id[], everything after 1010 has to be moved.
57. Advantages over arrays
• They are a dynamic in nature which allocates the memory when
required.
• Insertion and deletion operations can be easily implemented.
• Stacks and queues can be easily executed.
• Linked List reduces the access time.
Disadvantages of Linked Lists
• The memory is wasted as pointers require extra memory for storage.
• No element can be accessed randomly; it has to access each node
sequentially.
• Reverse Traversing is difficult in linked list.
• Random access is not allowed. We have to access elements
sequentially starting from the first node. So we cannot do binary
search with linked lists efficiently with its default implementation.
• Extra memory space for a pointer is required with each element of the
list.
• Not cache friendly. Since array elements are contiguous locations,
there is locality of reference which is not there in case of linked
lists.
58. Applications of Linked Lists
• Linked lists are used to implement stacks, queues, graphs, etc.
• Linked lists let you insert elements at the beginning and end of the list.
• In Linked Lists we don't need to know the size in advance.
59. Types of Linked Lists:
There are 3 different implementations of Linked List available, they are:
• Singly Linked List
• Doubly Linked List
• Circular Linked List
60. Singly Linked List
Singly linked lists contain nodes which have a data part as well as
an address part i.e. next, which points to the next node in the
sequence of nodes.
The operations we can perform on singly linked lists
are insertion, deletion and traversal.
61. Doubly Linked List
In a doubly linked list, each node contains a data part and two
addresses, one for the previous node and one for the next node.
62. Circular Linked List
In circular linked list the last node of the list holds the address of
the first node hence forming a circular chain.
63. ARRAY LINKED LIST
Array is a collection of elements of similar data type. Linked List is an ordered collection of elements of same type, which are
connected to each other using pointers.
Array supports Random Access, which means elements can be
accessed directly using their index, like arr[0] for 1st element, arr[6] for 7th
element etc.
Hence, accessing elements in an array is fast with a constant time
complexity of O(1).
Linked List supports Sequential Access, which means to access any
element/node in a linked list, we have to sequentially traverse the
complete linked list, upto that element.
To access nth element of a linked list, time complexity is O(n).
In an array, elements are stored in contiguous memory location or
consecutive manner in the memory.
In a linked list, new elements can be stored anywhere in the memory.
Address of the memory location allocated to the new element is stored in
the previous node of linked list, hence formaing a link between the two
nodes/elements.
In array, Insertion and Deletion operation takes more time, as the
memory locations are consecutive and fixed.
In case of linked list, a new element is stored at the first free and available
memory location, with only a single overhead step of storing the address
of memory location in the previous node of linked list.
Insertion and Deletion operations are fast in linked list.
Memory is allocated as soon as the array is declared, at compile time.
It's also known as Static Memory Allocation.
Memory is allocated at runtime, as and when a new node is added. It's
also known as Dynamic Memory Allocation.
In array, each element is independent and can be accessed using it's
index value.
In case of a linked list, each node/element points to the next, previous, or
maybe both nodes.
Array can single dimensional, two dimensional or multidimensional Linked list can be Linear(Singly), Doubly or Circular linked list.
Size of the array must be specified at time of array decalaration. Size of a Linked list is variable. It grows at runtime, as more nodes are
added to it.
Array gets memory allocated in the Stack section. Whereas, linked list gets memory allocated in Heap section.