0% found this document useful (0 votes)
48 views

Popular Coding Questions Asked in Data Science Interviews

This document provides 15 popular coding questions often asked in data science interviews related to data structures and algorithms. The questions cover topics like trees, binary trees, binary search trees, stacks, arrays, time complexity, and more. Example questions include properties of different tree data structures, performing traversals on trees, operations on stacks, determining the height of binary search trees, and analyzing time complexities. The author hopes these questions can help readers evaluate their knowledge of important data structures concepts frequently covered in interviews.

Uploaded by

Sheeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Popular Coding Questions Asked in Data Science Interviews

This document provides 15 popular coding questions often asked in data science interviews related to data structures and algorithms. The questions cover topics like trees, binary trees, binary search trees, stacks, arrays, time complexity, and more. Example questions include properties of different tree data structures, performing traversals on trees, operations on stacks, determining the height of binary search trees, and analyzing time complexities. The author hopes these questions can help readers evaluate their knowledge of important data structures concepts frequently covered in interviews.

Uploaded by

Sheeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Popular Coding Questions asked in Data Science Interviews

BE G I NNE R C A RE E R D AT A E XPLO RAT I O N I NT E RVI E W S

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 ver tices 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)?

(a) Binary Search Tree is considered as a special type of binary tree

(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?


(a) AVL trees are considered as a special kind of binary search 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?

(a) Stack is a type of dynamic set

(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 inser ted 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)

(a) 2

(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:

(a) 10

(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?

(a) An array is a collection of elements that are stored at contiguous memory locations

(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?

(a) In any tree, there may be more than one root node

(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

(a) 8 5 5 2 1

(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 inser ting 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?

(a) The root node in the formed tree is 50

(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 inser ting 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

(a) f 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?
(a) 5

(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 proper ties are correct about Binary Tree?

(a) Minimum number of nodes in a binary tree of height H = H + 1

(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

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 ar ticle are not owned by Analytics Vidhya and is used at the Author’s discretion. 
Article Url - https://www.analyticsvidhya.com/blog/2021/05/popular-coding-questions-asked-in-data-
science-interviews/

chirag676

You might also like