Coder Social home page Coder Social logo

mehmetpekdemir / data-structures-and-algorithms Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 139 KB

Data Structures and Algorithms with Java

Home Page: https://github.com/mehmetpekdemir/Data-Structures-and-Algorithms

Java 100.00%
algorithms-and-data-structures arrays big-o-notation sort-algorithms lists stacks queues hashtables search-algorithms trees

data-structures-and-algorithms's Introduction

Data-Structures-and-Algorithms

Big - O Notation

Notation Name
O(1) Constant
O(logn) Logarithmic
O(n) Linear
O(nlogn) n log-star n
O(n^2) Quadratic

Big O Notation

Array

Operation Time Complexity
Retrieve with index. O(1) - Constant time
Retrieve without index. O(n) - Linear time
Add an element to full array. O(n) - Linear time
Add an element to the end of an array. (has space) O(1) - Constant time
Insert or update an element at a specific index. O(1) - Constant time
Delete an element by setting it to null. O(1) - Constant time
Delete an element by shifting elements. O(n) - Linear time

Time Complexities of all Sorting Algorithms

Bubble Sort
Performance Time Complexity
Worst Case O(n^2) - Quadratic time
Avarage Case O(n^2) - Quadratic time
Best Case O(n) - Linear time
Selection Sort
Performance Time Complexity
Worst Case O(n^2) - Quadratic time
Avarage Case O(n^2) - Quadratic time
Best Case O(n^2) - Quadratic time
Insertion Sort
Performance Time Complexity
Worst Case O(n^2) - Quadratic time
Avarage Case O(n^2) - Quadratic time
Best Case O(n) - Linear time
Shell Sort
Performance Time Complexity
Worst Case O(n^2) - Quadratic time
Avarage Case O(nlogn) - n log-star n
Best Case O(nlogn) - n log-star n
Merge Sort
Performance Time Complexity
Worst Case O(nlogn) - n log-star n
Avarage Case O(nlogn) - n log-star n
Best Case O(nlogn) - n log-star n
Quick Sort
Performance Time Complexity
Worst Case O(n^2) - Quadratic time
Avarage Case O(nlogn) - n log-star n
Best Case O(nlogn) - n log-star n
Counting Sort
Performance Time Complexity
Worst Case O(n+k)
Avarage Case O(n+k)
Best Case O(n+k)
Radix Sort
Performance Time Complexity
Worst Case O(kn)
Avarage Case O(kn)
Best Case O(kn)

Performance analysis of ArrayList, LinkedList and Vector

ArrayList
Operation Time Complexity
Insert at last index O(1) --> If array copy operation is Considered then O(n)
Insert at given index O(n)
Search by value O(n) ( Preferred )
Get by index O(1) ( Preferred )
Remove by value O(n)
Remove by index O(n)
ArrayList<Employee> employees = new ArrayList<>();
LinkedList
Operation Time Complexity
Insert at last index O(1) ( Preferred )
Insert at given index O(n) ( Preferred )
Search by value O(n)
Get by index O(n)
Remove by value O(n) ( Preferred )
Remove by index O(n) ( Preferred )
LinkedList<Employee> employees= new LinkedList<>();
Vector

Vector : Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.

Performance: ArrayList is faster, since it is non-synchronized, while vector operations give slower performance since they are synchronized (thread-safe).

Vector<Employee> employees = new Vector<>();

Stack

LIFO (Last-in-first-out)

ArrayStack
Operation Time Complexity
Push O(n)
Pop O(1)
Peek O(1)
LinkedStack
Operation Time Complexity
Push O(1)
Pop O(1)
Peek O(1)

Search Algorithms

Linear Search
Operation Time Complexity
Search O(n)
Binary Search
Operation Time Complexity
Search O(logn)

Queue

FIFO (First-in-first-out)

Array implementation of queue
Operation Time Complexity
Add O(1)
Remove O(n)
Peek O(1)
LinkedList implementation of queue
Operation Time Complexity
Add O(1)
Remove O(1)
Peek O(1)

Binary Search Tree ( BST )

Operation Time Complexity
Insertion O(logn)
Deletion O(logn)
Retrieval O(logn)

data-structures-and-algorithms's People

Contributors

alphavs-76 avatar mehmetpekdemir avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

isambtb faikturan

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.