0% found this document useful (0 votes)
51 views10 pages

DSL Practical Oral QueAns

The document discusses data structures and provides details about various types of data structures like lists, arrays, records, trees, and tables. It also discusses linear data structures like arrays, stacks, strings, queues, and linked lists. Some applications of data structures mentioned are numerical analysis, operating systems, AI, compiler design, databases, graphics, statistics, and simulation. The document also answers questions about multidimensional arrays, linked lists, stacks, and differences between various data structures.

Uploaded by

Ankit Bhujbal
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)
51 views10 pages

DSL Practical Oral QueAns

The document discusses data structures and provides details about various types of data structures like lists, arrays, records, trees, and tables. It also discusses linear data structures like arrays, stacks, strings, queues, and linked lists. Some applications of data structures mentioned are numerical analysis, operating systems, AI, compiler design, databases, graphics, statistics, and simulation. The document also answers questions about multidimensional arrays, linked lists, stacks, and differences between various data structures.

Uploaded by

Ankit Bhujbal
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/ 10

ZEAL EDUCATION SOCIETY'S

ZEAL COLLEGE OF ENGINEERING AND RESEARCH

Data Structure Interview Questions and Answers

1. What is a Data Structure?

The Data Structure is the way data is organized (stored) and manipulated for retrieval and
access. It also defines the way different sets of data relate to one another, establishing
relationships and forming algorithms.

2. Describe the types of Data Structures?

The following are the types of data structures:

Lists: A collection of related things linked to the previous or/and following data items.

Arrays: A collection of values that are all the same.

Records: A collection of fields, each of which contains data from a single data type.

Trees: A data structure that organizes data in a hierarchical framework. This form of data
structure follows the ordered order of data item insertion, deletion, and modification.

Tables: The data is saved in the form of rows and columns. These are comparable to records in
that the outcome or alteration of data is mirrored across the whole table.

3. What is a Linear Data Structure? Name a few examples.

A data structure is linear if all its elements or data items are arranged in a sequence or a linear
order. The elements are stored in a non-hierarchical way so that each item has successors and
predecessors except the first and last element in the list.

Examples of linear data structures are Arrays, Stack, Strings, Queue, and Linked List.

4. What are some applications of Data Structures?

In terms of data structure interview questions, this is one of the most frequently asked question.

Numerical analysis, operating system, AI, compiler design, database management, graphics,
statistical analysis, and simulation.

5. What is the difference between file structure and storage structure?


The difference lies in the memory area accessed. Storage structure refers to the data structure in
the memory of the computer system, whereas file structure represents the storage structure in
the auxiliary memory.

6. What is a multidimensional array?

A multidimensional array is a multidimensional array with more than one dimension. It is an


array of arrays or an array with numerous layers. The 2D array, or two-dimensional array, is the
most basic multidimensional array. As you'll see in the code, it's technically an array of arrays. A
2D array is also referred to as a matrix or a table with rows and columns. Declaring a
multidimensional array is the same as saying a one-dimensional array. We need to notify C that
we have two dimensions for a two-dimensional array.

7. How are the elements of a 2D array stored in the memory?

Row-Major Order: -In row-major ordering, all of the rows of a 2D array are stored in memory in a
contiguous manner.

First, the first row of the array is entirely stored in memory, followed by the second row of the
array, and so on until the final row.

Column-Major Order: In column-major ordering, all of the columns of a 2D array are stored in
memory in the same order. The first column of the array is entirely saved in memory, followed by
the second row of the array, and so on until the last column of the array is wholly recorded in
memory.

8. What is a linked list Data Structure?

This is one of the most frequently asked data structure interview questions where the
interviewer expects you to give a thorough answer. Try to explain as much as possible rather
than finishing your answer in a sentence!

It’s a linear Data Structure or a sequence of data objects where elements are not stored in
adjacent memory locations. The elements are linked using pointers to form a chain. Each
element is a separate object, called a node. Each node has two items: a data field and a
reference to the next node. The entry point in a linked list is called the head. Where the list is
empty, the head is a null reference and the last node has a reference to null.

A linked list is a dynamic data structure, where the number of nodes is not fixed, and the list has
the ability to grow and shrink on demand.

It is applied in cases where:

We deal with an unknown number of objects or don’t know how many items are in the list
We need constant-time insertions/deletions from the list, as in real-time computing where time
predictability is critical

Random access to any elements is not needed

The algorithm requires a data structure where objects need to be stored irrespective of their
physical address in memory

