Home Theory
Category:

Theory

View theory topics

  • Theory

    What are infix, postfix and prefix expressions?

    by nikoo28
    2 minutes read

    Stacks can be used to implement algorithms involving Infix, postfix and prefix expressions. So let us learn about them:- INFIX:- An infix expression is a single letter, or an operator, proceeded by one infix string and followed by another infix string. A A + B (A + B) + (C – D) PREFIX:- A prefix expression is a single letter, or an operator, followed by two prefix strings. Every prefix string longer than a single variable contains an operator, first operand and second operand A + A B + + …

    0 FacebookTwitterLinkedinWhatsappEmail
  • MiscTheory

    What is Segmentation Fault?

    by nikoo28
    3 minutes read

    From Wikipedia: A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, “segmentation fault” being an example. …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: What is the difference between doing:         ptr = (char **) malloc (MAXELEMS * sizeof(char *)); or:         ptr = (char **) calloc (MAXELEMS, sizeof(char*)); When is it a good idea to use calloc and when to use malloc ? There are two differences:- Firstly it is in the number of arguments, malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments. Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO. calloc() allocates a memory area, the length …

    0 FacebookTwitterLinkedinWhatsappEmail
  • MiscTheory

    What is an unsigned char?

    by nikoo28
    1 minutes read

    Question: In C, what is an unsigned char used for? How is this different from a regular char? In C, there are three distinct character types: char signed char unsigned char If you are using character types for text, use the unqualified char: it is the type of character literals like ‘a’ or ‘0’. it is the type that makes up C strings like “abcde” It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop ? i++ is known as Post Increment whereas ++i is called Pre Increment. ++i will increment the value of i, and then return the incremented value. i++ will increment the value of i, but return the original value that i held before being incremented. For a for loop, either works. ++i seems more common, perhaps because that is what is used in Dennis Ritchie. In …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    What is Backtracking?

    by nikoo28
    1 minutes read

    Backtracking is the method of exhaustive search using divide and conquer. Sometimes the best algorithm for a problem is to try all the possibilities. This is always slow, but there are standard tools that can be used for help. Tools: algorithms for generating basic objects, such as binary strings [2n possibilities for n-bit string], permutations [n!], combinations [n!/r!(n-r)!], general strings [k-ary strings of length  n has kn possibilities], etc… Backtracking speeds the exhaustive search by pruning. Example Algorithms of Backtracking Binary Strings: generating all binary strings Generating k-ary Strings. The …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Discuss the Tower Of Hanoi puzzle

    by nikoo28
    3 minutes read

    The tower of Hanoi is a mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks on one rod in ascending order of size, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, satisfying the following rules:- Only one disk can be moved at a time. Each move consists of taking the upper disk from one of the …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Recursion and Memory (Vizualization)

    by nikoo28
    1 minutes read

    Each recursive call makes a new copy of that method (more specifically speaking ‘the variables’) in memory. Once a method ends (i.e returns some data), the copy of that returning method is removed from the memory. The recursive solutions look simple but visualization and tracing takes time. For better understanding, let us see the following example. For this example. if we call the print function with n = 4, visually our memory assignment may look like this:- Now, let us consider our factorial function. The visualization of this will be:-

    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