Coder Social home page Coder Social logo

rbinarysearch's Introduction

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

rbinarysearch's People

Contributors

rogercoll avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.