Simple personal site made with Angular 2
domfarolino / algorithms Goto Github PK
View Code? Open in Web Editor NEW๐ Documented algorithmic problems/solutions + datastructures
Home Page: https://domfarolino.com/algorithms
๐ Documented algorithmic problems/solutions + datastructures
Home Page: https://domfarolino.com/algorithms
For a lot of algorithms that use linked lists and binary trees, I often repeat the same struct
for each respectively, set up an example, and then create the same helpers (usually print and delete or something). These helpers and struct
definitions get repeated a lot, so it might make sense to factor them out into utilities, or even use the homemade data structures in this repository (though for some problems that might not be possible, given problem-specific modifications).
The repository is now published to https://domfarolino.com/algorithms and adding a table of contents to the README would make the site much more navigable and improve the ...wait for it...SEO.
/cc thanks @isiah-lloyd
It would be nice if this repository, under datastructures
, we had an implementation of a data structure that supports arbitrarily large integers. This should be relatively easy to implement, at least naively, and can be helpful for some future number-theory based algorithms under Number_Algorithms
.
Docs for datastructures
need added. Maybe even @kytrol could proofread them!!
Very interesting one: https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/description/
Reading https://github.com/domfarolino/algorithms/tree/master/src/datastructures/Vector#void-vectortclear should give you a good idea on the changes that may need made to clear()
. This is primarily because as it stands, clear()
can be called multiple times however the vector becomes unusable after a single call.
This repository has a lot of data structures (more coming!) and things like Leetcode algorithm solutions and documentation. There are some classic CS problems in here as well, like searching and sorting, however I think more needs done to make it easier to move more algos in. For example, I'd rather not put things like KMP string matching in the super /String_Algorithms
. It'd be nice to maybe have some "fundamentals" that carry textbook and classic algos in.
All binary search tree iterators support the increment and decrement operators (delegating to the tree's inorder_successor
and inorder_predecessor
methods, except for the iterator returned by end()
. The end()
iterator is currently naively implemented, simply wrapping a null node.
In order to support decrementing the end iterator (i.e., end()--
), this seems to require some sort of dummy-max node to be maintained as a special right-child of the maximum node in the tree. This will probably not be too hard to implement, but it does interact with at least the tree's insert logic. We should consider doing it so that we can make the binary_search_tree<T>::iterator
support the std::bidirectional_iterator_tag
.
See src/datastructures/BST/README.md
Some cursory research shows that std::multiset::find
returns an iterator to the lowest node matching the given key. For example, this means if a tree consists only of one node value, but many duplicates of it, then the find(val)
operation will always return an iterator that equals begin()
.
I don't believe this repository's binary search tree implementation has the same lower-bound find guarantee, but we should check, change our implementation if necessary, and add tests regardless.
Some logic is being duplicated in different forms (primarily in regards to shifting elements) inside Vector::push_front()
mainly due to the conditional. Factor as much of the logic out of the condition al as possible so it only appears one time. The result of a size == capacity
check should only modify this->_data
so that after a resize, the problem can be put in terms of the average case where we know the vector has room to shift elements around.
The README should do a much better job describing exactly what is going on in this repository. Things include:
algorithm_practice
and datastructures
foldersproblem.cpp
and ojAns.cpp
and how to find the original problem description/submission page...the above is a running list and is definitely subject to change.
See: https://leetcode.com/problems/last-stone-weight/description/. It's a good problem about using a binary search tree / set, but also needing to keep track of occurrences/duplicates. You can use a map
or a multiset
for this, which is nice.
The data structure implementations in this repository should adhere to the Chromium & Google C++ Style Guide. See #133 (comment) and https://github.com/domfarolino/algorithms/blob/master/src/datastructures/README.md.
See: https://leetcode.com/problems/diameter-of-binary-tree/description/. It's a good problem about selectively propagating information up a tree's suspended stack frames.
The recursive binary search "first occurrence" and "last occurrence" variations index out of bounds given an empty array, producing undefined (usually fine though) behavior. This should be fixed. Perhaps in these binary search variants, since we will always come out of the while
loop before returning, we should perform size == 0
checks early on?
The algorithm maxTrianglePath
currently in Array_Algorithms/
seems to not produce .out
files that match the ground truth ones included in the repository. Probably something is overflowing or being indexed incorrectly but it should be looked into.
I have a ton of algorithms and datastructures I'll be committing to this repository over the next few weeks (and years) but if you have anything you'd like to add please do! Algorithms in this repository range from technical interview questions/answers, to online judge problems/solutions, and classic fundamental CS problems.
If it is useful, add whatever you'd like. I only ask that:
If you'd like to modify something that already exists in the repository go ahead. Useful changes shouldn't have an issue getting merged.
API-wise, both min()
and max()
should return iterators, and we should introduce the following methods:
begin()
: returns the result of min()
.end()
: returns an iterator pointing to nullptrfind()
: returns an iterator pointing to the a found value. Similar to exists()
, but with an iterator return valueA binary_search_tree<T>::iterator
should support the following operations:
Given iterator increment and decrement support, does that imply we want to mark the iterator as a bidirectional iterator? See #146
This was a cool problem, don't have time to add it right now, but I certainly should soon.
... we want this :)
Ones left are:
The documentation for this algorithm currently exists in the implementation file and we should move it out to a README.md file
The SLL class needs an iterator mechanism if we're going to ever use it as the underlying datastructure for the Stack and Queue (others) classes.
LC example of this is: https://leetcode.com/problems/middle-of-the-linked-list/description/
This is a basic and fundamental problem to solve when learning linked lists, so this could be added to the linked list data structure algorithms folder.
Look into running valgrind memory tests on travis for ease of PR.
There is an issue in the base case of the SLL/addTwoNumbers
algorithm. The algorithm should always return a brand new list (consisting of entirely separate memory from the input lists) even if one of the input lists was NULL
.
The reasoning for this is so a user of this algorithm does not have to worry about a double free
when freeing both input lists as well as the output list. As it stands, we're just returning one of the input lists if the other is NULL
, so if a consumer of this algorithm were to call deleteList(a)
and deleteList(outputList)
they might be trying to delete the same list twice. See screenshot of valgrind below:
We can get around this by simply making a copy of the one input list we're returning now. This yield a much safer implementation!
Look out for other issues with base cases like this in SLL algos
Find dynamic programming-related problems and solutions and move them out into their own Dynamic_Programming
folder. One known algorithm that can be moved is maxTrianglePath
.
The "rule of three" should really be implemented for the
classes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.