Git Product home page Git Product logo

cracking-the-coding-interview's Introduction

cracking-the-coding-interview

Repository to practice examples of Cracking The Coding Interview but in Rust language

Amortised Time

If you do an operation say a million time, you don't really care about the worse-case or the best-case of that operation - what you care about is how much tiem is taken in total when you repeat the operation a million times. So it doesn't matter if the operation is vbery slow once in a while, as long as "once in a while" is rare enough for the slowness to be diluted away. Essentially amortised time means "average time taken per operation, if you do many operations". Amortised time doesn't have to be constants, you can have linear and logarithmic amortised time or whatever else.

Let's take mats' example of dynamic array, to which you repeatedly add new items. Normally adding an item takes constant time (that is, O(1)). But each time array is full, you allocate twice as much space, copy your data into the new region, and free the old space. Assuming allocates and frees run in constant time, this enlargement process take O(n) time where n is the current size of the array. So each time you enlarge, you take abouit twice as much time as the larst enlarge. But you've also waited twice as long before doing it! The cost of each enlargerment can thus be "spread out" amoung insertions. this means that in the long term, the total time taken for adding m items to the array is O(m), and so the amortised time (i.e per insertion) is O(1)

Log N Runtime

Tip

When you see a problem where the number of elements in the problem space gets halved each time, that will likely be a O(log N) runtime
this is the same reason why finding an element in a balanced binary search tree is O(log N). With each comparation, we go either left or right.
Half the nodes are on each side. so we cut the problem space in half each time(Tha bse doesn't matter infor the purposes of Big O             )

Space Complexity (Cap 6)

Space Complexity In Rust

Big O Complexity

Big O Complexity

cracking-the-coding-interview's People

Contributors

mateovelilla avatar

Watchers

 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.