Stack in python

Published: 04 March 2021
on channel: Nishu Singh
194
22

A stack is a data structure that holds a list of elements. A stack works based on the LIFO principle i.e., Last In, First out, meaning that the most recently added element is the first one to remove.
Operations of stack are:
Insertion (push)
Deletion (Pop)
Traversing
Searching
**Sorting: sort ( ) in use Timsort algorithm. Timsort is a hybrid sorting algorithm, derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data. It was invented by Tim Peters in 2002 for use in the Python programming language. The algorithm finds subsets of the data that are already ordered, and uses the subsets to sort the data more efficiently. This is done by merging an identified subset, called a run, with existing runs until certain criteria are fulfilled.

** Important question asked in company interview.

Question: What is the time complexity to search a element n from unsorted list L.
Answer: Best Case -O(1)
Worst case- O(n)

The content I have used to make presentation is from various websites including Python 3 documentation.

#datastructure #queue #stack #coding #list #developer #programminglanguage #pythonconcepts #pythonprogramming #code #python #implementation #python3 #timecomplexity #pythonquestion


On this page of the site you can watch the video online Stack in python with a duration of hours minute second in good quality, which was uploaded by the user Nishu Singh 04 March 2021, share the link with friends and acquaintances, this video has already been watched 194 times on youtube and it was liked by 22 viewers. Enjoy your viewing!