Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
data structures and algorithms DSA interview questions and answers

Data Structure & Algorithms Interview Questions/Answers

YASH PAL, 19 March 202228 June 2025

In this article, we are going to see the top most important questions and answers about Data Structures and algorithms. so if you are preparing for competitive exams, or for coding interviews for big companies like Google, Microsoft, Amazon, etc then you must prepare for the Data structures and algorithms questions. So here we are including some basic to advanced questions related to DSA so you can prepare for this topic.

Consider the following tree

Data Structure & Algorithms Interview Questions and Answers

If the post-order traversal gives ab-cd*+ then the label of the nodes 1,2,3,… will be

  1. +,-,*,a,b,c,d
  2. a,-,b,+,*,d
  3. a,b,c,d,d,-,*,+
  4. -,a,b,+,*,c,d

Answer – (1) +,-,*,a,b,c,d

Consider the following tree

Data Structure & Algorithms Interview Questions and Answers

If this tree is used for sorting, then a new number 8 should be placed as the

  1. the left child of the node labeled 30
  2. right child of the node labeled 5
  3. right child of the node labeled 30
  4. the left child of the node labeled 10

Answer – (4) the left child of the node labeled 10

The initial configuration of a queue is a,b,c,d,(‘a’ is in the front end). To get the configuration d,c,b, a, one needs a minimum of

  1. 2 deletions and 3 additions
  2. 3 deletions and 2 additions
  3. 3 deletions and 3 additions
  4. 3 deletions and 4 additions

Answer – (3) 3 deletions and 2 additions

The order of a B-tree is defined as the

  1. Minimum no. of keys in a non-root node
  2. Maximum no. of keys in a non-root node
  3. (n + 1) / 2
  4. Maximum no. of pointers in any node

Answer – (4) Maximum no. of pointers in any node

If the sequence of operations – push(1), push(2), pop, push(1), push(20), pop, pop, pop, push(2), pop, are performed on a stack, the sequence of popped out values are

  1. 2,2,1,1,2
  2. 2,2,1,2,2
  3. 2,1,2,2,1
  4. 2,1,2,2,2

Answer – (1) 2, 2, 1, 1, 2

The depth of a complete binary tree with ‘n’ nodes is (log is to the base two)

  1. log(n + 1) – 1
  2. log(n)
  3. log(n – 1) + 1
  4. log(n) + 1

Answer – (1) log(n + 1) – 1

Preorder is the same as

  1. depth-first order
  2. breadth-first order
  3. topological order
  4. linear order

Answer – (1) depth-first order

Which of the following traversal techniques lists the nodes of a binary search tree in ascending order?

  1. Post-order
  2. In-order
  3. Pre-order
  4. None of the above

Answer – (2) In-order

A hash function f defined as f(key) = key mod 7, with linear probing, is used to insert the keys 37,38,72,48,98,11,56, into a table indexed from 0 to 6. What will be the location of key 11?

  1. 3
  2. 4
  3. 5
  4. 6

Answer – (3) 5

There are 4 different algorithms A1, A2, A3, and A4 to solve a given problem with the order log(n), log(log(n)), nlog(n), and n/logn respectively. Which is the best algorithm?

  1. A1
  2. A2
  3. A4
  4. A3

Answer – (2) A2

The number of possible binary search trees with 3 nodes is

  1. 12
  2. 13
  3. 5
  4. 15

Answer –  (3) 5

Sorting is useful for

  1. report generation
  2. minimizing the storage needs and responding to queries easily
  3. making searching easier and more efficient
  4. all of the above

Answer – (4) all of the above

The order of an algorithm that finds whether a given Boolean function of ‘n’ variables, produces a 1 is

  1. constant
  2. linear
  3. logarithmic
  4. exponential

Answer – (4) exponential

In evaluating the arithmetic expression 2 * 3 – (4 + 5), using stacks to evaluate its equivalent postfix form, which of the following stack configuration is not possible?

Data Structure & Algorithms Interview Questions and Answers

Answer – (d)

The way a card game player arranges his cards as he picks them up one by one is an example of

  1. bubble sort
  2. selection sort
  3. insertion sort
  4. merge sort

Answer – (3) insertion sort

You want to check whether a given set of items is sorted. Which of the following sorting methods will be the most efficient if it is already in sorted order?

  1. Bubble sort
  2. Selection sort
  3. Insertion sort
  4. Merge sort

Answer – (3) insertion sort

Which of the following sorting methods will be the best if a number of swappings are done, is the only measure of efficiency?

  1. bubble sort
  2. selection sort
  3. insertion sort
  4. Quicksort

Answer – (3) insertion sort

You are asked to sort 15 randomly generated numbers. You should prefer

  1. bubble sort
  2. selection sort
  3. insertion sort
  4. Quicksort

Answer – (3) insertion sort

As part of maintenance work, you are entrusted with the work of rearranging the library books on a shelf in proper order, at the end of each day. The ideal choice will be

  1. bubble sort
  2. selection sort
  3. insertion sort
  4. heap sort

Answer – (2) selection sort

Which of the following algorithms exhibits the unnatural behavior that, the minimum number of comparisons are needed if the list to be sorted is in the reverse order and a maximum number of comparisons are needed if they are already in sorted order?

  1. Heapsort
  2. Radix sort
  3. Binary insertion sort
  4. There can’t be any such sorting methods

Answer – (3) Binary insertion sort

Note – more questions and answers will be added from time to time.

Data Structures Tutorials Interview questions answers computer scienceinterview preparation

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes