Interview Questions and Answers - Order By Newest Q31. Given the list of adjacent nodes, What will be the Depth First path
1 -> 2
1 -> 3
1 -> 6
2 -> 4
3 -> 5 Algorithm
Ans. 1 -> 2 -> 4 -> 3 -> 5 -> 6 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  depth first traversal  graph traversal Q32. What will happen in a graph traversal if we don't have a check for cycle Algorithm
Ans. It will result in never ending loop Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  graph traversal Q33. Describe how you could use a single array to implement three stacks Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Structure Q34. How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Stricture   Big O Notation  time complexity Q35. Write a program to sort a stack in ascending order You should not make any assumptions about how the stack is implemented The following are the only functions that should be used to write this program: push | pop | peek | isEmpty Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Structures Q36. How different is the Search algorithm when we query Cassandra Tables and When we query Oracle Tables ? Cassandra
Ans. Relational Database uses linear search if we don't query using indices. Performance for linear search is O(n). If indices have been used , relational database uses binary search. Performance for binary search is O(Log n).
Casandra uses hash search. Performance for Hash Search is O(1). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cassandra vs oracle  nosql vs relational  search algorithm Q37. Find Max from Stack in O(1) complexity Algorithm
Ans. Create one extra field called MAX O(1)
when you an element to the stack check these two condition
1. Stack is empty, then MAX = element
2. Stack is not empty then check if the element is greater than MAX then MAX = element
when getMax fuction is called, then return MAX Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  complexity  stack  data structure Asked in 1 Companies This question was recently asked at 'Nagarvision'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  search  binary search Asked in 1 Companies basic   frequent Q39. Find all paths of length L in an acyclic graph Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q40. Given a linked list with 0 to n node references , Flaten the Linked list Algorithm
This question was recently asked at 'One Click Retail'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q41. What is the Big O notation for Fibonacci series - both iterative as well as recursive ? Algorithm
This question was recently asked at 'Canopy Tax'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Big o Notation   Asked in 1 Companies expert Q42. Write code to see if a Linked List has cycle in it ?
or
Write code using Floyd Algorithm to see if a linked list has cycle in it ? What is it's comlexity ? Algorithm
Ans. public class LinkedList {
Node start = null;
Node head = null;
class Node {
Integer body;
Node nextNode;
Node(Integer value) {
body = value;
}
}
public static void main(String[] args) {
LinkedList ll = new LinkedList();
ll.addNodeToEnd(5);
ll.addNodeToEnd(10);
ll.addNodeToEnd(15);
ll.traverse();
if(checkIfLoop(l1)){
System.out.println("There is a Loop");
} else {
System.out.println("No Loop");
}
}
private boolean checkifLoop(Test l1) {
Node slow = start;
Node fast = start;
Node faster = start;
while(slow != null ) {
fast = slow.nextNode;
faster = fast.nextNode;
if(slow == fast || slow == faster) {
return true;
}
slow = slow.nextNode;
}
return false;
}
}
Complexity of this algorithm is O(n) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  LinkedList  Cyclic LinkedList Q43. What is the runtime complexity of appending strings to string object and Why ? Algorithm
Ans. O(n^2) because each time a string is appended a new String is created and it runs through all the letters to copy them over. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q44. Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q45. Write a method that returns maximum depth of a tree ? Algorithm
This question was recently asked at 'One Click Retail'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  tree  data structure  maximum depth of tree Asked in 1 Companies Q46. Given a sorted array, write an algorithm to create a binary tree. Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q47. What is the difference between time and space complexity ? Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q48. Which data structure would you use to implement LRU cache and Why ? Can you tell me the time complexity for it ? Algorithm
Ans. We can use LinkedHashMap as it will give time complexity of O(1) for lookup and We can maintain the insertion order to identify the Last used elements for eviction. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  LRU Cache Asked in 1 Companies Q49. what is parallel array sorting? Algorithm
Ans. Java provides a new additional feature in Array class which is used to sort array elements in parallel.New methods have been added to the java.util.Arrays package that use the JSR 166 Fork/Join parallelism common pool to provide sorting of arrays in parallel.
The methods are called parallelSort() and are overloaded for all the primitive data types and Comparable objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q50. What is the difference between dynamic programming and the brute force algorithm? Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Ans. https://www.geeksforgeeks.org/arrays-sort-in-java-with-examples/ Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  array  sorting Asked in 16 Companies basic   frequent Q52. What is the ideal situation / case for using heap sort ? Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q53. Given a max-heap represented as an array, Return the n th largest element without modifying the heap. Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q54. Explain In place sorting algorithm ? Algorithm
This question was recently asked at 'Reddit,ServiceNow'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sorting algorithm   in place sorting algorithm Asked in 2 Companies Q55. How to calculate distance between 2 points using latitude longitude ? Algorithm
This question was recently asked at 'Trimble'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q56. Write a Program to find depth of node binary tree ? Algorithm
Ans. public static int getLevel(Node root, int key) {
int levelOfNode = getLevelUtil(root, key, 1);
return levelOfNode;
}
public static int getLevelUtil(Node root, int key, int level) {
if (root == null) return 0;
if (root.data == key) return level;
int left = getLevelUtil(root.left, key, level 1);
int right = getLevelUtil(root.right, key, level 1);
if (left != 0) return left;
else return right;
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q57. Write a Program to print all nodes of the data structure ? Algorithm
This question was recently asked at 'Overstock.com'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data structure  algorithm Asked in 1 Companies Q58. What are the disadvantages of binary search trees? Algorithm
This question was recently asked at 'ServiceNow'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  binary search tree Asked in 1 Companies Q59. What is the logic behind the shuffle in Music player ?
or
Explain Music player shuffle algorithm. Algorithm
This question was recently asked at 'ASG Sweden'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies a. Sorted in Ascending Order b. Sorted in Descending Order c. Sorted in any Order d. UnsortedAns.c. Sorted in any Order