Data structure & algorithm using swift language.

How to Find a number which appears once and other numbers are twice ?

[Question]: In a given random array find a number which appears only single time Example : Random array input – [9,2,2,3,4,4,3] output = 9Solution: Step 1: Create a dictionary. Step 2: Create loop and fill the keys with element occurrence.Step 3: Create a loop and return the dictionary element which has only single occurrence .T …

How to Find a number which appears once and other numbers are twice ? Read More »

Quick Sort

Logic: Create a pivot element & arrange elements with two partitions, If the elements are lesser than pivot add it to left partition & if elements bigger than the pivot arrange it to right side of partition & make call recursively with the subarray found with same approach. Time Complexity: Avg O(n^2) .. Best: O(n …

Quick Sort Read More »

Merge Sort

Merge Sort is based on divide & conquer approach, first we divide array into two parts until we got single element then merge the single single element and create a subarray, Now merge two sorted subarray into single array likewise in final we got the final sorted array. In Conquer approach we have i, j …

Merge Sort Read More »

Insertion Sort

# Approach Assume two part of the array sorted & unsorted. Sorted start from 1 element A[0] & fills with unsorted one by one (A[1] to A[n-1]) Attached code with dry run.  In Insertion sort we sort using two sets. One is Sorted set Another is unsorted one. Initially we sorted is index 0 element …

Insertion Sort Read More »