1.1.13 • Published 6 years ago

rbinarysearch v1.1.13

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Binary Search

Status

Basic binary search implementation that works with integers and string. Also known as dichotomic search problem. The first r, is because of the recursive implementation of this algorithm.

In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.

Binary search runs in at worst logarithmic time, making O(log n) comparisons, where n is the number of elements in the array, the O is Big O notation, and log is the logarithm.

Requirements

  • Npm and Nodejs

Installation

Works with any Nodejs version:

npm install rbinarysearch

Usage

Basic example:

var rvector = require('rbinarysearch');

var test = new rvector();
var values = [1,-2,13,4,5,6,7,23,9,0]; //Can also be a strings vector ex: ["hi","abc,"roger"]

//Adding values
test.addElems(values);
test.addElems(6); //"hello" if its an array of strings

//Deleting elements
var aux = [9,-2,23,13,123,0];
test.deleteElems(aux);
test.deleteElems(6);

//Binary Search
var pos = test.binarysearch(13); //if array of strings "roger"
console.log(pos);

//Info
var actual_array = test.getvec();
test.printVec(); //it's a console log of the array
1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

1.0.0

6 years ago