Code Monkey home page Code Monkey logo

data-structures-algorithm's Introduction

Data Structures & Algorithm

Run time complexity(Big O)

  • O(1) Constant – no loops.
  • O(log N) Logarithmic – usually searching algorithms have log n if they are sorted (Binary Search).
  • O(n) Linear – for loops, while loops through n items.
  • O(n log(n)) Log Linear – usually sorting operations.
  • O(n^2) Quadratic – every element in a collection needs to be compared to ever other element. Two nested loops.
  • O(2^n) Exponential – recursive algorithms that solves a problem of size N.
  • O(n!) Factorial – you are adding a loop for every element.
  • Iterating through half a collection is still O(n).
  • Two separate collections: O(a * b).

Space complexity(Big O)

What causes Space Complexity

  • Variables
  • Data Structures
  • Function Call
  • Allocations

Screenshot (46)

Screenshot (47)

Screenshot (45)

Screenshot (44)

Built-in DataStructures

Quick Note using Python programming language as a reference.

Array

It is a collections of data type stored contiguous memory locations(ordered collections of values) operation run time complexity

  - Insertion : O(n)
  - Deletion : O(n)
  - accessing by index: O(1)
  - Append : O(1)

Hash Table or dictionary

It is unordered data structure that stores pairs of key-value operation run time complexity

  - accessing by key : O(1)
  - Insertion: O(1)
  - Deletion: O(1)

tuple

It is ordered collection of data type and being used for immutable things (that don't change).

operation run time complexity

 - access by index O(1)

sets

It is unorederd collection of unique elements.

operation run time complexity

 - Insertion: O(1)
 - Deletion: O(1)

self-defined DataStructures

Linked Lists

A linked list is a common data structure made of one or more than one node. Each node contains a value and a pointer to the previous/next node forming the chain-like structure

  operation run time complexity
  
    - prepend: O(1)
    - append: O(1)
    - lookup: O(n)
    - insert: O(n)   
    - delete: O(n)

singly linked list

a linear data structure comprising of nodes chained together in a single direction. Each node contains a data member holding useful information, and a pointer to the next node. Can traverse forward

LLdrawio

Doubly linked list

A doubly linked list contains a pointer to the next node as well as the previous node. This ensures that the list can be traversed in both directions(forward and backward).

DLL1

Stacks

Stack is a linear data structure in which the element inserted last is the element to be deleted first. LIFO method(Last In First Out)

operation run time complexity

  - push: O(1)
  - pop: O(1)

stack

queue

similar to a stack. A queue uses the FIFO method(First In First Out), by which the first element that is enqueued will be the first one to be dequeued. operation run time complexity

  - enqueue Inserts an element to the end of the queue: O(1)
  - dequeue Removes an element from the start of the queue: O(1)
  - isempty Returns true if the queue is empty: O(1)
  - peek Returns the first element of the queue: O(1)

queue

Tree

Graph

data-structures-algorithm's People

Contributors

fordpipatkittikul avatar

Stargazers

Wei Ching Lim 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.