Novice Programmer

MAKING HAND DIRTY BY WRITING CODES

Full width home advertisement

Learn C

Novice Programmer

Post Page Advertisement [Top]



What is Data Structure? Why should I learn Data Structure?

A Data Structure, as the name suggests, is a method to store data in a structured way so that it can be easily created, viewed, and managed.


Classification of Data Sturcture
Data Structures are generally classified into two classes:
  • Primitive Data Structures
  • Non-primitive Data Structures

    What is Stack?
    Stack is a linear data structure where the addition of new items and the removal of existing items always takes place at the same end. This end is commonly called as "top". As all the addition and removal in a stack is done from the "top" of the stack, the item added most recently will be removed first. Hence stack is called Last-In-First-Out(LIFO) data structure.

    Introduction to infix postix and prefix

    Conversion of Infix Expression to Postfix

    Let,
    Operator_Stack be empty stack to keep operators. Postfix_Expression be output.
    • Scan the expression from left to right.
    • If the scanned character is:
      • an operand, append it to the end of Postfix_Expression.
      • a left parentheses, push it on the Operator_Stack.
      • a right parentheses, pop the Operator_Stack until the corresponding` left parentheses is removed. Push every popped character to the end of the Postfix_Expression.
      • an operators like, x / + ^, push it on the Operator_Stack. Before that you need to move any operators on Operator_Stack having precedence greater than or equal to scanned operator to Postfix_Expression.
    Continue above steps until you get the final Postfix_Expression.


    Introduction to Abstract Data Types

    Computer Scientists uses the concept of abstraction to manage the complexity of a system or a problem. By abstraction we mean, specifying what it does, but not How it does. Applying the same concept of abstraction on the design of data structures give rise to abstract data types or ADTs.



How to Evaluate Postfix Expressions

As discussed earlier Computers Prefer Postfix Expressions over Infix Expressions. That is why given an algebraic expression written in infix, the computer first converts the expression into equivalent postfix expression.
Evaluating Postfix Expression make extensive use of stacks as a primary tool. Using stacks, any postfix expression can be evaluated very easily. Every character of the postfix expression is scanned from left to right. If the character encountered is an operand, it is pushed on to the stack. However, if an operator is encountered, then the top two values are popped from the stack and the operator is applied to these values. The result is then pushed on to the stack.
Consider the postfix expression 345x +. As you scan the expression from left to right, you first encounter the operands 3 and 4. Both of them are Operand, So no any operation is possible, so push them in stack until any operator is encountered. The next character 5 is also operator so check for next character Now we see an operator, x. This means that the two most recent operands need to be used in a multiplication operation. By popping the stack twice, we can get the proper operands and then perform the multiplication (in this case getting the result 20). We can now handle this result by placing it back on the stack so that it can be used as an operand for the later operators in the expression. When the final operator is processed(20+3=23), there will be only one value left on the stack. Pop and return it as the result of the expression.

Google Recursion Joke
Google likes to show some humor whenever possible. The search engine's "Did you mean" feature helps even the worst spellers locate useful results.
But when you type "recursion" into search box, it will apply the concept of recursion and will show you the same identical results no matter how many time you click the alternative "Recursion" text.
See the video for the illustration and try it for yourself.

Recursion vs Iteration

The main difference between recursion and iteration is that Recursion is the technique of defining anything in terms of itself while Iteration is a process of executing a statement or a set of statements repeatedly.
You can check full difference between them in Recursion vs Iteration



 

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib