Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R scripts #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Algorithms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

| Algorithm | Complexity | Implementations |
| --- | --- | --- |
| [Linear Search](#LinearSearch) | O(n) | <img src="https://img.shields.io/badge/-Python-blue"> <img src="https://img.shields.io/badge/-C-black"> <img src="https://img.shields.io/badge/-C++-grey"> <img src="https://img.shields.io/badge/-Java-red"> <img src="https://img.shields.io/badge/-PHP-purple"> |
| [Linear Search](#LinearSearch) | O(n) | <img src="https://img.shields.io/badge/-Python-blue"> <img src="https://img.shields.io/badge/-C-black"> <img src="https://img.shields.io/badge/-C++-grey"> <img src="https://img.shields.io/badge/-Java-red"> <img src="https://img.shields.io/badge/-PHP-purple"> <img src="https://img.shields.io/badge/-R-blue">8|
| [Binary Search](#BinarySearch) | Theta(logn) | <img src="https://img.shields.io/badge/-Python-blue"> <img src="https://img.shields.io/badge/-C-black"> <img src="https://img.shields.io/badge/-C++-grey"> <img src="https://img.shields.io/badge/-Java-red"> <img src="https://img.shields.io/badge/-PHP-purple">|
| [Ternary Search](#TernarySearch) | Theta(logn) | <img src="https://img.shields.io/badge/-C++-grey"> |
| [Jump Search](#JumpSearch) | O(sqrt(n)) | <img src="https://img.shields.io/badge/-Python-blue"> <img src="https://img.shields.io/badge/-C-black"> <img src="https://img.shields.io/badge/-C++-grey"> <img src="https://img.shields.io/badge/-Java-red"> <img src="https://img.shields.io/badge/-PHP-purple"> |
Expand Down Expand Up @@ -353,6 +353,7 @@
<!--
None yet: <img src="https://img.shields.io/badge/-None%20Yet-orange">
Python: <img src="https://img.shields.io/badge/-Python-blue">
R: <img src="https://img.shields.io/badge/-R-blue">
C: <img src="https://img.shields.io/badge/-C-black">
C++: <img src="https://img.shields.io/badge/-C++-grey">
Go: <img src="https://img.shields.io/badge/-Go-#7FFFD4"> // Aquamarine
Expand Down
25 changes: 25 additions & 0 deletions Algorithms/Searching/linearSearch.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Linear Search R implementation. O(n).
LinearSearch <- function (elements, x){
# elements : vector with the elements
# x : element to be found
if (length(elements)!= 0){
for (i in 1:length(elements)){
if (elements[i] == x){
return(i)
}
}
}
return(-1)
}

elements <- c(1, 3, 4, 5, 6, 8, 23, 43, 44, 45)
x <- 23

position <- LinearSearch(elements, x)

if (position[1] == -1){
print("The element has not been found")
} else {
sprintf("The element has been fount at position %d", position + 1)
}

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ python script.py

* <img src="https://img.shields.io/badge/-R-green"> :

```
Rscript script.R
```

* <img src="https://img.shields.io/badge/-C-black"> :

In case some flag is needed for the compiler, will be indicated in the script.
Expand Down Expand Up @@ -93,6 +97,7 @@ g++ script.cpp -o compiled/script
<!--
None yet: <img src="https://img.shields.io/badge/-None%20Yet-orange">
Python: <img src="https://img.shields.io/badge/-Python-blue">
R: <img src="https://img.shields.io/badge/-R-blue">
C: <img src="https://img.shields.io/badge/-C-black">
C++: <img src="https://img.shields.io/badge/-C++-grey">
Go: <img src="https://img.shields.io/badge/-Go-#7FFFD4"> // Aquamarine
Expand Down