https://github.com/stoverc/datastructuresandalgorithms
From-scratch attempts at implementing some common data structures and algorithms.
https://github.com/stoverc/datastructuresandalgorithms
algorithm algorithms core-language cpp data-structures data-structures-algorithms data-structures-and-algorithms datastructures java linked-list python study-guide
Last synced: 5 months ago
JSON representation
From-scratch attempts at implementing some common data structures and algorithms.
- Host: GitHub
- URL: https://github.com/stoverc/datastructuresandalgorithms
- Owner: stoverc
- Created: 2022-07-23T06:13:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-05T20:29:37.000Z (over 2 years ago)
- Last Synced: 2025-03-01T00:36:26.221Z (9 months ago)
- Topics: algorithm, algorithms, core-language, cpp, data-structures, data-structures-algorithms, data-structures-and-algorithms, datastructures, java, linked-list, python, study-guide
- Language: C++
- Homepage:
- Size: 4.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Data Structures and Algorithms
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!
## TODO:
* Consider returning pointer-type variables in data structures where "actual return" of a variable is impossible (see `stack` in CPP).
* Use [this link](https://stackoverflow.com/questions/68055899/concatenating-two-linked-lists-using-operator-overloading-c) to concert `Concatenate(...)` functionality into operator overloading in `LinkedList.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 new `LinkedList.cpp` implementation.
* Make sure `C++` files adhere to best practices re: [Rule of Three/Five/Zero](https://en.cppreference.com/w/cpp/language/rule_of_three) and [RAII](https://en.cppreference.com/w/cpp/language/raii).
* Continue adding to `SparseMatrixStruct.cpp` and `SparseMatrix.cpp` (include subtraction; possibly multiplication?).
* Get all the `Python` code translated in to `C++` (!!!) and `Java` (as time permits).
* Translate `Array` ADT from `C++` to `Python` and `Java`.
* Get study guide source re-added so I can work on it elsewhere.
* Keep working on the study guide.
Changelog
5 Jul 2023
- Reorganization of Trees, Tries, and Hybrid Trees in the study guide.
- Later, more fleshing out of study guide subsections on trees and substructures.
26 Jun 2023
- Edited the study guide to include more information about queues and related structures.
- Made several other study guide changes/commits throughout the day.
23 Jun 2023
- Edited the study guide to include more information about queues + to better delineate the subsections of the stack and queue topics.
21 Jun 2023
- In array-based
stack.cpp: Made changes to Peek().
- Later, made initial commits of
Node.h, LinkedList.h, and stack.cpp for LinkedList-based stack.
- Made changes to
Display() functions in both LinkedList.h and LinkedList-based stack.cpp.
- Later, made changes to
Peek(int index) in LinkedList-based stack.cpp to ensure that "Invalid Position!" prints whenever index is greater than top+1.
21 Jun 2023
- 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(), and IsFull().
14 Jun 2023
- Updated the study guide some restructuring re: Stacks, Queues, etc.
13 Jun 2023
- Added
Middle() support to LinkedList.cpp.
- Later, updated the study guide with details related to linked lists, variants of linked lists, and linked lists versus arrays.
9 Jun 2023
- In
LinkedList.cpp: Added Append(...) 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(...).
8 Jun 2023
- In
LinkedList.cpp: Added new example + SortedQ().
- Later, added
DeleteDuplicates() in LinkedList.cpp.
- Eventually, swapped order of parameters for
Insert(...) to better match what happens in the Array ADT.
- Added
Reverse() functionality to LinkedList.cpp.
- From home: Renamed
/Okay/ to /Working/.
7 Jun 2023
- Added
Display() to LinkedList.cpp.
- Later, added
Length(), Sum(), Min(), and Max() to LinkedList.cpp.
- Added
Insert(...) to LinkedList.cpp.
- Later, added
Delete(...) to LinkedList.cpp, and later, made a small edit to Delete(...).
- At home, moved
CPP/SinglyLinkedList/ and CPP/DoublyLinkedList to /Obsolete/CPP/ per inclusion of new /LinkedList/ files.
6 Jun 2023
- Changed
LinkedList.cpp to have head as a pointer + percolated the associated method changes throughout.
- Changed the name of old-
LinkedList.cpp file to LinkedListLegacy.cpp.
31 May 2023
- Initial commit of
Node.h and LinkedList.cpp; the particulars of this were written last week but uncommitted.
26 May 2023
- Updated the study guide.
24 May 2023
- Initial commit of
SparseMatrix.h and SparseMatrixNew, featuring hard-coded int-type data Element.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 my Array.h problems the other day!
- Split
SparseMatrix.cpp into Element.h and SparseMatrix.h.
23 May 2023
- Initial commit of
SparseMatrixStruct.cpp.
- Later, added
Add() functionality to SparseMatrixStruct.cpp.
- Uploaded initial commit of
SparseMatrix.cpp, which uses classes instead of structs.
- Later: Swapped
Read() and Display() for overloaded cin and cout.
- Even later: Implemented old
Add() as custom SparseMatrix::operator+ operator.
22 May 2023
- In
LowerTriangularMatrix.cpp: Revamped loops to start at i=1 and j=1.
- Later, initial commit of
UpperTriangularMatrix.h and UpperTriangularMatrix.cpp using row-major mapping.
- Used
LowerTriangularMatrix* to build initial commit of SymmetricMatrix*---and later, TridiagonalMatrix*---files.
- Fixed bug in
ShortPrint() for SymmetricMatrix.cpp.
- Later, fixed indexing bug in
TridiagonalMatrix.cpp and fixed typo in README.
- Even later: Initial commit of
ToeplitzMatrix.h and ToeplitzMatrix.cpp.
18 May 2023
- Added destructor to Array ADT in
C++.
- Created
CPP/Matrices directory + added initial commit of DiagonalMatrix files (.cpp and .h).
- Later, created
C++ files LowerTriangularMatrix.h and LowerTriangularMatrix.cpp using row-major mapping.
- Improved commenting in
Array.h, DiagonalMatrix.cpp, and LowerTriangularMatrix.cpp.
- Added a driver to
LowerTriangularMatrix.cpp to allow for entering a whole matrix all at once.
16 May 2023
- In
C++ Array ADT: Added Setters, in part to allow the public T* A to become private.
- Later, declared
Union2 as a friend 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 renamed Union2 and Union3 both as Union.
- Also: Implemented
friend versions of Intersection and Complement.
- Later still: Changed a number of dereferencing operations to
->s.
- Also, added
Intersection, Complement member functions.
15 May 2023
- In
C++ Array ADT: Added functionality for Intersection and Complement.
- Later, simplified
Intersection algorithm and changed the existing algorithm to LegacyIntersection for posterity.
- Eventually figured out a non-
Void version of Union in C++ Array ADT. This will be fleshed out more soon.
- Mimicked non-member
Union2 code into member function Union3.
12 May 2023
- Made some small code tweaks to the Array ADT in
C++, and later, added support for Contains and (Unsorted) Union.
11 May 2023
- To Array ADT in
C++: Added Get, Set, Sum, Avg, Max, and Min.
- Later, rewrote some code in a clearer manner + deleted some commented-out code in
C++ Array ADT.
- In Array ADT
C++ files: Added Reverse, LeftShift, LeftRotate, RightShift, RightRotate.
- Added functionality in Array ADT for
SortedInsert, IsSorted, and PosNegSwap.
- Later, improved incapsulation in Array ADT by making member vars private + adding getters.
10 May 2023
- Committed initial version of Array ADT in
C++ (both .cpp and .h files).
- Later, fixed up some pointer-related things in Array ADT.
19 Aug 2022
- Made some small edits to linked list in
C++
- Completed doubly linked list in
C++ with generics.
14 Aug 2022
- Completed singly linked list in
C++ with generics.
- Learned more about pointers, but still need additional refresher.
12 Aug 2022
- 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.
10 Aug 2022
- 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 very C++-like? :shrug:
23 Jul 2022
- Decided to try my hand at hash sets in
C++ after having not written C++ 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.
16 Jul 2022
- Filled in the
Stacks and Queues section of the study guide.
- Also, added in the
Stack and Queue rows of the first-page complexity table.
12 Jul 2022
- 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.
9 Jul 2022
- Made some complexity-related edits to the study guide.
8 Jul 2022
- 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 both Python3 and Java.
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.
7 Jul 2022
- 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).
6 Jul 2022
- First upload of a Java version (
HashSet) plus a general restructuring of directory structure + a revamped .gitignore file.
4 Jul 2022
- 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.
3 Jul 2022
- 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.
27 Jun 2022
- 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."
26 Jun 2022
- 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!