GithubHelp home page GithubHelp logo

algos-backend's Introduction

algos-backend

API for https://github.com/kunalpanchal/algos-frontend based on Node.JS

Algo (Frequent Words Count)

Run locally and test

cd algos-backend && npm i && npm start

For testing run :

npm run test

alt screenshot-1

Routes

GET /get-frequent-words?input=99
GET /get-frequent-words?input=99&useRedis=true

Pseudo Code

1.Check if request inputs are valid

2.If useRedis is not specified and perform a get request to the URL and get the raw data.

3.Perform data sanitization

* replace all the newline,tabs and return carriages
* replace special characters with space
* replace numbers with space
* replace multiple spaces with a single space
* trim the data 

4.Split the data with a space and save it to a arr.

5.Create a hashMap from array with frequency saved as its value.

6.Sort the hashmap.

7.Return the required number of top frequencies

Complexity

n = total number of words in the file test.txt

m = total number of unique words in the file test.txt

COMPLEXITY => O( n + m + mlog(m) ) => O( n + mlog(m) )

The use of Redis

Whenever the values are computed using the above algorithm, they are saved to Redis.And it can be used to retrieve the data faster.Speed comparisson:

Without Redis With Redis

Dependencies Used

"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"cors": "^2.8.4",
"dotenv": "^4.0.0",
"express": "~4.15.2",
"express-promise-router": "^2.0.0",
"redis": "^2.8.0"

// Dev Dependencies
"chai": "^4.1.2",
"chai-http": "^3.0.0",
"mocha": "^4.0.1"

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.