# Popular Coding Questions asked in Data Science Interviews

*This article was published as a part of the Data Science Blogathon.*

**Introduction**

**Data Structures and Algorithms **are the integral part that every **Machine Learning** Practitioners should know about. It allows the programmers to write codes in an optimized manner which comes in handy to use especially when we are dealing with very large datasets.

Therefore it becomes necessary for every aspiring candidate to have a good grasp of the fundamentals. Data Structure and Algorithm Questions are usually asked extensively in multiple coding rounds.

So I have come up with a curated list of 15 popular Data Structure and Algorithm questions often asked in Data Science Interviews.

Do Attempt these questions and evaluate yourself!

** **

**1. Which of the following statements are correct about Tree Data Structure?**

(a) It is a non-linear data structure

(b) In a tree data structure, a node can have any number of child nodes

(c) There is one and only one possible path between every pair of vertices in a tree

(d) Any connected graph having n vertices and n edges is considered as a tree

**Answer: [ a, b, c ]**

**Explanation: A graph is a tree if and only if it is minimally connected, which means any connected graph with n vertices and (n-1) edges is a tree.**

** **

** **

**2. Which of the following statements are TRUE about Tree Traversals for a given tree?**

(a) The Inorder traversal of the given tree is B D A G E C H F I

(b) The Preorder traversal of the given tree is A B D C E G F H I

(c) The Postorder traversal of the given tree is D B G E H I F C A

(d) The breadth-first traversal of the given tree is A B C D E F G H I

**Answer: [ a, b, c, d ]**

**Explanation: Preorder: Root → Left → Right**

** Inorder: Left → Root → Right**

** Postorder: Left → Right → Root**

** **

** **

**3. Which of the following statements are TRUE about Binary Tree?**

(a) In a binary tree, each node must have 2 children

(b) In a binary tree, nodes are always arranged in a specific order

(c) It is a special type of tree data structure

(d) Number of nodes having zero children in any binary tree depends only on the number of nodes with 2 children

**Answer: [ c, d ]**

**Explanation: In a binary tree, each node can have at most 2 children.**

** Total Number of nodes having zero children in a Binary Tree = Total Number of nodes having 2 children + 1**

** **

** **

**4. Which of the following statements are correct about Binary Search Tree(BST)?**

(b) Nodes are arranged in a specific order

(c) Only smaller values in its right subtree

(d) Only larger values in its left subtree

**Answer: [ a, b ]**

**Explanation: In a binary search tree (BST), each node contains, only smaller values in its left subtree and only larger values in its right subtree.**

** **

** **

**5. Which of the following statements are TRUE about AVL Tree?**

(b) AVL trees are also called self-balancing binary search trees

(c) In AVL trees, the height of the left subtree and right subtree of every node differs by at least one

(d) In AVL trees, the balancing factor of each node is either 0 or 1 or -1

**Answer: [ a, b, d ]**

**Explanation: In AVL trees, the height of the left subtree and the right subtree of every node differs by at most one.**

** **

** **

**6. Which of the following statements are True about Stack Data Structure?**

(b) It follows the Last-In-First-Out(LIFO) principle

(c) Stack is a non-linear Data Structure

(d) The INSERT operation on the stack is often known as PUSH

**Answer: [ a, b, d ]**

**Explanation: Stack is a linear Data Structure.**

** **

** **

**7. The following integers are inserted into an initially empty binary search tree in order:**

**10, 1, 3, 5, 15, 12, 16**

**What is the height of the binary search tree formed? (Here, Height is defined as the maximum distance of a leaf node from the root. If the tree has only the root node then the height is 0)**

(b) 3

(c) 4

(d) 5

**Answer: [ b ]**

**Explanation: The Binary Search Tree formed is shown as below:**

**8. Suppose in a Binary tree, the number of the internal nodes having degree-1 is 9 and the number of internal nodes having degree-2 is 16. Then, the number of nodes having 0 children in the binary tree are:**

(b) 17

(c) 25

(d) 7

**Answer: [ b ]**

