Skip to content

Commit 3c363e8

Browse files
authored
Merge branch 'master' into master
2 parents 3e3b3f6 + eab8ce6 commit 3c363e8

File tree

14 files changed

+196
-8
lines changed

14 files changed

+196
-8
lines changed

Contributor.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This is a repo created to remember the Hacktober Fest organized by Github, Digit
77
* [Your Name](http://yourgithuburl) | [Your School/Uni](https://www.youruniurl/)
88
* [Saurav Jaiswal](https://github.com/sauravjaiswalsj) | [Sathyabama Institute of Science and Technology](http://www.sathyabama.ac.in/)
99
* [Foxxy](https://github.com/foxxydev) | ["Aurel Vlaicu" University of Arad](http://www.uav.ro)
10+
* [Tejas Tank](https://github.com/majordwarf) | [Thakur College of Science and Commerce](http://tcsc.org.in/)
1011

1112

1213

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Welcome to the SCC-SIST-Algorithms
1+
## Welcome to the Algorithms-Hacktoberfest by Fnplus
22

33
This repository is a part of [ HacktoberFest -an event organised by DigitalOcean ](https://hacktoberfest.digitalocean.com/).
44
You are requested to create your profile using the above link to be a part of it.
@@ -39,6 +39,7 @@ This repository contains examples of various algorithms written on different pro
3939
| C | <pre>gcc [filename.c]<br>./a.out # unix<br>a.exe # windows</pre> |
4040
| CPP | <pre>g++ [filename.cpp]<br>./a.out # unix<br>a.exe # windows</pre> |
4141
| Java | <pre>javac [filename.java]<br>java [filename]</pre> |
42+
| golang | <pre>go build [filename.go]<br>[./filename]</pre> |
4243

4344

4445
## Contributing

binary_search/clang/binary_search.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//add your code here
1+
//add your code here

binary_search/cpp/binary_search.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// add your code here
2-
1+
// add your code here

binary_search/java/binary_search.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
// add your code here :
1+
/**
2+
* Returns index of value in values array or -1 if array doesn't contain specified element
3+
* @param values array with integers to search in
4+
* @param value integer value to search in values
5+
* @param start first index of array to search in
6+
* @param end last index of array to search in
7+
*/
8+
public int binary_search(int [] values, int value, int start, int end) {
9+
if(end >= 1) {
10+
int middle = (start+end)/2;
11+
if(values[middle] == value)
12+
return middle;
13+
14+
if (values[middle] > value)
15+
return binary_search(values, value, start, middle-1);
16+
else
17+
return binary_search(values, value, middle+1, end);
18+
}
19+
20+
return -1;
21+
}

binary_search/python/binary_search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# add your code here
1+
# add your code here

counting_sort/cpp/counting_sort.cpp

+54-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
//add your code here
1+
/* Created by SubCoder1 on 31-May-18.
2+
3+
Sorting Technique -- Counting Sort
4+
Input -- A sequence of n numbers
5+
Output -- Reordered into a definite sequence {Ascending(HERE)}
6+
7+
Time Complexity :-
8+
Worst Case - O(N^2)
9+
Best Case - O(N + RANGE)
10+
*/
11+
12+
13+
14+
15+
16+
#include <iostream>
17+
#include <vector>
18+
#include <algorithm>
19+
#include <chrono>
20+
21+
using namespace std::chrono;
22+
using namespace std;
23+
24+
int main(){
25+
int inpt;
26+
vector<int> store;
27+
vector<int>:: iterator it;
28+
29+
cout << "Unsorted Input -- ";
30+
while(cin.peek() != '\n'){
31+
cin >> inpt;
32+
store.push_back(inpt);
33+
}
34+
35+
auto start = high_resolution_clock::now();
36+
37+
it = max_element(store.begin(), store.end());
38+
int range = *it;
39+
vector<int> aux(range, 0);
40+
41+
for(auto i: store){ aux[i-1]+=1; }
42+
43+
cout << "Sorted Output -- ";
44+
for(int i = 0; i < range; i++){
45+
for(int j = 1; j <= aux[i]; j++){
46+
cout << i+1 << " ";
47+
}
48+
}
49+
50+
auto end = high_resolution_clock::now();
51+
52+
cout << "Time Elapsed -- " << duration_cast<microseconds>(end - start).count() << " microS.\n";
53+
54+
}
File renamed without changes.
File renamed without changes.

fibonacci/golang/fibonacci.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package golang
2+
3+
func fib(n int) []int {
4+
seq := []int{1, 1}
5+
for len(seq) < n {
6+
i := len(seq)
7+
seq = append(seq, seq[i-1]+seq[i-2])
8+
}
9+
return seq[:n]
10+
}

fibonacci/golang/fibonacci_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package golang
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func Test_fib(t *testing.T) {
9+
type args struct {
10+
n int
11+
}
12+
tests := []struct {
13+
name string
14+
args args
15+
want []int
16+
}{
17+
{
18+
name: "Passing 0 as the args",
19+
args: args{n: 0},
20+
want: []int{},
21+
},
22+
{
23+
name: "Passign legit number",
24+
args: args{n: 2},
25+
want: []int{1, 1},
26+
},
27+
{
28+
name: "Passign legit number",
29+
args: args{n: 5},
30+
want: []int{1, 1, 2, 3, 5},
31+
},
32+
}
33+
for _, tt := range tests {
34+
t.Run(tt.name, func(t *testing.T) {
35+
if got := fib(tt.args.n); !reflect.DeepEqual(got, tt.want) {
36+
t.Errorf("fib() = %v, want %v", got, tt.want)
37+
}
38+
})
39+
}
40+
}
File renamed without changes.

fibonacci/python/fibonacci.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def fib(n):
2+
sequence = [1, 1]
3+
while (len(sequence) < n):
4+
i = len(sequence)
5+
sequence.append(
6+
sequence[i-1] +
7+
sequence[i-2]
8+
)
9+
10+
return sequence[:n]
11+
12+
# fib(2) -> [1, 1]
13+
# fib(5) -> [1, 1, 2, 3, 5]
14+
# fib(10) -> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

merge_sort/java/merge_sort.java

+51-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1-
// add your code here :
1+
public class MergeSort {
2+
private static int[] exArray;
3+
public static void sort(int[] arrayToSort){
4+
exArray = new int[arrayToSort.length];
5+
mergeSort(arrayToSort,0,arrayToSort.length-1);
6+
}
7+
8+
private static void mergeSort(int[]array,int leftIndex,int rightIndex){
9+
if(leftIndex<rightIndex)
10+
{
11+
int middleIndex = (leftIndex+rightIndex)/2;
12+
mergeSort(array,leftIndex,middleIndex);
13+
mergeSort(array,middleIndex+1,rightIndex);
14+
merge(array,leftIndex,middleIndex,rightIndex);
15+
}
16+
}
17+
private static void merge(int[]array,int leftIndex,int middleIndex, int rightindex){
18+
for(int i=leftIndex;i<=rightindex;i++)
19+
{
20+
exArray[i]=array[i];
21+
}
22+
23+
int pointer1 = leftIndex;
24+
int pointer2 = middleIndex+1;
25+
int current = leftIndex;
26+
while(pointer1 <= middleIndex && pointer2<=rightindex)
27+
{
28+
Main.iterationCounter++;
29+
if(exArray[pointer1]<=exArray[pointer2])
30+
{
31+
array[current] = exArray[pointer1];
32+
pointer1++;
33+
}
34+
else
35+
{
36+
37+
array[current] = exArray[pointer2];
38+
pointer2++;
39+
}
40+
current++;
41+
}
42+
while(pointer1<= middleIndex){
43+
array[current] = exArray[pointer1];
44+
pointer1++;
45+
current++;
46+
47+
}
48+
49+
}
50+
51+
}

0 commit comments

Comments
 (0)