Used To Find A Specific Item or Element Within A Collection of Data
Used To Find A Specific Item or Element Within A Collection of Data
A data structure is a storage that is used to store and organize data. It is a way of arranging data on a
computer so that it can be accessed and updated efficiently.
Types of DSA :
Array
Queue
Stack
Linked List
Hash Map
Tree
Graph
Linear Search Working : A linear search algorithm works by sequentially checking each element of
the array from start to end until the desired element is found or all elements have been checked. It starts at the
first element of an array and moves element to element in a linear fashion.
Binary Search Working : Binary search compares the target value to the middle element of the array.
If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining
half, again taking the middle element to compare to the target value, and repeating this until the target value is
found.
Sorting : rearrangement of a given array or list of elements according to a comparison operator on the
elements.
Types :
Selection Sort
Bubble Sort
Insertion Sort
Merge Sort
Quick Sort
Heap Sort
Counting Sort
Radix Sort
Selection Sort working : Selection sort works by taking the smallest element in an unsorted array
and bringing it to the front. You'll go through each item (from left to right) until you find the smallest one.
Bubble Sorting working : Bubble sort is a sorting algorithm that starts from the first element of an
array and compares it with the second element. If the first element is greater than the second, we swap them. It
continues this process until the end of the array.
Insertion sort Working : iterates, consuming one input element each repetition, and grows a sorted
output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs
within the sorted list, and inserts it there. It repeats until no input elements remain.
Merge Sort Working : Merge sort is one of the most efficient sorting algorithms. It is based on the
divide-and-conquer strategy. Merge sort continuously cuts down a list into multiple sublists until each has only one
item, then merges those sublists into a sorted list.
Quick Sort Working : QuickSort is a sorting algorithm that uses a divide-and-conquer strategy to sort
an array. It does so by selecting a pivot element and then sorting values larger than it on one side and smaller to
the other side, and then it repeats those steps until the array is sorted. It is useful for sorting big data sets.
Heap Sort Working : The heapsort algorithm begins by rearranging the array into a binary max-heap.
The algorithm then repeatedly swaps the root of the heap (the greatest element remaining in the heap) with its last
element, which is then declared to be part of the sorted suffix.
Counting Sort Working : Counting sort is an integer sorting algorithm used in computer science to
collect objects according to keys that are small positive integers. It works by determining the positions of each key
value in the output sequence by counting the number of objects with distinct key values and applying prefix sum
to those counts.
Radix Sort Working : Radix sort works by sorting each digit from least significant digit to most
significant digit. So in base 10 (the decimal system), radix sort would sort by the digits in the 1's place, then the 10's
place, and so on. To do this, radix sort uses counting sort as a subroutine to sort the digits in each place value.
Array : An array is a linear data structure that collects elements of the same data type and stores them in
contiguous and adjacent memory locations. Arrays work on an index system starting from 0 to (n-1), where n is the
size of the array.
Linked List Working : A linked list is the most sought-after data structure when it comes to handling
dynamic data elements. A linked list consists of a data element known as a node. And each node consists of two
fields: one field has data, and in the second field, the node has an address that keeps a reference to the next node.
Stack Working : A Stack is a linear data structure that holds a linear, ordered sequence of elements. It is an
abstract data type. A Stack works on the LIFO process (Last In First Out), i.e., the element that was inserted last will
be removed first.
Queue Working : A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. It
operates like a line where elements are added at one end (rear) and removed from the other end (front).
Hash Map Working : HashMap use singly linked list to store elements, these are called bins or
buckets. When we call put method, hashCode of key is used to determine the bucket that will be used to store the
mapping. Once bucket is identified, hashCode is used to check if there is already a key with same hashCode or not.