**Explanation: Total Number of leaf nodes in a Binary Tree = Total Number of nodes having 2 children + 1**

** **

** **

**9. Which of the following statements are TRUE about Array Data Structure?**

(b) Array can store the elements of different data type

(c) Array is a Linear Data Structure

(d) Accessing array elements takes constant time

**Answer: [ a, c, d ]**

**Explanation: Array contains all the elements of the same data type.**

** **

** **

10. How many of the following statements are TRUE about Tree Terminology?

(b) The connecting link between any two nodes in a tree is called an edge

(c) Nodes that belong to the same parent are called siblings

(d) Degree of a Tree is the total number of children of any node of a tree

**Answer: [ b, c ]**

**Hint: Self Explanatory(Basics of Tree Terminology)**

** **

** **

**11.** **Choose correct output for the following sequence of operations on Stack Data Structure:**

push(5) push(8) pop push(2) push(5) pop pop pop push(1) pop

(b) 8 2 5 5 1

(c) 8 1 2 5 5

(d) 8 5 2 5 1

**Answer: [ d ]**

**Explanation: Stack Data Structure follows the Last-In-First-Out(LIFO) Principle.**

** **

** **

**12. A binary search tree is formed by inserting the numbers in the given order-**

**50, 5, 20, 58, 91, 3, 8, 24**

**Then, Which of the following statements are TRUE about BST formed?**

(b) Number of nodes in the left subtree of the root = 5

(c) Number of nodes in the right subtree of the root = 2

(d) Node with label 20 have only 1 child

**Answer: [ a, b, c ]**

**Explanation: The tree formed after inserting all the elements is shown as below:**

**13. Compare the following in the term of increasing time complexity:**

**f _{1}(n)=2^{n}, f_{2}(n)=n^{3/2}, f_{3}(n)=nlog_{2}n, f_{4}(n)=n^{log2n}**

_{2}, f

_{3}, f

_{4}, f

_{1}

(b) f_{2}, f_{1}, f_{3}, f_{4}

(c) f_{1}, f_{2}, f_{3}, f_{4}

(d) f_{3}, f_{2}, f_{4}, f_{1}

**Answer: [ d ]**

**Explanation: Comparison of various time complexities:**

**O(1) <O(log(logn)) <O(logn) <O(n ^{1/2}) <O(n) <O(nlogn) <O(n^{2}) <O(n^{3}) <0(n^{k}) <O(2^{n}) <O(n^{n})**

**14. What is the minimum number of nodes required to construct an AVL Tree of height = 3?**

(b) 6

(c) 7

(d) 8

**Answer: [ c ]**

**Hint: Using the recursive relation: N(h) = N(h-1) + N(h-2) + 1, with base condition as N(0)=1 and N(1)=2 and here we have to calculate the value of N(3).**

** **

** **

**15. Which of the following properties are correct about Binary Tree?**

(b) Maximum number of nodes in a binary tree of height H = 2^{H+1} – 1

(c) Maximum number of nodes at any level ‘L’ in a binary tree = 2^{L}

(d) Maximum number of nodes at any level ‘L’ in a binary tree = 2^{L}-1

**Answer: [ a, b, c ]**

**Hint: Self Explanatory(Take a small tree example and then verifies the options).**

** **

**End Notes**

*Thanks for reading!*

I hope you enjoyed the questions and were able to test your knowledge about Data Structures.

If you liked this and want to know more, go visit my other articles on Data Science and Machine Learning by clicking on the **Link**

Please feel free to contact me on **Linkedin, Email.**

Something not mentioned or want to share your thoughts? Feel free to comment below And I’ll get back to you.

__About the author__

__About the author__

**Chirag Goyal**

Currently, I pursuing my Bachelor of Technology (B.Tech) in Computer Science and Engineering from the **Indian Institute of Technology Jodhpur(IITJ). **I am very enthusiastic about Machine learning, Deep Learning, and Artificial Intelligence.

*The media shown in this article are not owned by Analytics Vidhya and is used at the Author’s discretion. *