Home Theory
Category:

Theory

View theory topics

  • Question: Given an array with n+2 elements, all elements of the array are in range 1 to n and also all elements occur only once except 2 numbers which occur twice. Find those 2 repeating numbers. Input: arr [ ] = {6, 2, 6, 5, 2, 3, 1} Output: 6 2 We discussed the method to find the 2 repeating element using 2 loops, but that method had a great time complexity and it was not at all an optimal solution. We can optimize it using a count array. This …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Different types of loops in C

    by nikoo28
    3 minutes read

    There are 3 loops in C: for, while, do-while. Here is a bit detail about them:- A while loop will always evaluate the condition first. A do/while loop will always execute the code in the do{} block first and then evaluate the condition. A for loop allows you to initiate a counter variable, a check condition, and a way to increment your counter all in one line. At the end of the day, they are all still loops, but they offer some flexibility as to how they are executed. For …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Linear Search

    by nikoo28
    4 minutes read

    Linear Search is probably the easiest searching technique that is available in computer programming. You simply need to iterate over each element in a list sequentially and compare if it matches the element to search. Searching is a prime concept, as it gives you a starting point to your code. Even in real life, if you plan to go to a movie, a vacation or a shopping mall, the first thing you do is search for a location. Similarly, in programming you could have a search for anything. Google has …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    SEARCHING and its forms

    by nikoo28
    1 minutes read

    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 …

    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
  • ArraysTheory

    SORTING and its types

    by nikoo28
    5 minutes read

    What is sorting? Sorting is an algorithm that arranges the elements of a list in a certain order (either ascending or descending, as per the requirement). The output is simply a permutation of the input data. Why sorting? Sorting is one of the most important categories of algorithms in computer science. Sometimes sorting significantly reduces the problem complexity. We can use sorting as a technique to reduce the search complexity. Great research went into this category of algorithms because of its importance. These algorithms are very much used in many …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    What is a priority queue?

    by nikoo28
    2 minutes read

    In some situations we might need to find the minimum/maximum element among a collection of elements. Priority Queue ADT is the one which supports these kind of operations. A priority queue ADT is a data structure that supports the operations Insert and DeleteMin (which returns and removes the minimum element) or DeleteMax (which returns and removes the maximum element). These operations are equivalent to EnQueue and DeQueue operations of a queue. The difference is that, in priority queues, the order in which the elements enter the queue may not be …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    How do pointers to pointers work in C?

    by nikoo28
    3 minutes read

    We generally see cases like:-Here ptr is a pointer to a memory location of the variable x. What if we do something likeWhat we did just now was made a pointer to a pointer. Now the question arises, what happens behind the scene? Let’s assume an 8 bit computer with 8 bit addresses (and thus only 256 bytes of memory). This is part of that memory (the numbers at the top are the addresses): What we can see here, is that at address 63 the string “hello” starts. So in …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Here what we are trying to learn is the difference between:- and The difference is that const char * is a pointer to a const char, while char * const is a constant pointer to a char. const char * :- In this, the value being pointed to can’t be changed but the pointer can be. char  * const :- In this, the value being pointed at can change but the pointer can’t. The third type is which is a constant pointer to a constant char (so nothing about it …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    What is a Queue?

    by nikoo28
    3 minutes read

    A queue is a linear data structure that stores data (similar to Linked Lists and Stacks). In a queue, the order in which the data arrives is important. Definition: A queue is an ordered list in which insertions are done at one end (rear) and deletions are done at other end (front). The first element that you insert, is the first one that is removed. This makes it a First In First Out (FIFO) or Last In Last Out (LILO) list. Basic Operations: The basic operations on this data structure …

    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