Skip to content

mihirpatankar/Java-Code-Samples

Repository files navigation

Java Code Samples

Searching and Sorting Algorithms

  • Selection Sort --> O(n2)
  • Insertion Sort --> O(n2)
  • Binary Search (Iterative and Recursive) --> O(logn)

Linked Lists

  • Print Linked List --> O(n)
  • Append Node --> O(n)
  • Delete Node at end --> O(n)
  • Prepend Node --> O(1)
  • Delete Node at head --> O(1)
  • Reverse Linked List --> O(n)
  • Detect Cycle--> O(n)

Binary Search Trees

  • Check Same Tree --> O(n)
  • Check Symmetry --> O(n)
  • Maximum Depth of BST --> O(n)
  • Recursive Traversal (inOrder, preOrder, postOrder) --> O(n)
  • Validate BST --> O(n)

Stack

  • Check Valid Paranthesis --> O(n)

Arrays

  • Remove Element --> O(n)
  • Remove Duplicates from Sorted Array --> O(n)
  • Two Sum --> O(n)
  • Max Consecutive Ones --> O(n)
  • Spiral Matrix --> O(n2)
  • Search Insert Position --> O(logn)
  • Rotate Image --> O(n2)

Strings

  • Valid Palindrome --> O(n)

Tries

n=number of words, l=average length of each word

  • Insert words --> O(l x n)
  • Prefix Search --> O(l)
  • Complete Word Search --> O(l)
  • Delete Word --> O(l x n)

Others

  • Recursive Integer Multiplication --> O(n2)
  • Karatsuba Multiplication --> O(n1.59)

About

Java Code Samples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages