Data Structures Technical Interview Questions

What are Data Structures?

A Data Structure is a specific way of organizing and storing data in a computer. The data must be structured in such a way so that it can be used efficiently. This included being easily stored, accessed and retrieved. Usually the data structure is designed in such a way to organize the data to suit a specific purpose.

The general data structure types include the array, the file, the record, the table, the tree, and so on.

What is the purpose of Data Structures?

Data structures are primarily used as a form of storing and organizing data. The most common types of data structures include the array, the file, the record, the table, the tree, etc. They are utilized by data management systems to store, organize and easily retrieve data.

Hence, it can be said that the primary purpose of data structures is so that the data can effectively be collected, stored, and utilized for use in various algorithms.

Differentiate file structure from storage structure

The primary difference between file structures and storage structures is the memory area that is accessed in each.

A storage structure is the representation of a particular data structure in the memory of a computer, whereas a file structure is a storage structure representation in auxiliary memory.

When is a binary search best applied?

Binary search is a type of algorithm. It is best applied to search in a list in which the elements are already in order or sorted.

The binary search algorithm starts searching the list from the middle. If the middle value is not the correct one, then it will go on to search the top or the bottom half in a similar manner, i.e. it will then divide the top or the bottom part into halves and start searching from its middle. It will continue to do this until the searched for value is found.

Which data structures are used for BFS and DFS of a graph?

Breadth First Search (BFS) and Depth First Search (DFS) are two different way of searching through data structures. BFS and DFS are algorithms that are primarily used for traversing or searching tree or graph data structures. DFS uses stack to search through the data structures, whereas BFS uses queue.

BFS is fairly simple to use as it doesn't need any data structures. It typically starts at the tree root or some arbitrary node of a graph, which is referred to as a 'search key'. It then explores the neighbor nodes first, before moving to the next level neighbors.

 DFS is closely related to preorder traversal of a tree, which means that it first searches each node before its children. It starts searching at the tree root or some arbitrary node of a graph and explores as far as possible along each branch before backtracking and trying another route.

Can doubly linked list be implemented using a single pointer variable in every node?

Yes, a doubly linked list can be implemented using a single pointer variable in every node. This type of list is called a XOR Linked List or Memory Efficient. This is because it is called bitwise XOR operation to save space for one address. In the XOR linked list, instead of storing actual memory addresses, every node stores the XOR of addresses of previous and next nodes.

What is LIFO?

LIFO stands for Last In and First Out. Basically, this means that the last data or information to be added is the only one that can be accessed. As the name suggest, the last thing to be inputted or added, is the first thing to be accessed. Hence, in order to access the first piece of data, all the other data to be stored after must first be accessed and extracted, until the first one can be reached.

What is FIFO?

FIFO stands for First In and First Out. Basically, here the first piece of data to be stored is the first one to be accessed. Hence, it can be said that the data is accessed in the order that it was stored. Think of FIFO as a line, where the first person to get in the line is the first person to get service, the second person in line gets service second, and so on and so forth.

What is a queue?

A queue is a type of data structure. Here, the first element in the structure is the only one that can be accessed. A Queue follows FIFO, which stands for First In and First Out. Basically, this means that in a queue when new data is added to the structure, it is put in line or order behind the last data. When it comes time to access the data, the first data to be filed or stored, is the first one to be accessed; then the second one, then the third one, until eventually the last one to be stored.

Compare this to people standing in a queue for something, such as ice-cream. Now, when the ice-cream seller stands selling the ice-cream, they will sell it to the person who was first in line. If they start selling to anybody, all of the people will rush to the front and there will no order. So, the first person to get in line is the first person to be served.

In queue, only two operations are allowed enqueue and dequeue. Enqueue means to insert an item into the back of the queue, dequeue means removing the front item.

What is a stack?

A stack is a type of data structure. Here, only the top element in the structure can be accessed. Stack follows LIFO, which stands for Last In First Out. Basically, what this means is that in the stack, as new data keeps getting added to the structure, the previous data keeps getting pushed out and cannot be accessed. Only the last data to be added can be accessed.

Compare this to a stack of plates. Each plate is stacked on top of each other. However, when it comes to removing the plate, either to use or to wash, the first plate to be taken would be from the top of the pile. If one removes a plate from the middle or the bottom, they risk toppling the entire pile. Hence, the last plate to be put on the stack, is the first one to be removed.

In the pushdown stacks, only two operations are allowed: push the item into the stack, and pop the item out of the stack. Push adds an item to the top of the stack, and pop removes the item from the top.

What is the difference between Stack and Queue data structure?

The primary difference between Stack and Queue data structure is that Stack is LIFO (Last In First Out), while Queue is a FIFO (First In First Out). Due to this, the manner in which each of these operate and the manner in which they handle data differs.

Stack

Queue

Type of data structure

Type of data structure

Follows Last In First Out (LIFO) order

Follows First In First Out (FIFO) order

Objects are inserted and removed at the same end.

Objects are inserted and removed from different ends.

The last inserted object is first to be accessed and extracted

The first object to be inserted is the first to be accessed and extracted.

Only one pointer is used. It points to the top of the stack.

Two different pointers are used. One for the front end and the other at the rear end.

Stack operations are called push and pop.

Queue operations are called enqueue and dequeue.

Are visualized as vertical collections

Are visualized as horizontal collections

What is a Linked List?

As its name suggests, a Linked List is a list of linked data elements. Technically speaking, a linked list is a linear collection of data elements, called nodes. In this list, each node points to another node by means of a pointer. It can also be said that it is a data structure consisting of a group of nodes which together represent a sequence, i.e. from one to another. In a linked list, each node is composed of data and a reference or link to the next node in the sequence.

Linked lists are among the simplest and most common data structures. They are primarily used to implement several other common abstract data types, including lists, stacks, queues, associative arrays, and S-expressions. In addition to these, they can also be used to implement other data structures directly without using a list as the basis of implementation.

What are the different types of Linked Lists

A linked list is a linear data structure where each element is a separate object. Technically speaking, a linked list is a linear collection of data elements, called nodes. In this list, each node points to another node by means of a pointer, and together form a sequence.

There are three types of Linked Lists:

  • Singly Linked List: Every node stores, addresses or references to the next node in list and the last node has next address or referenced as NULL. For example: 1->2->3->4->NULL
  • Doubly Linked List: There are two references associated with each node. One of the references points to the next node and one to the previous node. For example: NULL<-1<->2<->3->NULL
  • Circular Linked List: All nodes are connected to form a circle. There is no NULL at the end. The pointer of last node points back to the first. A circular linked list can be a singly circular linked list or doubly circular linked list. For example: 1->2->3->1.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.