Giter Site home page Giter Site logo

trunghieu-tran / leetcode-solutions-and-data-structure-analysis Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 7.0 2.12 MB

A collection of LeetCode novel solutions that is implemented in Java. An overview about data structure for interview questions

Home Page: https://leetcode.com

Java 100.00%
leetcode algorithm-challenges algorithms-datastructures data-structures algorithms solutions java leetcode-solutions leetcode-java big-o

leetcode-solutions-and-data-structure-analysis's Introduction

LeetCode Solutions in Java

A collection of LeetCode novel solutions that is implemented in Java. It would support you to solve the problems from easy to hard by the simplest ways.

Solutions LeeCode

# Problem Difficulty Source code Solution
1 Two Sum Medium Java 1. Hash O(n) and O(n) space.
2. Sort and search with two points O(n) and O(1) space.
2 Add Two Numbers Medium Java Take care of the carry from lower digit.
--- To-be-updated soon ---------- ----------- --------

Big O performance

Below are the Big O performance of common functions of different Java Collections.

List Add Remove Get Contains Next Data Structure
ArrayList O(1) O(n) O(1) O(n) O(1) Array
LinkedList O(1) O(1) O(n) O(n) O(1) Linked List
Set Add Remove Contains Next Size Data Structure
HashSet O(1) O(1) O(1) O(h/n) O(1) Hash Table
LinkedHashSet O(1) O(1) O(1) O(1) O(1) Hash Table + Linked List
EnumSet O(1) O(1) O(1) O(1) O(1) Bit Vector
TreeSet O(log n) O(log n) O(log n) O(log n) O(1) Red-black tree
ConcurrentSkipListSet O(log n) O(log n) O(log n) O(1) O(n) Skip List
  • Note: h is the table capacity
Queue Offer Peak Poll Remove Size Data Structure
PriorityQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
LinkedList O(1) O(1) O(1) O(1) O(1) Array
ArrayDequeue O(1) O(1) O(1) O(n) O(1) Linked List
ConcurrentLinkedQueue O(1) O(1) O(1) O(n) O(n) Linked List
ArrayBlockingQueue O(1) O(1) O(1) O(n) O(1) Array
PriorirityBlockingQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
SynchronousQueue O(1) O(1) O(1) O(n) O(1) None!
DelayQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
LinkedBlockingQueue O(1) O(1) O(1) O(n) O(1) Linked List
Map Get ContainsKey Next Data Structure
HashMap O(1) O(1) O(h / n) Hash Table
LinkedHashMap O(1) O(1) O(1) Hash Table + Linked List
IdentityHashMap O(1) O(1) O(h / n) Array
WeakHashMap O(1) O(1) O(h / n) Hash Table
EnumMap O(1) O(1) O(1) Array
TreeMap O(log n) O(log n) O(log n) Red-black tree
ConcurrentHashMap O(1) O(1) O(h / n) Hash Tables
ConcurrentSkipListMap O(log n) O(log n) O(1) Skip List

JAVA Collections Framework

alt text

Source: Suryaprakash R.

Sort Algorithm Comparison

alt text

Source: MCN Professionals

Contributors

Hieu Tran ([email protected])

leetcode-solutions-and-data-structure-analysis's People

Contributors

trunghieu-tran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.