Primitive Data Structures: 2. Types of Data Structure?
Primitive Data Structures: 2. Types of Data Structure?
Primitive Data Structures: 2. Types of Data Structure?
1. What is ds?
Data structure is a storage that is used to store and organize data. It
is a way of arranging data on a computer so that it can be accessed
and updated efficiently. on your requirement and project, it is
important to choose the right data structure for your project. For
example, if you want to store data sequentially in the memory, then
you can go for the Array data structure.
The first of the two components of a program is a data structure,
which is a specialized and organized “collection and arrangement of
data (or data elements) and its subsequent storage in a computer’s 2
memory, in such a way that it can be easily accessed and retrieved
when needed.” Since a data structure refers to how data is
organized, it also shows the logical relationship between and among
the elements of data
2. Types of data structure?
1. Primitive Data Structures
Also called “primary data structure”, a primitive data structure is one
that is created from scratch, so to speak, without using other data
structures as support or tool. This is the most basic and simple data
structure, which is designed to operate upon by machine-level
instructions.Briefly, the known types of primitive data structures
include the Integer, Floating Point, Double, Character, Enumerated
Type, and the “true or false” Boolean structure.
2. Derived Data Structures (non-primitive data structures)
When the users get to use a set of operations in order to define a
data type, we are referring to the Abstract Data Structure. Others
refer to it as “non-primitive data structure” and “secondary data
structure”, a name adapted in reference to the fact that its creation
is dependent on a primary data structure. Further, there are two
subcategories under this classification.
3. What is stack?
Stack: stack is a Last In, First Out (LIFO) data structures which can be
implemented both using static methods and dynamic methods.. the
two basic operations can be performed in a stack are pushing and
popping. Pushing is the process of inserting an element to the top of
the stack where top is the position of last inserted item. Popping is
the process of deleting an element from the stack top.
4. Operation of stack?
A stack is an Abstract Data Type (ADT), commonly used in most
programming languages.
Then we have to know what a stack top is. stack top is nothing but
the position of the last inserted item in a stack.
Stack can be implemented either statically or dynamically. Static
implementation of a stack is possible only with the help of an array
and the dynamic implementation of the stack is performed with the
help of a linked list.
Another two concepts related with the stack are stack overflow and
stack underflow. Stack overflow is a condition in which there is no
further space in the stack for the insertion. And the stack underflow
is a condition in which the stack is empty.
5. What is push and pop with algorithm?
5.1. Push operation
Adding an element into the top of the stack is referred to as push
operation. Push operation involves following two steps
o Increment the variable Top so that it can now refer to the next
memory location.
o Add an element at the position of the incremented top. This is
referred to as adding a new element at the top of the stack.
Algorithm
push (STACK,ITEM )
TOP points to the top most element and ITEM is the value to be
inserted.
Print: Overflow
Else
End of If
2.Exit
Algorithm
pop (STACK )
TOP points to the top most element and ITEM contains the value
popped from STACK.
Print: Underflow
Else
End If
2. Return
6. what is infix postfix and prefix operation?
We know that a mathematical expression is a combination of
operands and operators And depending upon the position of the
operands and operators expression they can be represented in three
different ways. Prefix expression postfix expressions and infix
expressions
Infix to postfix(infix)
Description: Here infix is an infix expression and we have to obtain a
corresponding postfix expression and a stack STK is used.
Initially we have to scan the infix expression from left to right until the
end of the infix expression until the end of expression is encountered.
While scanning from left to right we have to perform the required
operations depending on whether it is an operand and operator.
1) start
2) Add closing braces to the end of the infix expression and
corresponding opening braces to the top of the stack.
3) Scan infix from left to right until the end of the expression is
encountered.
a) If an operand is encountered simply push the operand on to STK
after incrementing the top
b) If an operand is encountered just add it to the postfix expression.
c) When a closing parenthesis is encountered
i) Pop and add to the postfix expression each operators until an
opening bracket is encountered
ii) Then remove the opening bracket from STK
d) If an operator is encountered
i) repeatedly pop and add to the postfix expression all the
operators having equal or higher precedence than the
operator encountered.
ii) Then add the operator on to STK
4) Stop