From-scratch attempts at implementing some common data structures and algorithms.
Currently, this repo contains (both bug-free and buggy) versions of code I've written to try to get a better understanding of the under-the-hood inner workings of various data structures.
As of this writing (23 July 2022), most of the code is in Python3
, though some Java
and C++
updates have started to creep in as well. Future iterations will include more Java
and C++
code, and perhaps some other languages as well. Update: Due to some changes in circumstance, C++
may become the main focal point of my contributions; we shall see.
As of 3 July 2022, a study guide has also made its way into the repo. This study guide is LaTeX
'ed and is intended to help guide my studies + document the journey so far. Update: Later, I removed the TeX
source code from the repo so that the code percentages would better reflect my real contributions rather than showing a repo with 80% TeX
code!
- Consider returning pointer-type variables in data structures where "actual return" of a variable is impossible (see
stack
in CPP). - Use this link to concert
Concatenate(...)
functionality into operator overloading inLinkedList.cpp
file. - Incorporate more headers for new
LinkedList.cpp
file. - Work on porting the old
C++
singly linked list + doubly linked list algorithms to the newLinkedList.cpp
implementation. - Make sure
C++
files adhere to best practices re: Rule of Three/Five/Zero and RAII. - Continue adding to
SparseMatrixStruct.cpp
andSparseMatrix.cpp
(include subtraction; possibly multiplication?). - Get all the
Python
code translated in toC++
(!!!) andJava
(as time permits). - Translate
Array
ADT fromC++
toPython
andJava
. - Get study guide source re-added so I can work on it elsewhere.
- Keep working on the study guide.
- Reorganization of Trees, Tries, and Hybrid Trees in the study guide.
- Later, more fleshing out of study guide subsections on trees and substructures.
- Edited the study guide to include more information about queues and related structures.
- Made several other study guide changes/commits throughout the day.
- Edited the study guide to include more information about queues + to better delineate the subsections of the stack and queue topics.
- In array-based
stack.cpp
: Made changes toPeek()
. - Later, made initial commits of
Node.h
,LinkedList.h
, andstack.cpp
forLinkedList
-based stack. - Made changes to
Display()
functions in bothLinkedList.h
andLinkedList
-basedstack.cpp
. - Later, made changes to
Peek(int index)
inLinkedList
-basedstack.cpp
to ensure that"Invalid Position!"
prints wheneverindex
is greater thantop+1
.
- Initial commit of array-based
stack.cpp
in CPP. - Added
Pop()
functionality to stack. - After some time weighing how to handle the Stack underflow! situation, changed
Pop()
to return pointer type variable. - After learning that Stack underflow! resulted in seg fault in VSCode, I decided to undo the above change for the time being.
- Later, Added
Peek(...)
,IsEmpty()
, andIsFull()
.
- Updated the study guide some restructuring re: Stacks, Queues, etc.
- Added
Middle()
support toLinkedList.cpp
. - Later, updated the study guide with details related to linked lists, variants of linked lists, and linked lists versus arrays.
- In
LinkedList.cpp
: AddedAppend(...)
functionality, which should have been here a long time ago. - After much back-and-forth, added
Concatenate(...)
functionality. Later, this will come in the form of an overloaded operator. - Later, refactored (old)
Concatenate(...)
into (renamed)Join(...)
and (new) (void
)Concatenate(...)
.
- In
LinkedList.cpp
: Added new example +SortedQ()
. - Later, added
DeleteDuplicates()
inLinkedList.cpp
. - Eventually, swapped order of parameters for
Insert(...)
to better match what happens in theArray
ADT. - Added
Reverse()
functionality toLinkedList.cpp
. - From home: Renamed
/Okay/
to/Working/
.
- Added
Display()
toLinkedList.cpp
. - Later, added
Length()
,Sum()
,Min()
, andMax()
toLinkedList.cpp
. - Added
Insert(...)
toLinkedList.cpp
. - Later, added
Delete(...)
toLinkedList.cpp
, and later, made a small edit toDelete(...)
. - At home, moved
CPP/SinglyLinkedList/
andCPP/DoublyLinkedList
to/Obsolete/CPP/
per inclusion of new/LinkedList/
files.
- Changed
LinkedList.cpp
to havehead
as a pointer + percolated the associated method changes throughout. - Changed the name of old-
LinkedList.cpp
file toLinkedListLegacy.cpp
.
- Initial commit of
Node.h
andLinkedList.cpp
; the particulars of this were written last week but uncommitted.
- Updated the study guide.
- Initial commit of
SparseMatrix.h
andSparseMatrixNew
, featuring hard-codedint
-type dataElement.x
. I'm still trying to figure out the intricacies of the templating for non-integer types. - Later, deleted those two files to try to figure out stuff.
- After much work + help on Stack Overflow: Got
SparseMatrix.cpp
to work with generics / templating. I'm an idiot for not considering forward-declaration as a solution sooner; forward-declaration literally solved one of myArray.h
problems the other day! - Split
SparseMatrix.cpp
intoElement.h
andSparseMatrix.h
.
- Initial commit of
SparseMatrixStruct.cpp
. - Later, added
Add()
functionality toSparseMatrixStruct.cpp
. - Uploaded initial commit of
SparseMatrix.cpp
, which usesclass
es instead ofstruct
s. - Later: Swapped
Read()
andDisplay()
for overloadedcin
andcout
. - Even later: Implemented old
Add()
as customSparseMatrix::operator+
operator.
- In
LowerTriangularMatrix.cpp
: Revamped loops to start ati=1
andj=1
. - Later, initial commit of
UpperTriangularMatrix.h
andUpperTriangularMatrix.cpp
using row-major mapping. - Used
LowerTriangularMatrix*
to build initial commit ofSymmetricMatrix*
---and later,TridiagonalMatrix*
---files. - Fixed bug in
ShortPrint()
forSymmetricMatrix.cpp
. - Later, fixed indexing bug in
TridiagonalMatrix.cpp
and fixed typo inREADME
. - Even later: Initial commit of
ToeplitzMatrix.h
andToeplitzMatrix.cpp
.
- Added destructor to Array ADT in
C++
. - Created
CPP/Matrices
directory + added initial commit ofDiagonalMatrix
files (.cpp
and.h
). - Later, created
C++
filesLowerTriangularMatrix.h
andLowerTriangularMatrix.cpp
using row-major mapping. - Improved commenting in
Array.h
,DiagonalMatrix.cpp
, andLowerTriangularMatrix.cpp
. - Added a driver to
LowerTriangularMatrix.cpp
to allow for entering a whole matrix all at once.
- In
C++
Array ADT: Added Setters, in part to allow thepublic
T* A
to become private. - Later, declared
Union2
as afriend
function to allow access to private member variables. - Added better commenting to show the breakdown of functions throughout code.
- Later, moved legacy functions to
ArrayLegacy.cpp
and renamedUnion2
andUnion3
both asUnion
. - Also: Implemented
friend
versions ofIntersection
andComplement
. - Later still: Changed a number of dereferencing operations to
->
s. - Also, added
Intersection
,Complement
member functions.
- In
C++
Array ADT: Added functionality forIntersection
andComplement
. - Later, simplified
Intersection
algorithm and changed the existing algorithm toLegacyIntersection
for posterity. - Eventually figured out a non-
Void
version ofUnion
inC++
Array ADT. This will be fleshed out more soon. - Mimicked non-member
Union2
code into member functionUnion3
.
- Made some small code tweaks to the Array ADT in
C++
, and later, added support forContains
and(Unsorted) Union
.
- To Array ADT in
C++
: AddedGet
,Set
,Sum
,Avg
,Max
, andMin
. - Later, rewrote some code in a clearer manner + deleted some commented-out code in
C++
Array ADT. - In Array ADT
C++
files: AddedReverse
,LeftShift
,LeftRotate
,RightShift
,RightRotate
. - Added functionality in Array ADT for
SortedInsert
,IsSorted
, andPosNegSwap
. - Later, improved incapsulation in Array ADT by making member vars private + adding getters.
- Committed initial version of Array ADT in
C++
(both.cpp
and.h
files). - Later, fixed up some pointer-related things in Array ADT.
- Made some small edits to linked list in
C++
- Completed doubly linked list in
C++
with generics.
- Completed singly linked list in
C++
with generics. - Learned more about pointers, but still need additional refresher.
- Started working on singly linked lists in
C++
. - In so doing, realized I have a lot to (re-)learn (for the 17th time) about pointers.
- Got a 0th draft of hash sets working in
C++
. To get this working, I had to abandon my aspirations for generic types and just stick with integers. Generic types will come soon! ::crosses fingers:: - Later, added working(!!!) generics to
C++
hash sets. - Also, removed references to
this->*
, as that doesn't appear to be veryC++
-like? 🤷
- Decided to try my hand at hash sets in
C++
after having not writtenC++
code in 15 years. It did not go well! - Made some small tweaks to the
Java
Hash Map file. - Edited the README and the .gitignore files.
- Later, removed some of the
Python
test code so the GitHub calculator thing gets the language percentages more accurate.
- Filled in the
Stacks and Queues
section of the study guide. - Also, added in the
Stack
andQueue
rows of the first-page complexity table.
- Made a few small edits to the study guide.
- Also, added a section for
Stacks and Queues
+ filled in the subsections a bit before bedtime.
- Made some complexity-related edits to the study guide.
- Renamed the repo to include common algorithms. Will ultimately restructure the directories as well.
- Later, restructured all subdirectories.
- Much later, wrote + uploaded initial versions of
SelectionSort
for bothPython3
andJava
.Both versions include the algorithm, as well as a
SelectionSortAnalysis
method/function which shows how the number of steps grows as the size of the input array doubles.What I reallllllly want to show is how time increases, not code count. I'll do some digging into that soon and try to implement ASAP.
- Much later still, updated the study guide pretty heavily, including uses of newly-included images and a new .gitignore file.
- Big changes to the study guide, including:
- Data Structures and Search Algorithms main sections.
- A full-populated and linked search algorithm complexity table.
- A fully-written section on Selection Sort (plus a lot of dummy text for other sort algorithms).
- First upload of a Java version (
HashSet
) plus a general restructuring of directory structure + a revamped.gitignore
file.
- I added some details to the study guide, and implemented BFS to the
BST.py
file. Next up, I plan to implement some deletion methods, and possibly to adapt some BST-implemented methods to code a less-specific brand of tree.
- I'm keeping a study guide to go along with my explorations into these data structures/algorithms. I decided it was a good idea to upload the related .tex, .sty, and .pdf files.
- Later, added BST information to both
Okay
directory (in Python3) and study guide.
- Used some snippets from this answer to prototype a redo of SinglyLinkedList. This code + the code in the accepted comment contained >= 2 very serious bugs and needed quite a bit of plussing up, so I did that plus thoroughly documented everything before **finally** reaching the level of "accepted LeetCode answer."
- Initial upload.
- Later, updated the README.md file to its current state.
- Approximately 22 hours later, attempted to use the GeeksForGeeks solution as an inspiration for a new implementation of SinglyLinkedList, only to find that this one times out on LeetCode. I think my best plan of action moving forward will be to try a whole new implementation; I have some ideas!