Skip to content

Commit

Permalink
Update description comments to match format
Browse files Browse the repository at this point in the history
Underline headings and remove trailing colons, as per the format in issue #8.
  • Loading branch information
janos-laszlo authored and faheel committed Jul 11, 2017
1 parent ec5e6d9 commit 0bead6c
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Backtracking/N-Queens.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
N-Queens problem
-----------------
----------------
Find a way to place N non-attacking queens on an N×N chessboard
Time complexity
----------------
---------------
O(N!), where N is the number of queens
Space complexity
-----------------
----------------
O(1), constant amount of extra space
*/

Expand Down
9 changes: 6 additions & 3 deletions NumberTheory/Fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/*
Fibonacci number:
Fibonacci number
-----------------
Find the N-th Fibonacci number, given the value of N.
(The Fibonacci sequence is characterized by the fact that every number
after the first two is the sum of the two preceding ones.)
Time complexity:
Time complexity
---------------
O(N), where N is the term of the Fibonacci sequence to calculate
Space complexity:
Space complexity
----------------
O(1), constant amount of extra space
*/

Expand Down
9 changes: 6 additions & 3 deletions NumberTheory/GCD.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/*
Euclid's GCD algorithm:
Euclid's GCD algorithm
----------------------
Basic Euclidean Algorithm is used to find GCD of two numbers say a and b.
The Euclidean algorithm is based on the principle that the greatest common divisor
of two numbers does not change if the larger number is replaced by its difference with
the smaller number.
Below is a recursive C++ function to evaluate gcd using Euclid’s algorithm.
Time complexity:
Time complexity
---------------
O(log10(M)), where M = min(A, B) is the smaller of the input integers A and B
Space complexity:
Space complexity
----------------
O(1)
*/

Expand Down
9 changes: 6 additions & 3 deletions NumberTheory/SimpleSieve.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/*
Prime numbers using simple Sieve of Eratosthenes:
Prime numbers using simple Sieve of Eratosthenes
------------------------------------------------
Given a number N, find all prime numbers upto N (inclusive) using the simple
Sieve of Eratosthenes method, which efficiently finds primes in the order of
10^7. (The efficiency limit is due to poor cache utilisation.)
Time complexity:
Time complexity
---------------
O(N * log(log(N))), where N is the number upto which primes have to be found
Space complexity:
Space complexity
----------------
O(N), where N is the number upto which primes have to be found
*/

Expand Down
9 changes: 6 additions & 3 deletions String/LCS.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
Longest common subsequence algorithm:
Longest common subsequence algorithm
------------------------------------
Given two strings, find their longest common subsequence (not sub-string).
A classic dynamic programming algorithm for string processing.
Time complexity:
Time complexity
----------------
O(M*N), where M and N are the lengths of the two strings.
Space complexity:
Space complexity
----------------
O(M*N), where M and N are the lengths of the two strings.
*/

Expand Down
9 changes: 6 additions & 3 deletions String/Searching/KMP.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/*
Knuth-Morris-Pratt (KMP) algorithm:
Knuth-Morris-Pratt (KMP) algorithm
----------------------------------
A string searching algorithm that searches for a given "pattern" in a "text".
It uses the fact that when a mismatch occurs, one can jump further in the text
than a naive algorithm would (i.e. 1 step). The KMP algorithm can jump up to
all the length of the search pattern.
Time complexity:
Time complexity
---------------
O(N + M), where N is the pattern size and M is the text size.
Space complexity:
Space complexity
----------------
O(N), where N is the pattern size.
*/

Expand Down
55 changes: 39 additions & 16 deletions Trees/BinarySearchTree.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
Author:
Author
------
Varun Jayathirtha (www.github.com/varunjm)
Binary Search Tree:
Binary Search Tree
------------------
A graph data structure where each node has a unidirectional path to at most
two node, none of which are itself or its predecessors, i.e the graph is
acyclic. The first node is called the root node. Another important feature
Expand Down Expand Up @@ -31,17 +33,20 @@ BinarySearchTree::BinarySearchTree() {

/*
Insert
------
This traverses the tree to find the right spot to insert the newly given
value. At each node, it checks if the node has a value lesser than or equal
to itself, if so it goes to its left subtree. Otherwise it goes to the right
subtree. When it meets an end point i.e. NULL it inserts the new Node along
with the new value
Time complexity:
Time complexity
---------------
Average case : O(log n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity:
Space complexity
----------------
O(1)
*/

Expand Down Expand Up @@ -83,15 +88,21 @@ bool BinarySearchTree::insert(int value) {

/*
Remove
------
This traverses the tree to find the given value. At each node, it checks if
the node has a value equal to the given value, if so it finds the inorder
successor of the node, and replaces the value to be deleted with that number.
Otherwise, it searches in the left subtree if the value is smaller than
node value and it searches the right subtree if the value is larger.
Time complexity:
Time complexity
---------------
Average case : O(log n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity
----------------
O(1)
*/

bool BinarySearchTree::remove(int value) {
Expand Down Expand Up @@ -166,17 +177,20 @@ void BinarySearchTree::remove_current_node(Node* current, Node* parent) {

/*
Search
------
This traverses the tree to find the presence of number in the tree. At each
node, it checks if the node has a value lesser than itself, if so it goes
to its left subtree. If it is greater it goes to the right subtree. When it
node with the matching value or reaches the end of the tree it returns either
true or false appropriately.
Time complexity:
Time complexity
---------------
Average case : O(log n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity:
Space complexity
----------------
O(1)
*/

Expand All @@ -203,17 +217,20 @@ bool BinarySearchTree::search(int value) {
}

/*
In order traversal:
Inorder traversal
-----------------
This Algorithm visits and displays each node in the following order starting
with the root node. The Left subtree, followed by Parent, followed by the
Right subtree. This traversal gives the values stored in the tree in a
sorted order.
Time complexity:
Time complexity
---------------
Average case : O(n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity:
Space complexity
----------------
O(n), where n is the number if nodes in the tree
*/

Expand Down Expand Up @@ -256,16 +273,19 @@ void BinarySearchTree::traversal_inorder_iterative() {
}

/*
Pre order traversal:
Preorder traversal
------------------
This Algorithm visits and displays each node in the following order starting
with the root node. Parent, followed by the Left subtree, followed by the
Right subtree.
Time complexity:
Time complexity
---------------
Average case : O(n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity:
Space complexity
----------------
O(n), where n is the number if nodes in the tree
*/

Expand Down Expand Up @@ -309,16 +329,19 @@ void BinarySearchTree::traversal_preorder_iterative() {
}

/*
Pre order traversal:
Postorder traversal
-------------------
This Algorithm visits and displays each node in the following order starting
with the root node. The Left subtree, followed by the Right subtree,
followed by the Parent.
Time complexity:
Time complexity
---------------
Average case : O(n), where n is the number of nodes in the tree
Worst case : O(n)
Space complexity:
Space complexity
----------------
O(n), where n is the number if nodes in the tree
*/

Expand Down

0 comments on commit 0bead6c

Please sign in to comment.