Posts

Showing posts with the label DataStructure-Algorithms

Data Structure in Java

Image
Types of Data Structures: A data structure is way of collecting and organizing data Choosing the right data structure impacts efficiency Data comes from many sources e.g. Database, Files etc. Many data structures are implemented using as Linked list (Stack, queue etc.) Array List: Stores objects and can grow or shrink Linked List: Uses pointers to keep track of elements Vector: Can grow or shrink, It provides synchronization Stack: Operates on Last In , First Out (LIFO) Queue: Operates on First In, First Out (FIFO) Array List and Vectors: Advantages: Provide fast access using indexing  Memory Coherence Provide an initial size (optional) User internal array for storage, which makes random access fast Disadvantages: Can be time consuming to add elements in the middle Waste space if array is not full Need to be resized when they reach capacity Slower when deleting elements from the middle Linked List: Advantages: Insertion and deletion operations are easily implemented Elements are ef...

Data structure and Algorithms - BIG O Cheat Sheet

Big O Cheat Sheet: -Big Os- 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 nth items O(n log(n)) Log Linear - Usually for 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) -What can cause time in a function? - Operations (+, -, *, /) Comparisons (<, >, ==) Looping (for, while) Outside Function call (function ()) -Rule Book- Rule 1: Always worst Case Rule 2: Remove Constants Rule 3: Different inputs should have different variables. O(a+b).  A and B arrays nested would be O(a*b) + for steps ...