GithubHelp home page GithubHelp logo

data-structure-and-algorithms's Introduction

Algorithmic Complexity and Common Operations

1. Representing Complexity

Asymptotic Notation

When analyzing algorithms, understanding asymptotic notations is crucial for describing their time and space complexity.

1.1 Big-O Notation (Worst Case Complexity)

Time Complexity
  • Constant: O(1)
  • Linear: O(n)
  • Quadratic: O(n^2)
  • Cubic: O(n^3)
  • Logarithmic: O(log n)
Space Complexity

1.2 Omega Notation (Best Case Complexity)

1.3 Theta Notation (Average Case Complexity)

2. Objects and Array Operations

Understanding common operations on objects and arrays is crucial for efficient algorithm design.

  • Insert / Remove at End
  • Insert / Remove at Beginning
  • Access
  • Search
  • Push / Pop
  • Shift / Unshift / Concat / Slice / Splice
  • forEach / map / filter / reduce

3. Mathematics Algorithms

  1. Fibonacci Sequence

    • Explanation: Series of numbers where each number is the sum of the two preceding ones.
    • Code Example: (JavaScript)
      function fibonacci(n) {
          if (n <= 1) return n;
          return fibonacci(n - 1) + fibonacci(n - 2);
      }
  2. Factorial of a Number

    • Explanation: Product of all positive integers up to a given number.
    • Code Example: (JavaScript)
      function factorial(n) {
          return n === 0 ? 1 : n * factorial(n - 1);
      }
  3. Prime Number

    • Explanation: A number greater than 1 not divisible by any other numbers except 1 and itself.
    • Code Example: (JavaScript)
      function isPrime(n) {
          // Implementation
      }
  4. Power of Two

    • Explanation: Numbers that can be expressed as 2^n.
    • Code Example: (JavaScript)
      function isPowerOfTwo(n) {
          // Implementation
      }
  5. Recursion

    • Explanation: A programming technique where a function calls itself.
    • Code Example: (JavaScript)
      function recursiveFunction() {
          // Implementation
          recursiveFunction(); // Call itself
      }
  6. Fibonacci Sequence with Recursion

    • Explanation: Calculating Fibonacci sequence using recursion.
    • Code Example: (JavaScript)
      function fibonacciRecursive(n) {
          // Implementation
      }
  7. Factorial of a Number with Recursion

    • Explanation: Calculating factorial using recursion.
    • Code Example: (JavaScript)
      function factorialRecursive(n) {
          // Implementation
      }

data-structure-and-algorithms's People

Contributors

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