We need to insert items in the middle of the list as in a priority queue

Some implementations are stacks and queues, graphs, directory of names, dynamic memory
allocation, and performing arithmetic operations on long integers.

9. Are linked lists considered linear or non-linear Data Structures?

Linked lists are considered both linear and non-linear data structures depending upon the
application they are used for. When used for access strategies, it is considered as a linear
data-structure. When used for data storage, it is considered a non-linear data structure.

10. What are the advantages of a linked list over an array? In which scenarios do we use Linked
List and when Array?

1. Insertion and Deletion

Insertion and deletion of nodes is an easier process, as we only update the address present in
the next pointer of a node. It’s expensive to do the same in an array as the room has to be
created for the new elements and existing elements must be shifted.

2. Dynamic Data Structure

As a linked list is a dynamic data structure, there is no need to give an initial size as it can grow
and shrink at runtime by allocating and deallocating memory. However, the size is limited in an
array as the number of elements is statically stored in the main memory.

3. No Wastage of Memory

As the size of a linked list can increase or decrease depending on the demands of the program,
and memory is allocated only when required, there is no memory wasted. In the case of an
array, there is memory wastage. For instance, if we declare an array of size 10 and store only five
elements in it, then the space for five elements is wasted.

4. Implementation

Data structures like stack and queues are more easily implemented using a linked list than an
array.

Some scenarios where we use linked list over array are:


When we know the upper limit on the number of elements in advance

When there are a large number of add or remove operations

When there are no large number of random access to elements

When we want to insert items in the middle of the list, such as when implementing a priority
queue

Some scenarios in which we use array over the linked list are:

When we need to index or randomly access elements

When we know the number of elements in the array beforehand, so we can allocate the correct
amount of memory

When we need speed when iterating through all the elements in the sequence

When memory is a concern; filled arrays use less memory than linked lists, as each element in
the array is the data but each linked list node requires the data as well as one or more pointers
to the other elements in the linked list

In summary, we consider the requirements of space, time, and ease of implementation to decide
whether to use a linked list or array.

11. What is a doubly-linked list? Give some examples.

It is a complex type (double-ended LL) of a linked list in which a node has two links, one that
connects to the next node in the sequence and another that connects to the previous node. This
allows traversal across the data elements in both directions.

Examples include:

A music playlist with next and previous navigation buttons

The browser cache with BACK-FORWARD visited pages

The undo and redo functionality on a browser, where you can reverse the node to get to the
previous page

12. How do you reference all of the elements in a one-dimension array?

Using an indexed loop, we may access all of the elements in a one-dimensional array. The
counter counts down from 0 to the maximum array size, n, minus one. The loop counter is used
as the array subscript to refer to all items of the one-dimensional array in succession.

13. What is the difference between static and dynamic data structure?
14. What is a stack?

A stack is an abstract data type that specifies a linear data structure, as in a real physical stack or
piles where you can only take the top item off the stack in order to remove things. Thus,
insertion (push) and deletion (pop) of items take place only at one end called top of the stack,
with a particular order: LIFO (Last In First Out) or FILO (First In Last Out).

15. Where are stacks used?

Expression, evaluation, or conversion of evaluating prefix, postfix, and infix expressions

Syntax parsing

String reversal

Parenthesis checking

Backtracking

16. What are the operations that can be performed on a stack?


A stack is a linear data structure that operates on the same concept, in that components in a
stack are added and deleted only from one end, referred to as the TOP. As a result, a stack is
known as a LIFO (Last-In-First-Out) data structure because the piece that was put last is the first
to be removed.

A stack may perform three fundamental operations:

PUSH: The push action inserts a new element into the stack. The new feature is placed at the top
of the stack. However, before inserting the value, we must first verify if TOP=MAX–1, since if so,
the stack is filled, and no more insertions are possible. An OVERFLOW message is printed if an
attempt is made to put a value into an existing stack.

POP: The pop operation is performed to remove the stack's topmost element. However, before
removing the value, we must first verify if TOP=NULL, since if it is, the stack is empty, and no
further deletions are permitted. An UNDERFLOW notice is produced if an attempt is made to
erase a value from a stack that is already empty.

PEEK: A peek action returns the value of the stack's topmost element without removing it from
the stack. On the other hand, the Peek operation first checks if the stack is empty, i.e., if TOP =
NULL, then an appropriate message is written. Otherwise, a value is returned.

17. What is a queue Data Structure?

In this type of data structure interview questions, you can also discuss your experience and
situations using queue. A queue is an abstract data type that specifies a linear data structure or
an ordered list, using the First In First Out (FIFO) operation to access elements. Insert
operations can be performed only at one end called REAR and delete operations can be
performed only at the other end called FRONT.

18. List some applications of queue Data Structure.

To prioritize jobs as in the following scenarios:

As waiting lists for a single shared resource in a printer, CPU, call center systems, or image
uploads; where the first one entered is the first to be processed

In the asynchronous transfer of data; or example pipes, file IO, and sockets

As buffers in applications like MP3 media players and CD players

To maintain the playlist in media players (to add or remove the songs)

19. What is a Dequeue?

It is a double-ended queue, or a data structure, where the elements can be inserted or deleted
at both ends (FRONT and REAR).
20. What operations can be performed on queues?

enqueue() adds an element to the end of the queue

dequeue() removes an element from the front of the queue

init() is used for initializing the queue

isEmpty tests for whether or not the queue is empty

The front is used to get the value of the first data item but does not remove it

The rear is used to get the last item from a queue

21. Where can stack Data Structure be used?

Expression evaluation

Backtracking

Memory management

Function calling and return

22. What is the difference between a PUSH and a POP?

In terms of data structure interview questions, this is one of the most frequently asked question.

The acronyms stand for Pushing and Popping operations performed on a stack. These are ways
data is stored and retrieved.

PUSH is used to add an item to a stack, while POP is used to remove an item.

PUSH takes two arguments, the name of the stack to add the data to and the value of the entry
to be added. POP only needs the name of the stack.

When the stack is filled and another PUSH command is issued, you get a stack overflow error,
which means that the stack can no longer accommodate the last PUSH. In POP, a stack underflow
error occurs when you’re trying to POP an already empty stack.

23. How does the Selection sort work?

This is one of the most frequently asked data structure interview questions. Selection sort works
by repeatedly picking the smallest number in ascending order from the list and placing it at the
beginning. This process is repeated moving toward the end of the list or sorted subarray.

Scan all items and find the smallest. Switch over the position as the first item. Repeat the
selection sort on the remaining N-1 items. We always iterate forward (i from 0 to N-1) and swap
with the smallest element (always i).
Time complexity: best case O(n2); worst O(n2)

Space complexity: worst O(1)

24. Differentiate NULL and VOID

Null is a value, whereas Void is a data type identifier

Null indicates an empty value for a variable, whereas void indicates pointers that have no initial
size

Null means it never existed; Void means it existed but is not in effect

25. Do dynamic memory allocations help in managing data? How?

Dynamic memory allocation stores simple structured data types at runtime. It has the ability to
combine separately allocated structured blocks to form composite structures that expand and
contract as needed, thus helping manage data of data blocks of arbitrary size, in arbitrary order.

26. What are the applications of queue?

The following are the areas in which queues are applicable

a. Simulation

b. Batch processing in an operating systems

c. Multiprogramming platform systems

d. Queuing theory

e. Printer server routines

f. Scheduling algorithms like disk scheduling , CPU scheduling

g. I/O buffer requests

27. What are enqueue and dequeue operations?

• Enqueue - adding an element to the queue at the rear end

If the queue is not full, this function adds an element to

the back of the queue, else it prints “OverFlow”.

void enqueue(int queue[], int element, int& rear, int arraySize) {

if(rear == arraySize) // Queue is full

printf(“OverFlow\n”);
else{

queue[rear] = element; // Add the element to the back

rear++;

• Dequeue – removing or deleting an element from the queue at

the front end

If the queue is not empty, this function removes the

element from the front of the queue, else it prints “UnderFlow”.

void dequeue(int queue[], int& front, int rear) {

if(front == rear) // Queue is empty

printf(“UnderFlow\n”);

else {

queue[front] = 0; // Delete the front element

front++;

28. Distinguish between stack and queue.

STACK: Insertion and deletion are made at one end. The element inserted last would

be removed first. So LIFO structure.

Full stack condition:

If(top==Maxsize)

Physically and Logically full stack

QUEUE:

Insertion at one end rear and deletion at other end front. The element inserted first would be
removed first. So FIFO structure.
Full stack condition:

If(rear = = Maxsize)

Logically full. Physically may or may not be full.

29. Convert the infix (a+b)*(c+d)/f into postfix & prefix expression

Postfix : a b + c d + * f /

Prefix : / * + a b + c d f

You might also like