Professional Documents
Culture Documents
ADS Viva
ADS Viva
ADS Viva
2.ADS JAVA?
Data structures are useful in storing and organizing the data in an efficient manner. t Java Data
Structures like arrays, linked lists, stacks, queues, graphs and, Set with their types,
implementation, and examples.
Linked List is a part of the Collection framework present in java. util package. This
class is an implementation of the LinkedList data structure which is a linear data
structure where the elements are not stored in contiguous locations and every element
is a separate object with a data part and address part.
List ADT. The data is generally stored in key sequence in a list which has a head
structure consisting of count, pointers and address of compare function needed to
compare the data in the list.
If the character is an operator, If the operator stack is empty then push it to the operator
stack. Else If the operator stack is not empty, If the character's precedence is greater
than or equal to the precedence of the stack top of the operator stack, then push the
character to the operator stack
17.What is postfix expression in Java?
The Postfix notation is used to represent algebraic expressions. The expressions
written in postfix form are evaluated faster compared to infix notation as parenthesis are
not required in postfix. Create a stack to store operands (or values).
Infix to postfix
Algorithm
1. Scan the infix expression from left to right.
2. If the scanned character is an operand, output it.
3. Else,
1 If the precedence of the scanned operator is greater than the precedence
of the operator in the stack(or the stack is empty or the stack contains a ‘(‘ ),
push it.
2 Else, Pop all the operators from the stack which are greater than or equal
to in precedence than that of the scanned operator. After doing that Push the
scanned operator to the stack. (If you encounter parenthesis while popping then
stop there and push the scanned operator in the stack.)
4. If the scanned character is an ‘(‘, push it to the stack.
5. If the scanned character is an ‘)’, pop the stack and output it until a ‘(‘ is
encountered, and discard both the parenthesis.
6. Repeat steps 2-6 until infix expression is scanned.
7. Print the output
8. Pop and output from the stack until it is not empty.
20..Circular Queue
Circular Queue is a linear data structure in which the operations are performed based
on FIFO (First In First Out) principle and the last position is connected back to the first
position to make a circle. In a normal Queue Data Structure, we can insert elements
until queue becomes full.
The Queue interface present in the java. ... It is an ordered list of objects with its use
limited to insert elements at the end of the list and deleting elements from the start
of the list, (i.e.), it follows the FIFO or the First-In-First-Out principle.
If a number remains same, even if we reverse its digits then the number is known
as palindrome number. For example 12321 is a palindrome number because it remains
same if we reverse its digits.
A stack can be easily implemented through the linked list. In using array will put a
restriction to the maximum capacity of the array which can lead to stack overflow. ...
Here each new node will be dynamically allocate.
27.Time Complexity:
Time complexity of both operations enqueue() and dequeue() is O(1) as we only
change few pointers in both operations. There is no loop in any of the operations.
Searching
Dijkstra's algorithm to find the shortest path between a and b. ... It picks the unvisited
vertex with the lowest distance, calculates the distance through it to each unvisited
neighbor, and updates the neighbor's distance if smaller. Mark visited (set to red) when
done with neighbors.
In this traversal method, the left subtree is visited first, then the root and later the right
sub-tree. We should always remember that every node may represent a subtree itself. If
a binary tree is traversed in-order, the output will produce sorted key values in an
ascending order.
40.https://www.gpp7.org.in/wp-content/uploads/sites/22/2020/04/file_5e95cd881b8c4.pd
f
41.In-order Traversal
In this traversal method, the left subtree is visited first, then the root and later the right sub-tree.
We should always remember that every node may represent a subtree itself.
If a binary tree is traversed in-order, the output will produce sorted key values in an ascending
order.
Pre-order Traversal
In this traversal method, the root node is visited first, then the left subtree and finally the right
subtree.
Post-order Traversal
In this traversal method, the root node is visited last, hence the name. First we traverse the left
subtree, then the right subtree and finally the root node.