Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dhravya/dsa-for-noobs
A collection of data structures and algorithms I'm writing while learning
https://github.com/dhravya/dsa-for-noobs
algorithms data-structures
Last synced: 27 days ago
JSON representation
A collection of data structures and algorithms I'm writing while learning
- Host: GitHub
- URL: https://github.com/dhravya/dsa-for-noobs
- Owner: Dhravya
- Created: 2022-01-09T13:59:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T18:40:53.000Z (about 3 years ago)
- Last Synced: 2024-10-11T23:05:06.436Z (3 months ago)
- Topics: algorithms, data-structures
- Language: Python
- Homepage: https://dhravya.me
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Data Structures and Algorithms:
This is a collection of data structures and algorithms that I write while learning the subject
## Stack:
stack.py
A stack algorithm is a data structure that is like a pack of cards - a stack.
Stack has the following properties:### Push
Adds element to the top of the stack### Pop
Removes element from the top of the stack### Peek
Returns the element at the top of the stackSize and is_empty are just helper functions
### Stuff Done with stack:
- Checking if a bracket string is balanced
Explanation:
- Add all brackets in the stack one by one
- on reaching a closing bracket, check if the top of the stack is a matching bracket
- if it is, pop the top of the stack and check the next bracket
- rinse and repeat
- if the stack is empty, the string is balanced
- otherwise, the string is not balanced in the end- Reverse algorithm
Explanation:
- Add all characters in the string to the stack
- make a new string - which will hold the return value
- pop the top of the stack until its empty and add it to the string
- Voila! the string has been reversed- Int to binary conversion
Explanation:
- Divide the integer by 2 and add the remainder to the stack
- the quotient obtained from the division is what we'll use to get the next remainder
- Keep repeating until the quotient is 0
- Reverse the stack by popping its values to obtain the binary string
```
___________________________
|Quotient: 2 Remainder: 1 | - remainder added (Current stack: 1)
|Quotient: 1 Remainder: 0 | - remainder added (Current stack: 10)
|Quotient: 0 Remainder: 1 | - remainder added (Current stack: 101)
____________________________
Answer will be the reverse of this stack : 101
```