Giter Site home page Giter Site logo

optimization-problems's Introduction

Optimization Problems

A set of interesting short optimization problems, with solutions in C++.

Two Array Median

Given two sorted arrays with lengths M and N, find their median in O(M + N) time.

> g++ two_array_median.cpp -std=c++17 -o two_array_median
> ./two_array_median

Unique Letter Words

Find all sets of 5 5-letter English words that do not share or repeat any letters. The inspiration is taken from this video. The problem can be abstracted to M N-letter words. The word bank used has 370106 words, and 831 solutions were found in 136 seconds.

The solution works by:

  • Filtering words with different lengths
  • Filtering words with repeating letters
  • Caching anagrams and leaving only one representative word
  • Creating a 26-ary tree dictionary
  • Recursively searching through the tree, while skipping all already taken letters, utilizing multithreading

Parameters: number of words, word length, thead count, path to a new line-delimited dictionary file, output file

> g++ unique_letter_words.cpp -std=c++17 -pthread -o unique_letter_words
> ./unique_letter_words 5 5 15 dictionary_en_370105.txt output.txt

optimization-problems's People

Contributors

nikolajov96 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.