ADS Viva

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

1.What is java?

Java is a high-level, class-based, object-oriented programming language that is designed to


have as few implementation dependencies as possible.

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.

3.What is a recursive function in Java?


a method calls itself to solve some problem.

4.Why recursion is used in Java?


Recursion is the technique of making a function call itself. This technique provides a way to
break complicated problems down into simple problems which ar
e easier to solve.

5.What is a non recursive function?


Non Recursive Functions are procedures or subroutines implemented in a programming
language, whose implementation does not reference itself.

6.What is the difference between recursive and nonrecursive?


Recursive function is a function which calls itself again and again. ... A recursive
function in general has an extremely high time complexity while a non-recursive one
does not. A recursive function generally has smaller code size whereas a non-recursive
one is larger

7.What is recursive and non recursive system?


A recursive system is a system in which current output depends on previous output(s)
and input(s) but in non-recursive system current output does not depend on
previous output(s)

8.What is linear search and binary search?


Linear search is a search that finds an element in the list by searching the element
sequentially until the element is found in the list.
A binary search is a search that finds the middle element in the list recursively until the
middle element is matched with a searched element.
9.What is meant by binary search?
Binary search is an efficient algorithm for finding an item from a sorted list of
items. It works by repeatedly dividing in half the portion of the list that could contain the
item, until you've narrowed down the possible locations to just one.

10.What is an array in Java?


An array in Java is a set of variables referenced by using a single variable name
combined with an index number. Each item of an array is an element. All the
elements in an array must be of the same type. ... An int array can contain int values, for
example, and a String array can contain strings.

11.What is a LinkedList java?

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.

12.​​What is ADT list?

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.

13.What is ADT give ADT of stack?


A stack is an Abstract Data Type (ADT), commonly used in most programming
languages. ... Likewise, Stack ADT allows all data operations at one end only. At any
given time, we can only access the top element of a stack. This feature makes it LIFO
data structure. LIFO stands for Last-in-first-out.

14.What is queue ADT in Java?


https://www.google.com/search?q=What+is+queue+ADT+in+Java?&tbm=isch&s
ource=iu&ictx=1&fir=8oOY1vdMO-Wn_M%252C88RLwXRwekC3NM%252C_&v
et=1&usg=AI4_-kQ2OrrYoWUBg-S3nDXpX-jroHAN5w&sa=X&ved=2ahUKEwiI7
ZuIwbzzAhXtwjgGHSWuCEoQ9QF6BAgQEAE#imgrc=8oOY1vdMO-Wn_M
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.

15.What is infix expression?


Infix notation: X + Y. Operators are written in-between their operands. This is the usual
way we write expressions. An expression such as A * ( B + C ) / D is usually taken to
mean something like: "First add B and C together, then multiply the result by A, then
divide by D to give the final answer."

16.Can we evaluate infix expression?

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).

18.What is a postfix expression explain with example?


Postfix: An expression is called the postfix expression if the operator appears in the
expression after the operands. Simply of the form (operand1 operand2 operator).
Example : AB+CD-* (Infix : (A+B * (C-D) ) Given a Prefix expression, convert it into a
Postfix expression

19.Infix expression: The expression of the form a op b. When an operator is


in-between every pair of operands.
Postfix expression: The expression of the form a b op. When an operator is
followed for every pair of operands.

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.

21.What is queue ADT in Java?

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.

22.What is stack ADT in Java?


A Stack is a collection of objects inserted and removed according to the Last In
First Out (LIFO) principle. Think of a stack of dishes. Push and Pop are the two main
operations.

23.What is palindrome in Java?


Palindrome number in java: A palindrome number is a number that is same after
reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers. It
can also be a string like LOL, MADAM etc.

24.What is the logic of palindrome?

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.

25.What is a singly linked list in Java?


The singly linked list is a linear data structure in which each element of the list
contains a pointer which points to the next element in the list. Each element in the
singly linked list is called a node. ... The last node of the list contains a pointer to the
null.

26.Can stack be implemented using singly linked list?

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.

28.What is a deque ADT?


The deque abstract data type is defined by the following structure and operations. A
deque is structured, as described above, as an ordered collection of items where
items are added and removed from either end, either front or rear. ... addFront(item)
adds a new item to the front of the deque.

29.What is an array deque?

An ArrayDeque (also known as an “Array Double Ended Queue”, pronounced as


“ArrayDeck”) is a special kind of a growable array that allows us to add or remove
an element from both sides. An ArrayDeque implementation can be used as a Stack
(Last-In-First-Out) or a Queue(First-In-First-Out).

30Can queue be implemented using singly linked list?


A queue can be easily implemented using a linked list. In singly linked list
implementation, enqueuing happens at the tail of the list, and the dequeuing of items
happens at the head of the list.

31.Is deque doubly linked list?


deque uses a linked list as part of its data structure. ... With doubly linked lists, deque
is capable of inserting or deleting elements from both ends of a queue with constant
O(1) performance.

32.What is queue ADT in data structure?


Queue ADT. The queue abstract data type (ADT) follows the basic design of the stack
abstract data type. Each node contains a void pointer to the data and the link pointer to
the next element in the queue.

33.How do you search elements in a binary search tree?

Searching

1. Compare the element with the root of the tree.


2. If the item is matched then return the location of the node.
3. Otherwise check if item is less than the element present on root, if so then move
to the left sub-tree.
4. If not, then move to the right sub-tree.
5. Repeat this procedure recursively until match found.

34.How do you search for a key in a binary search tree?


Searching a binary search tree for a specific key can be programmed recursively or
iteratively. We begin by examining the root node. If the tree is null, the key we are
searching for does not exist in the tree. Otherwise, if the key equals that of the root, the
search is successful, we return the node.

35.What do you mean by hashing?


Hashing is the process of converting an input of any length into a fixed size string
or a number using an algorithm. In hashing, the idea is to use a hash function that
converts a given key to a smaller number and uses the small number as an index in a
table called a hash table.

36.What is Dijkstra's algorithm explain with example?


https://www.google.com/search?q=What+is+Dijkstra%27s+algorithm+explain+wi
th+example?&biw=1280&bih=576&tbm=isch&source=iu&ictx=1&fir=FGGDzsHR
k4rE9M%252Cx2T0PY8Z_Y1AzM%252C_&vet=1&usg=AI4_-kQWkfaN7UdGOT
0MLPFG0G8layYuAA&sa=X&ved=2ahUKEwjPrsemx7zzAhUXxTgGHb2ID_oQ9
QF6BAgOEAE#imgrc=FGGDzsHRk4rE9M
Well simply explained, an algorithm that is used for finding the shortest distance,
or path, from starting node to target node in a weighted graph is known as
Dijkstra's Algorithm. This algorithm makes a tree of the shortest path from the starting
node, the source, to all other nodes (points) in the graph.

37.How does Dijkstra's algorithm determine the shortest path?

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.

38.How do you recursively traverse a binary tree?


For a recursive traversal of a binary tree, when at a node there are three things that can
be done: visit, traverse the left subtree, and traverse the right subtree. Varying the
order we have three important binary tree traversals: preorder - visit, traverse left,
traverse right.

39.How do you traverse a binary tree?

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.

You might also like