Algorithm - Interview Questions and Answers for 'Algorithm' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   
 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     


  Q51. Write code to sort an array.Algorithm
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


 Q60. Binary Search requires that the collection should beAlgorithm
a. Sorted in Ascending Order
b. Sorted in Descending Order
c. Sorted in any Order
d. Unsorted

Ans.c. Sorted in any Order

previous 30   

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: