Skip to content

Seher-Kanwal/Stack-Data-Structure-in-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

"Pthon image"

Stack-Data-Structure-in-Python

Stack Data Structure in Python with different exercise

STACK:

In computer science, a stack is an abstract data type that serves as a collection of elements, with two main operations:

  • Push, which adds an element to the collection, and
  • Pop, which removes the most recently added element that was not yet removed.

Here is another operation that helps to view the top element without removing it from stack:

  • Peek operation can, without modifying the stack, return the value of the last element added.

Order:

The order in which an element added to or removed from a stack is described as last in, first out, referred to by the acronym LIFO.

we have different ways of implementing the stack in python:

* Using list

  Stack concept are done by using arrays and linked lists where the top position is tracked using a variable or header pointer respectively
  The method that will be used:

  * append(x): Appends x at the end of the list
  * pop() : Removes last elements of the list

* Using Deque from Collection library

* Using Class that also include Deque

Applications of Python Stack

 Stacks are considered as the backbone of Data Structures. Most of the algorithms and applications are implemented using stacks.

Some of the key applications of Python Stacks are—

  • Used in browsers to move to the last page we visited
  • used in “undo” mechanism in the text editor.
  • Language processing:
  • space for parameters and local variables is created internally using a stack.
  • compiler’s syntax check for matching braces is implemented by using stack.
  • support for recursion.
  • Expression evaluation like postfix or prefix in compilers.
  • Backtracking (game playing, finding paths, exhaustive searching.
  • Python Stack is also used in Memory management, run-time environment for nested language features. etc
  • Used in Algorithms like Tower of Hanoi, tree traversals, histogram problem and also in graph algorithms like Topological Sorting.

About

Stack Data Structure in Python with different exercise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published