SEARCHING and its forms

    by nikoo28

    What is Searching?

    In computer science, searching is the process of finding an item with specified properties among a collection of items. The items may be sorted as records in a database, simple data elements in arrays, text in files, nodes in trees, vertices and edges in graphs or may be elements of other search space.

    Why Searching?

    Searching is one of core computer science algorithms. We know that today’s computers store lot of information. To retrieve this information efficiently we need very efficient searching algorithms. There are certain ways of organizing the data which improves the search process. That means, if we keep the data is some proper order, it is easy to search the required element. Sorting is one of the techniques for making the elements ordered. We shall try to understand the different type of searching algorithms.

    Types of Searching

    The following are the types of searches which we will try to understand:-

    0 comments
    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Write a program to reverse an array.

    by nikoo28
    2 minutes read

    Iterative way: 1) Initialize start and end indexes. start = 0, end = n-1 2) In a loop, swap arr[start] with arr[end] and change start and end as follows. start = start +1; end = end – 1 Time Complexity: O(n) Recursive Way: 1) Initialize start and end indexes start = 0, end = n-1 2) Swap arr[start] with arr[end] 3) Recursively call reverse for rest of the array. Time Complexity: O(n)

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Counting Sort

    by nikoo28
    4 minutes read

    Counting sort is not a comparison sort algorithm. The sorting techniques that work on comparison are: Selection Sort Bubble Sort Insertion Sort Merge Sort Quick Sort The best time complexity you can achieve in any of these sorting techniques is . However, is some very specific cases, you can achieve an even faster computation time of . This is made possible by an assumption. We assume that the input data set is within a finite limit. For example, if you want to sort some characters of the English alphabet. You …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Shell sort

    by nikoo28
    3 minutes read

    Shell sort (also called diminishing increment sort) was invented by Donald Shell. This sorting algorithm is a generalization of insertion sort. Insertion sort works efficiently on input that is already almost sorted. In insertion sort, comparison happens between the adjacent elements. At most 1 inversion is eliminated for each comparison done with insertion sort. The variation used in shell sort is to avoid comparing elements until the last step of the algorithm. So, the last step of shell sort is to avoid comparing adjacent elements until the last step of …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    How to initialize an array to 0 in C ?

    by nikoo28
    2 minutes read

    In C, we declare an array as:- But by simply doing this declaration, the array is assigned all junk values. There can be many cases and situations when we need to initialize all the elements to ZERO (0) before we can make any further computations. The most naive technique to initialize is to loop through all the elements and make them 0. We have 3 other simple techniques as:- 1.>  Global variables and static variables are automatically initialized to zero. If we have an array at global scope it will …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: We are given an input string, and we need to find the character with the maximum frequency. Input:- “This is an sample string.” Output:- The character with maximum frequency is :- i The logic of this problem is very simple, we need to scan the string and store the frequency of each of the character. For this we can use the ASCII code of the characters which is a separate integer. Note that character are not only the English alphabets. !@#$ are also characters. To extend our program to …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Quick Sort

    by nikoo28
    6 minutes read

    This algorithm is one of the specific ones people generally have a problem to understand. We will try out best to simplify it and understand it.Basically quick sort comprises of these steps:- Choose a pivot element (it can be any random element in array) In one iteration keep all the numbers smaller to it on the left side and larger to it on the right side.(smaller numbers)_ _ _[PIVOT]_ _ _(larger numbers) Now we have the left sub-array of (small numbers) and the right sub-array (large numbers) Repeat steps 1 …

    0 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More