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
stackin CPP). - Use this link to concert
Concatenate(...)functionality into operator overloading inLinkedList.cppfile. - Incorporate more headers for new
LinkedList.cppfile. - Work on porting the old
C++singly linked list + doubly linked list algorithms to the newLinkedList.cppimplementation. - Make sure
C++files adhere to best practices re: Rule of Three/Five/Zero and RAII. - Continue adding to
SparseMatrixStruct.cppandSparseMatrix.cpp(include subtraction; possibly multiplication?). - Get all the
Pythoncode translated in toC++(!!!) andJava(as time permits). - Translate
ArrayADT fromC++toPythonandJava. - 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.cppforLinkedList-based stack. - Made changes to
Display()functions in bothLinkedList.handLinkedList-basedstack.cpp. - Later, made changes to
Peek(int index)inLinkedList-basedstack.cppto ensure that"Invalid Position!"prints wheneverindexis greater thantop+1.
- Initial commit of array-based
stack.cppin 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 theArrayADT. - 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/DoublyLinkedListto/Obsolete/CPP/per inclusion of new/LinkedList/files.
- Changed
LinkedList.cppto haveheadas a pointer + percolated the associated method changes throughout. - Changed the name of old-
LinkedList.cppfile toLinkedListLegacy.cpp.
- Initial commit of
Node.handLinkedList.cpp; the particulars of this were written last week but uncommitted.
- Updated the study guide.
- Initial commit of
SparseMatrix.handSparseMatrixNew, 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.cppto work with generics / templating. I'm an idiot for not considering forward-declaration as a solution sooner; forward-declaration literally solved one of myArray.hproblems the other day! - Split
SparseMatrix.cppintoElement.handSparseMatrix.h.
- Initial commit of
SparseMatrixStruct.cpp. - Later, added
Add()functionality toSparseMatrixStruct.cpp. - Uploaded initial commit of
SparseMatrix.cpp, which usesclasses instead ofstructs. - Later: Swapped
Read()andDisplay()for overloadedcinandcout. - Even later: Implemented old
Add()as customSparseMatrix::operator+operator.
- In
LowerTriangularMatrix.cpp: Revamped loops to start ati=1andj=1. - Later, initial commit of
UpperTriangularMatrix.handUpperTriangularMatrix.cppusing 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.cppand fixed typo inREADME. - Even later: Initial commit of
ToeplitzMatrix.handToeplitzMatrix.cpp.
- Added destructor to Array ADT in
C++. - Created
CPP/Matricesdirectory + added initial commit ofDiagonalMatrixfiles (.cppand.h). - Later, created
C++filesLowerTriangularMatrix.handLowerTriangularMatrix.cppusing row-major mapping. - Improved commenting in
Array.h,DiagonalMatrix.cpp, andLowerTriangularMatrix.cpp. - Added a driver to
LowerTriangularMatrix.cppto allow for entering a whole matrix all at once.
- In
C++Array ADT: Added Setters, in part to allow thepublicT* Ato become private. - Later, declared
Union2as afriendfunction to allow access to private member variables. - Added better commenting to show the breakdown of functions throughout code.
- Later, moved legacy functions to
ArrayLegacy.cppand renamedUnion2andUnion3both asUnion. - Also: Implemented
friendversions ofIntersectionandComplement. - Later still: Changed a number of dereferencing operations to
->s. - Also, added
Intersection,Complementmember functions.
- In
C++Array ADT: Added functionality forIntersectionandComplement. - Later, simplified
Intersectionalgorithm and changed the existing algorithm toLegacyIntersectionfor posterity. - Eventually figured out a non-
Voidversion ofUnioninC++Array ADT. This will be fleshed out more soon. - Mimicked non-member
Union2code into member functionUnion3.
- Made some small code tweaks to the Array ADT in
C++, and later, added support forContainsand(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.cppand.hfiles). - 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
JavaHash Map file. - Edited the README and the .gitignore files.
- Later, removed some of the
Pythontest code so the GitHub calculator thing gets the language percentages more accurate.
- Filled in the
Stacks and Queuessection of the study guide. - Also, added in the
StackandQueuerows 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
SelectionSortfor bothPython3andJava.Both versions include the algorithm, as well as a
SelectionSortAnalysismethod/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.gitignorefile.
- I added some details to the study guide, and implemented BFS to the
BST.pyfile. 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
Okaydirectory (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!