## Data Structures

Arrays - ds easy problem solving (basic) max score: 10 success rate: 93.24%, 2d array - ds easy problem solving (basic) max score: 15 success rate: 93.16%, dynamic array easy problem solving (basic) max score: 15 success rate: 86.78%, left rotation easy problem solving (basic) max score: 20 success rate: 91.19%, sparse arrays medium problem solving (basic) max score: 25 success rate: 97.29%, array manipulation hard problem solving (intermediate) max score: 60 success rate: 61.10%, print the elements of a linked list easy problem solving (basic) max score: 5 success rate: 97.18%, insert a node at the tail of a linked list easy problem solving (intermediate) max score: 5 success rate: 95.26%, insert a node at the head of a linked list easy problem solving (basic) max score: 5 success rate: 98.33%, insert a node at a specific position in a linked list easy problem solving (intermediate) max score: 5 success rate: 96.99%.

## Browse Course Material

Course info.

- Prof. Erik Demaine

## Departments

- Electrical Engineering and Computer Science

## As Taught In

- Algorithms and Data Structures

## Learning Resource Types

Advanced data structures, assignments.

- There will be a weekly one-page assignment, 10 assignments in total.
- You may skip any one problem, or we will ignore the problem with the lowest grade. If you volunteered to scribe twice, we will ignore the lowest two grades.
- The answers must be typeset in LaTeX. The answers must fit in one page, or your solution will not be read. Use at least 10 pt font and 1 inch margins. This rule is meant to prepare you for writing research publications: one often has to explain great ideas in a very limited number of pages.
- Submissions must be made online and consist of a compiled PDF document.
- Grades and comments will be posted online.
- Solutions do not need to include all calculations, trivial details etc. Just prove to us that you found the solution, and you understand it well.
- 0 = You didn’t get it. Filling one page to the brim does not mean you can’t get zero. Please don’t write stuff you know is wrong.
- 1 = Your solution was ultimately a good one, but the write-up contained significant errors or omissions.
- 2 = (We think) you got it.

## 600.226: Data Structures (Spring 2017)

Assignment 4: stacking queues.

- Out on: February 23, 2017
- Due by: Thursday , March 2 before 10:00 pm
- Collaboration: None
- Grading: Packaging 10%, Style 10% (where applicable), Testing 10% (where applicable), Performance 10% (where applicable), Functionality 60% (where applicable)

The fourth assignment is mostly about stacks and queues. For the former you’ll build a simple calculator application, for the latter you’ll implement the data structure in a way that satisfies certain performance characteristics (in addition to the usual correctness properties).

## Problem 1: Calculating Stacks (50%)

Your first task is to implement a basic RPN calculator that supports integer operands like 1 , 64738 , and -42 as well as the (binary) integer operators + , - , * , / , and % . The style of arithmetic expressions our calculator will evaluate is also called a post-fix notation. Stacks are great for doing this job! Your task is to write a driver (client) program that uses our Stack interface and one of the given implementations to perform these calculations as specified here.

Your program should be called Calc and work as follows:

- The user enters input through System.in consisting of operands and operators, presumably in post-fix notation. We have also included some extra operators to get information about results and the current state of the stack.
- If the user enters a valid integer, you push that integer onto the stack.
- If the user enters a valid operator, you pop two integers off the stack, perform the requested operation, and push the result back onto the stack.
- If the user enters the symbol ? (that’s a question mark), you print the current state of the stack using its toString method followed by a new line.
- If the user enters the symbol ^ (that’s a caret), you pop the top element off the stack and print only that element (not the entire stack) followed by a new line.
- If the user enters the symbol ! (that’s an exclamation mark or bang), you exit the program.

Note that there are a number of error conditions that your program must deal with gracefully for full credit. We’ll give you two examples for free, you’ll have to figure out any further error conditions for yourself:

- If the user enters blah or 1.5 or anything else that doesn’t make sense for an integer calculator as specified above, your program should make it clear that it can’t do anything helpful with that input; but it should not stop at that point.
- If the user requests an operation for which there are not enough operands on the stack, your program should notify the user of the problem but leave the stack unchanged; again, it should certainly not stop at that point.

Of course this means that you’ll have to print error messages to the user. Error messages must be printed to standard error and not to standard output! (Of course, the regular input and output is done through standard input and standard output as usual.) Furthermore, all error messages must start with the symbol # (that’s a hash sign) and be followed by a new line!

Here are two examples for interacting with Calc that will hopefully help you understand what you’re trying to achieve. First a “slow” example:

Here $ is the shell prompt. After starting the program, the first command was ? to print the stack (which is empty at this point, hence [] is the output). Then the user typed 10 followed by ? and we see that the stack now holds that number: [10] . Now the user typed two numbers 20 30 in sequence before hitting return. When we check the stack now using ? we get the answer [30, 20, 10] so obviously the “top” of the stack is to the left. Then we see the * operator being typed, which will multiply the top two numbers. We use ? again to check the result: [600, 10] . This is followed by the + operator, which will add the top two numbers. Again we check with ? and get [610] as we’d expect. The ^ command prints the same result 610 and pops if off the stack. So the next ? shows an empty stack again. Finally the user typed the ! command to quit, returning us to the shell. Here’s the same example, done “fast” this time:

As you can see, if the entire sequence of integers, operators, and commands is entered on a single line, they are all executed in order. It’s like having our own little programming language! Finally, here’s an example for the sample error conditions described above:

Note in particular that blah and 1.0 lead to error messages but are otherwise ignored (the program doesn’t stop); same for the two + operations when the stack only has a single element (the program doesn’t even modify the stack in that case).

## Implementation Details and Hints

- You must create an empty Stack to hold intermediate results and then repeatedly accept input from the user. It doesn’t matter whether you use the ArrayStack or the ListStack we provide, what does matter is that the specific type only appears once in your program. (In other words, the type of the stack reference variable you use in your program must be Stack and not ArrayStack or ListStack . Polymorphism!)
- Note that we’re dealing with integers only (type Integer in Java) so / stands for integer division and % stands for integer remainder . Both of these should behave in Calc just like they do in Java. The details are messy but worth knowing about, especially regarding modulus .
- You may find it interesting to read up on Autoboxing and Unboxing in Java. It’s the reason we can use our generic Stack implementations for Integer objects yet still do arithmetic like we would on regular int variables.
- Only if you’re not afraid of learning on your own: You’ll be able to use the matches method of the String class to your advantage when it comes to checking whether a valid operator was entered. (But you can just as well do it with a bunch of separate comparisons or a simple String variable containing all the valid operation symbols if you don’t want to learn about regular expressions .)

## Problem 2: Hacking Growable Deques (50%)

Your second task is to implement a generic ArrayDeque class as outlined in lecture. As is to be expected, ArrayDeque must implement the Deque interface we provided on Piazza .

Your implementation must be done in terms of an array that grows by doubling as needed. It’s up to you whether you want to use a built-in Java array or the SimpleArray class you know and love; just in case you prefer the latter, we’ve once again included it on the Piazza post for this assignment. Your initial array must have a length of one slot only! (Trust us, that’s going to make debugging the “doubling” part a lot easier.)

Your implemention must support all Deque operations except insertion in (worst-case) constant time ; insertion can take longer when you need to grow the array, but overall all insertion operations must be constant amortized time as discussed in lecture.

You should provide a toString method in addition to the methods required by the Deque interface. The toString will orient the front of the deque at the left and the back at the right. For example, a new dequeue into which 1, 2, and 3 were inserted using insertBack() should print as [1, 2, 3] whereas an empty dequeue should print as [] .

You must write JUnit 4 test drivers for the Deque interface and your ArrayDeque class. All the general test cases should go into DequeTestBase.java whereas test cases specific to ArrayDeque (if any!) should go into ArrayDequeTest.java . (Follow the example for testing the Array interface and its various implementations we posted on Piazza and discussed in lecture.)

Be sure to test all methods and all exceptions as well. Note that it is not enough to have just one test case for each method; there are plenty of complex interactions between the methods that need to be covered as well. (And yes, of course you need to test toString !)

## Documentation

Don’t forget to add proper javadoc comments for your ArrayDeque class. Running checkstyle will remind you to do this!

## General Assignment Hints

- Ensure that the version of your code you hand in does not produce any extraneous debugging output anymore!
- Pay attention to edge cases in the input your classes and programs are expected to handle! For example, make sure that you handle the empty input in a reasonable way for Problem 1.
- Private helper methods are your friends. Your best friends, actually! If you don’t write plenty of them, you’ll have a much harder time getting your code to work.

## Bonus Problem (0%)

Develop an algebraic specification for the abstract data type Queue . Use new , empty , enqueue , dequeue , and front (with the meaning of each as discussed in lecture) as your set of operations. Consider unbounded queues only, unless of course you want to do a bonus bonus problem on bounded queues as well.

The difficulty is going to be modelling the FIFO (first-in-first-out) behavior accurately. You’ll probably need at least one axiom with a case distinction using an if expression; the syntax for this in the Array specification for example.

Doing this problem without resorting to Google may be rather helpful for the upcoming midterm. There’s no need to submit the problem, but of course you can submit it if you wish; just include it at the end of your README file.

## Deliverables

You must turn in a zipped ( .zip only) archive containing all source code, your README file, and any other deliverables required by the assignment. The filename should be HW##-jhed.zip with ## replaced by the 2-digit number (use leading 0s) of this assignment (see above) and jhed replaced by your Blackboard login. (For example, Peter would use HW03-pfroehl1.zip for his submission of Assignment 3.) The zip should contain no derived files whatsoever (i.e. no .class files, no .html files, etc.), but should allow building all derived files. Include a plain text README file (not README.txt or README.docx or whatnot) that briefly explains what your programs do and contains any other notes you want us to check out before grading. Your answers to written problems should be in this README file as well. Finally, make sure to include your name and email address in every file you turn in (well, in every file for which it makes sense to do so anyway)!

For reference, here is a short explanation of the grading criteria; some of the criteria don't apply to all problems, and not all of the criteria are used on all assignments.

Packaging refers to the proper organization of the stuff you hand in, following both the guidelines for Deliverables above as well as the general submission instructions for assignments.

Style refers to Java programming style, including things like consistent indentation, appropriate identifier names, useful comments, suitable javadoc documentation, etc. Many aspects of this are enforced automatically by Checkstyle when run with the configuration file available on Piazza . Style also includes proper modularization of your code (into interfaces, classes, methods, using public , protected , and private appropriately, etc.). Simple, clean, readable code is what you should be aiming for.

Testing refers to proper unit tests for all of the data structure classes you developed for this assignment, using the JUnit 4 framework as introduced in lecture. Make sure you test all (implied) axioms that you can think of and all exception conditions that are relevant.

Performance refers to how fast/with how little memory your program can produce the required results compared to other submissions.

Functionality refers to your programs being able to do what they should according to the specification given above; if the specification is ambiguous and you had to make a certain choice, defend that choice in your README file.

If your programs cannot be built you will get no points whatsoever. If your programs cannot be built without warnings using javac -Xlint:all we will take off 10% (except if you document a very good reason; no, you cannot use the @SuppressWarnings annotation either). If your programs fail miserably even once, i.e. terminate with an exception of any kind, we will take off 10% (however we'll also take those 10% off if you're trying to be "excessively smart" by wrapping your whole program into a universal try-catch).

## Data Structures Assignment 1

(implementing a queue using stacks), due: aug 17.

This assignment is for you to get comfortable with JAVA features. You will get a chance to use class hierarchy, File I/O, Exception handling, Thread programming, Inter-thread synchronization etc. Please read the entire assignment carefully, many times over.

The goal is to implement a data structure called “queue” using another data structure called “stack”. Refer chapter 4 of the Goodrich and Tamassia book for stacks and queues.

Programming problem 1 : Implement a stack using an array. Implement the stack interface defined here . Use generics in Java to make sure that you can use the stack for any type of data. You may assume that the number of elements inserted into the stack never exceeds 100,000. Do NOT use the inbuilt Stack class of java. Name your stack implementation as myStack .

Queue using two Stacks

The goal of this assignment is to implement a queue using two stacks. We will employ two different ideas for this and try to understand why one idea is better than the other. Let us first consider a naive implementation.

Implementation 1:

Let S1 and S2 be the two stacks to be used in the implementation of our queue. All we have to do is to define the enqueue and dequeue operations for the queue.

enqueue ( T a)

S1.push( a);

dequeue ( ){

if (S1 is empty) return(error);

while( S1 is not empty){

S2.push( S1.pop());

}

r <- S2.pop( );

while( S2 is not empty){

S1.push( S2.pop());

return( r);

Programming Problem 2 : Use your stack implementation (programming problem 1) to implement a queue using the above pseudocode . Implement the queue interface defined here . Name your implementation myQueue1.

Implementation 2:

Again, let S1 and S2 be the two stacks to be used in the implementation of our queue. As in the previous implementation we have to define enqueue and dequeue operations.

if (S1 is empty & S2 is empty) return(error);

if (S2 is empty){

while( S1 is not empty){

S2.push( S1.pop());

}

return( S2.pop());

Programming Problem 3 : Use your stack implementation to implement a queue using the above pseudocode . Implement the queue interface defined here . Name this implementation myQueue2.

Analysis Problem 1 (not to be submitted) : Argue for yourself that the above two correctly implements a queue using two stacks.

Analysis Problem 2 (not to be submitted) : Try to figure out why the second implementation is much better than the first one.

Parallel Programming

This is an important programming paradigm where you can run multiple “threads” of execution in parallel. Parallel programming is useful in reducing the running time, or deal with asynchronous inputs, or sometimes just to model the problem in a better manner. Here we will use Java threads to get a taste of parallel programming.

Programming Problem 4 : You have to create multiple java threads (number of threads will be specified as input). Each thread will read from a separate file and execute the operation on a shared queue. You have to use the queue that you have made in programming problems 2 and 3. The implementation you have to use will be specified in the input. Note that you should make proper use of synchronization.

Input-output format for programming problems 4 : Programming problem 4 should use your implementations in programming problems 1 ,2 , and 3. We will not specifically check your implementation of programming problems 1 ,2 , and 3.

Program name : You must write a Simulate.java program which contains the main method. This is the program that we will run to check your implementations.

Input : Your program should take two command line arguments that are both integers. The first argument denotes the number of threads your program should run. The second argument tells you which implementation of a queue (myQueue1 or myQueue2) you should be using. For example, consider that you run the following command:

This means that you must run 5 threads and use your 1 st queue implementation (i.e., myQueue1).

The queue operations must be read from files named operations-x.dat . For example if there are 5 threads, thread 1 reads from operations-1.dat file, thread 2 reads from operations-2.dat file and so on. Each file contains enqueue and dequeue statements in separate lines. Following is an example of an operations-x.dat file:

<a>, <b>, etc. denote arbitrary strings.

Output : Your program should output two files. First it should produce a file named operations-out.dat which should contain the enqueue / dequeue operation and the thread number which executes this operation. For example suppose thread #1 executed enqueue ( a), dequeue (), enqueue (b), and then thread #2 executed dequeue (). Then your operations-out.dat file should be the following:

Your second file should be named output.dat and it should contain the output of the dequeue operations performed on the shared queue and the thread number performing the operation. For example, corresponding to the above operations-out.dat file, your output.dat file should be the following:

Your program must handle the errors in input file format as exception. These must be caught and reported on standard output as "FileFormatException".

Empty stack errors : In case of errors, for example, the queue is empty and there is a dequeue request. The output.dat file should contain the appropriate exception name for that request. For example, there is a single thread and the input file operations-1.dat is the following:

Then the output.dat file should look like:

- Computer Science and Engineering
- Data Structures And Algorithms (Video)
- Co-ordinated by : IIT Delhi
- Available from : 2009-12-31
- Introduction to Data Structures and Algorithms
- Queues and Linked Lists
- Dictionaries
- Tree Walks / Traversals
- Ordered Dictionaries
- Red Black Trees
- Insertion in Red Black Trees
- Disk Based Data Structures
- Case Study: Searching for Patterns
- Data Compression
- Priority Queues
- Binary Heaps
- Why Sorting
- More Sorting
- Data Structures for Graphs
- Two Applications of Breadth First Search
- Depth First Search
- Applications of DFS
- DFS in Directed Graphs
- Applications of DFS in Directed Graphs
- Minimum Spanning Trees
- Prims Algorithm for Minimum Spanning Trees
- Single Source Shortest Paths
- Correctness of Dijkstras Algorithm
- Watch on YouTube
- Assignments
- Transcripts

## Online Embedded Systems Course with Placements

## Advanced Embedded Course With Placements

## Online Embedded IoT Course

## Advanced Embedded IoT Course With Placements

## Linux Device Drivers

## IoT Internship

## Campus Ambassador Program

- For Corporates
- All Courses
- Hire Trainees
- Short-term Courses

## Schedule a Call

With Our Career Counsellor

Invalid value

- Register now!

## Data Structures Question Bank With Answers PDF Free Download

Data Structures Question Bank With Answers PDF: Are you a student and facing trouble in finding the right questions for your preparation for data structures exam? Students can overcome this problem just by downloading the data structures question bank with answers PDF, and it will eliminate all the troubles. It will make the preparation of the students more efficient.

Data structures question bank with answers PDF helps the students to gain a piece of detailed knowledge of data structures, and this will strengthen the core knowledge of the students. With a strong base, students can secure good marks in the exams. Data structures question bank with answers PDF is prepared to keep in mind the syllabus of data structures so that the students can precisely follow the curriculum.

Students can get access to some of the best reference books of the data structure and Lecture Notes from this article which will help them in enhancing their preparation.

- About data structures
- Data structures question bank with answers PDF
- Data structures reference books.
- Data structure syllabus
- Data structure important Questions.
- Frequently asked questions

## About Data Structures Question Bank With Answers

The data structure, in computer science, is defined as a data organisation, management, and storage format that allows efficient access and modification. In simpler words, data structures can be termed as the collection of data values, the relationship prevailing among them and the functions and operations that are possible to be applied to the data.

They are the basis of Abstract Data Types (ADT). The ADT is used to define the logical form of data type, whereas the data structure describes the physical form of a data type. Data structures are of different types and are suited for different kind of applications, and some are also highly specialised for specific tasks only. Data structures provide a medium to manage a large amount of data efficiently for uses such as databases and internet indexing services.

Data structure generally depends on the capability of the computer in fetching and storing data inside the memory of computer, which is to be specified by a pointer. The implementation of data structure generally requires to write a set of procedures that would create and manipulate the instances of a particular structure. It is not possible to analyse the efficiency of data structure separately from the operations.

All these concepts and basics can be learned from the data structures question bank with answers PDF as it includes questions that have the ability to give a detailed overview of a data structure without any doubt.

Students facing problems in the data structure chapter must download data structures question bank with answers PDF to get a clear overview of the chapter. The questions in the PDF will help students in enhancing their preparation for the exams. An efficient preparation for the exams can result in the scoring of good marks in the exams.

The questions included in the data structures question bank with answers PDF helps the students by giving them a preview of the problem they are going to face in the exams thus motivating them to get prepared according to it. This PDF will wash away all the weaknesses of the students and will help them to strengthen their cores.

- Data structures notes PDF
- Data structures lecture notes
- Data structures study materials
- Data structures questions PDF
- Data structures PPT
- Data Structures Important Questions And Answers Pdf
- Data Structure Question Paper With Answer Pdf
- Data Structures Question Bank With Answers Pdf
- Data Structures And Algorithms Question Bank With Answers Pdf
- Data Structures Important Questions Pdf
- Data Structure Important Questions And Answers Pdf
- Data Structure Questions And Answers Pdf Free Download
- Dsa Question Bank Pdf
- Data Structures Questions And Answers Pdf
- Data Structure Question Paper With Answer
- Data Structure Questions And Answers Pdf
- Data Structures And Algorithms Important Questions Pdf
- Data Structures And Algorithms Questions And Answers Pdf

## Data Structure Important Questions

- Data Structures And Algorithms Interview Questions And Answers Pdf
- Data Structure Question Paper Pdf
- Dsa Questions And Answers Pdf
- Data Structures University Questions And Answers
- Data Structures Important Questions And Answers
- Advanced Data Structures And Algorithms Question Bank With Answers
- Dsa Interview Questions And Answers Pdf

## Data Structures Reference Books

Books are the best source of gaining knowledge on a particular topic. They give the students a detailed view of the topic, which help them to strengthen their cores. A book can help the students to enhance his/her preparation for the exams and become confident of scoring good marks in the exams.

Referring to one book is not always enough because one book cannot give all the information related to a particular topic. A student who is interested in scoring good marks must try referring more than one books for his/her own benefits.

There are some books of data structures that are considered as best by some experts who have years of experience in this field. Students should refer this books during their preparations. Some of these books are:-

- Introduction to Algorithms by Thomas H. Corman
- Algorithms by Robert Sedgewick & Kevin Wayne
- The Algorithm Design Manual by Steve S.Skiena
- Algorithms For Interview by Adnan Aziz
- Algorithms in Nutshell by O’Reilly’s
- Algorithm Design by Kleinberg & Tardos
- The Design and Analysis of Computer Algorithms by Alfred Aho, Jeffrey Ullman, John Hopcraft
- Data Structures and Algorithms by Aho, Ullman & Hopcraft
- Python Algorithms: Mastering Basic Algorithms in the Python Language by some Python Programmers

## Data Structures Syllabus

Students should know the pattern of questions that are coming in the exams. They should learn from which section of the subject most of the questions are coming from. This will help them in their preparation and make them more confident for the final exams. A confident student can easily score the highest possible marks in the exams.

Let us list out some of the important questions that can help a student to enhance his/her preparation and becoming more efficient on this particular chapter data structure:-

- What is the data structure?
- Difference between file structure and storage structure
- When is a binary search best applied?
- What do you mean by linked list?
- In what areas data structures can be applied?
- What do you understand by LIFO?
- What is the queue?
- What do you mean by binary trees?
- Which data structures are meant to be applied while dealing with a recursive function?
- What do you mean by a stack?
- Explain binary search tree
- What are multidimensional arrays?
- What can be linked lists considered as: linear or non-linear data structures?
- List the ways how dynamic memory allocation helps in managing data
- What do you understand by FIFO?
- What is an ordered list?
- What do you understand by merge sort?
- Differentiate between NULL and VOID
- List out the primary advantages of linked list.
- What’s the difference between a PUSH and a POP?
- What is a linear search?
- How does the variable declaration affect memory allocation?
- List out the advantages that can come when the heap is over a stack
- What do you understand by postfix expression?
- What does data abstraction mean?
- How to insert a new item in the binary search tree?
- What are the ways in which a selection sort works for an array?

Data structures question banks with answers PDF can act as a saviour for the students in their final exams. They can increase their knowledge and be experts in this subject with the help of this PDF. The reference books mentioned in this article are trusted to be valuable and have the capability of giving the students a detailed knowledge. The questions mentioned above are some of the important questions that are likely to come in the exams; thus, students should prepare it efficiently. Students can achieve success with this PDF.

Also Refer: Multiple Bus Organisation Notes and Study Material PDF Free Download

## Frequently Asked Questions on Data Structure Question Bank With Answers

Question 1. What are the advantages of data structures?

Answer: Some of the advantages of data structures are

- It allows information storage on hard disks.
- It provides means of management for large datasets, for example, databases or internet indexing services.
- It is required for designing efficient algorithms.
- It allows security to storage by providing safe storage of information on a computer.
- It helps in data usage and processing on a software system.
- Processing of data can be much easier with the data structure.
- In the data structure, a person can access the data anytime at any place using the internet, which is a beneficial aspect of data structuring.

Question 2. What are the disadvantages of data structure?

Answer: Some of the important disadvantages of the data structure are:-

- Applications which are using data structure for operations requires a highly qualified professional resource that can manage the operations related to the data structure easily. Acquiring this professional resource is very difficult.
- If the data structure used to maintain and control the application is more significant, then it must require a lot of workforces. Increase in labour cost will make data structure operations expensive.
- Designing a data structure is very difficult as it involves a complex algorithm. It will require a lot of time and testing to prove that it is ready to be used in a organisation.

Question 3. What is a binary tree in data structure?

Answer: Binary tree in computer science can be defined as a tree data structure in which each node consists of at most two children. These two children are referred to as the left child and the right child. The binary tree sometimes is also interpreted as an undirected rather than as a directed graph. In these cases, the binary tree is an ordered and rooted tree. Some authors also use a rooted binary tree in spite of the binary tree to emphasise on this particular fact.

Question 4. What do you understand by a linked list?

Answer: Linked list is defined as a collection in a linear way of data elements whose orders are not mentioned by their physical placement in the memory. Instead, in this case, each element points to the next element. This is a type of data structure that consists of a collection of nodes which together can be represented as a sequence.

## All Interview

Company interview, technical interview, web interview, php interview, .net interview, java interview, database interview, 46) list some applications of tree-data structure.

Applications of Tree- data structure:

- The manipulation of Arithmetic expression,
- Symbol Table construction,
- Syntax analysis
- Hierarchal data model

## 47) Define the graph data structure?

A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices and E(G) represents the set of edges which are used to connect these vertices. A graph can be seen as a cyclic tree, where the vertices (Nodes) maintain any complex relationship among them instead of having parent-child relations.

## 48) Differentiate among cycle, path, and circuit?

- Path: A Path is the sequence of adjacent vertices connected by the edges with no restrictions.
- Cycle: A Cycle can be defined as the closed path where the initial vertex is identical to the end vertex. Any vertex in the path can not be visited twice
- Circuit: A Circuit can be defined as the closed path where the intial vertex is identical to the end vertex. Any vertex may be repeated.

## 49) Mention the data structures which are used in graph implementation.

For the graph implementation, following data structures are used.

- In sequential representation, Adjacency matrix is used.
- In Linked representation, Adjacency list is used.

## 50) Which data structures are used in BFS and DFS algorithm?

- In BFS algorithm, Queue data structure is used.
- In DFS algorithm, Stack data structure is used.

## 51) What are the applications of Graph data structure?

The graph has the following applications:

- Graphs are used in circuit networks where points of connection are drawn as vertices and component wires become the edges of the graph.
- Graphs are used in transport networks where stations are drawn as vertices and routes become the edges of the graph.
- Graphs are used in maps that draw cities/states/regions as vertices and adjacency relations as edges.
- Graphs are used in program flow analysis where procedures or modules are treated as vertices and calls to these procedures are drawn as edges of the graph.

## 54) In what scenario, Binary Search can be used?

Binary Search algorithm is used to search an already sorted list. The algorithm follows divide and conqer approach

## 52) What are the advantages of Binary search over linear search?

There are relatively less number of comparisons in binary search than that in linear search. In average case, linear search takes O(n) time to search a list of n elements while Binary search takes O(log n) time to search a list of n elements.

## 53) What are the advantages of Selecetion Sort?

- It is simple and easy to implement.
- It can be used for small data sets.
- It is 60 per cent more efficient than bubble sort.

## 55) List Some Applications of Multilinked Structures?

- Sparse matrix,
- Index generation.

## 56) What is the difference between NULL and VOID?

- Null is actually a value, whereas Void is a data type identifier.
- A null variable simply indicates an empty value, whereas void is used to identify pointers as having no initial size.

## You may also like:

- Java Interview Questions
- SQL Interview Questions
- Python Interview Questions
- JavaScript Interview Questions
- Angular Interview Questions
- Selenium Interview Questions
- Spring Boot Interview Questions
- HR Interview Questions
- C Programming Interview Questions
- C++ Interview Questions
- Data Structure Interview Questions
- DBMS Interview Questions
- HTML Interview Questions
- IAS Interview Questions
- Manual Testing Interview Questions
- OOPs Interview Questions
- .Net Interview Questions
- C# Interview Questions
- ReactJS Interview Questions
- Networking Interview Questions
- PHP Interview Questions
- CSS Interview Questions
- Node.js Interview Questions
- Spring Interview Questions
- Hibernate Interview Questions
- AWS Interview Questions
- Accounting Interview Questions

## Learn Latest Tutorials

Transact-SQL

Reinforcement Learning

R Programming

React Native

Python Design Patterns

Python Pillow

Python Turtle

## Preparation

Verbal Ability

Interview Questions

Company Questions

## Trending Technologies

Artificial Intelligence

Cloud Computing

Data Science

Machine Learning

## B.Tech / MCA

Data Structures

Operating System

Computer Network

Compiler Design

Computer Organization

Discrete Mathematics

Ethical Hacking

Computer Graphics

Software Engineering

Web Technology

Cyber Security

C Programming

Control System

Data Mining

Data Warehouse

## Download Interview guide PDF

- Data Structure Interview Questions

## Download PDF

Data structures are the building blocks of any computer program as they help in organizing and manipulating data in an efficient manner. Without data structures, the computer would be unable to understand how to follow a program's instructions properly. It also defines their relationship with one another.

Arrays , Linked Lists , Stacks, Queues, and others are examples of Data Structure. Data structures also provide clarity, organization and structure to the program's code while also helping the programmer ensure that each line of code performs its function correctly.

In this article, we've compiled the answers to the most frequently asked Data Structure Interview Questions so that you may better prepare for your job interview.

## Basic Data Structure Interview Questions for Freshers

Data structure interview questions for experienced, data structure mcq, 1. what are data structures.

A data structure is a mechanical or logical way that data is organized within a program. The organization of data is what determines how a program performs. There are many types of data structures, each with its own uses. When designing code, we need to pay particular attention to the way data is structured. If data isn't stored efficiently or correctly structured, then the overall performance of the code will be reduced.

## 2. Why Create Data Structures?

Data structures serve a number of important functions in a program. They ensure that each line of code performs its function correctly and efficiently, they help the programmer identify and fix problems with his/her code, and they help to create a clear and organized code base.

## 3. What are some applications of Data structures?

Following are some real-time applications of data structures:

- Decision Making
- Image Processing
- Numerical and Statistical Analysis
- Compiler Design
- Database Design and many more

## 4. Explain the process behind storing a variable in memory.

- The required amount of memory is assigned first.
- Then, it is stored based on the data structure being used.
- Using concepts like dynamic allocation ensures high efficiency and that the storage units can be accessed based on requirements in real-time.

## 5. Can you explain the difference between file structure and storage structure?

- File Structure: Representation of data into secondary or auxiliary memory say any device such as a hard disk or pen drives that stores data which remains intact until manually deleted is known as a file structure representation.
- Storage Structure : In this type, data is stored in the main memory i.e RAM, and is deleted once the function that uses this data gets completely executed.

The difference is that the storage structure has data stored in the memory of the computer system, whereas the file structure has the data stored in the auxiliary memory.

## Learn via our Video Courses

6. describe the types of data structures.

- Linear Data Structure: A data structure that includes data elements arranged sequentially or linearly, where each element is connected to its previous and next nearest elements, is referred to as a linear data structure. Arrays and linked lists are two examples of linear data structures.
- Non-Linear Data Structure: Non-linear data structures are data structures in which data elements are not arranged linearly or sequentially. We cannot walk through all elements in one pass in a non-linear data structure, as in a linear data structure. Trees and graphs are two examples of non-linear data structures.

## 7. What is a stack data structure? What are the applications of stack?

A stack is a data structure that is used to represent the state of an application at a particular point in time. The stack consists of a series of items that are added to the top of the stack and then removed from the top. It is a linear data structure that follows a particular order in which operations are performed. LIFO (Last In First Out) or FILO (First In Last Out) are two possible orders. A stack consists of a sequence of items. The element that's added last will come out first, a real-life example might be a stack of clothes on top of each other. When we remove the cloth that was previously on top, we can say that the cloth that was added last comes out first.

Following are some applications for stack data structure:

- It acts as temporary storage during recursive operations
- Redo and Undo operations in doc editors
- Reversing a string
- Parenthesis matching
- Postfix to Infix Expressions
- Function calls order

## 8. What are different operations available in stack data structure?

Some of the main operations provided in the stack data structure are:

- push: This adds an item to the top of the stack. The overflow condition occurs if the stack is full.
- pop: This removes the top item of the stack. Underflow condition occurs if the stack is empty.
- top: This returns the top item from the stack.
- isEmpty: This returns true if the stack is empty else false.
- size: This returns the size of the stack.

## 9. What is a queue data structure? What are the applications of queue?

A queue is a linear data structure that allows users to store items in a list in a systematic manner. The items are added to the queue at the rear end until they are full, at which point they are removed from the queue from the front. Queues are commonly used in situations where the users want to hold items for a long period of time, such as during a checkout process. A good example of a queue is any queue of customers for a resource where the first consumer is served first.

Following are some applications of queue data structure:

- Breadth-first search algorithm in graphs
- Operating system: job scheduling operations, Disk scheduling, CPU scheduling etc.
- Call management in call centres

## 10. What are different operations available in queue data structure?

- enqueue: This adds an element to the rear end of the queue. Overflow conditions occur if the queue is full.
- dequeue: This removes an element from the front end of the queue. Underflow conditions occur if the queue is empty.
- isEmpty: This returns true if the queue is empty or else false.
- rear: This returns the rear end element without removing it.
- front: This returns the front-end element without removing it.
- size: This returns the size of the queue.

## 11. Differentiate between stack and queue data structure.

## 12. How to implement a queue using stack?

A queue can be implemented using two stacks . Let q be the queue and stack1 and stack2 be the 2 stacks for implementing q . We know that stack supports push, pop, and peek operations and using these operations, we need to emulate the operations of the queue - enqueue and dequeue. Hence, queue q can be implemented in two methods (Both the methods use auxillary space complexity of O(n)):

1. By making enqueue operation costly:

- Here, the oldest element is always at the top of stack1 which ensures dequeue operation occurs in O(1) time complexity.
- To place the element at top of stack1, stack2 is used.
- Enqueue: Here time complexity will be O(n)
- Dequeue: Here time complexity will be O(1)

2. By making the dequeue operation costly:

- Here, for enqueue operation, the new element is pushed at the top of stack1 . Here, the enqueue operation time complexity is O(1).
- In dequeue, if stack2 is empty, all elements from stack1 are moved to stack2 and top of stack2 is the result. Basically, reversing the list by pushing to a stack and returning the first enqueued element. This operation of pushing all elements to a new stack takes O(n) complexity.
- Enqueue: Time complexity: O(1)
- Dequeue: Time complexity: O(n)

## 13. How do you implement stack using queues?

- A stack can be implemented using two queues. We know that a queue supports enqueue and dequeue operations. Using these operations, we need to develop push, pop operations.
- Let stack be ‘s’ and queues used to implement be ‘q1’ and ‘q2’. Then, stack ‘s’ can be implemented in two ways:

1. By making push operation costly:

- This method ensures that the newly entered element is always at the front of ‘q1’ so that pop operation just dequeues from ‘q1’.
- ‘q2’ is used as auxillary queue to put every new element in front of ‘q1’ while ensuring pop happens in O(1) complexity.
- Push element to stack s: Here push takes O(n) time complexity.
- Pop element from stack s: Takes O(1) time complexity.

2. By making pop operation costly:

- In push operation, the element is enqueued to q1.
- In pop operation, all the elements from q1 except the last remaining element, are pushed to q2 if it is empty. That last element remaining of q1 is dequeued and returned.
- Push element to stack s: Here push takes O(1) time complexity.
- Pop element from stack s: Takes O(n) time complexity.

## 14. What is array data structure? What are the applications of arrays?

An array data structure is a data structure that is used to store data in a way that is efficient and easy to access. It is similar to a list in that it stores data in a sequence. However, an array data structure differs from a list in that it can hold much more data than a list can. An array data structure is created by combining several arrays together. Each array is then given a unique identifier, and each array’s data is stored in the order in which they are created.

Array data structures are commonly used in databases and other computer systems to store large amounts of data efficiently. They are also useful for storing information that is frequently accessed, such as large amounts of text or images.

## 15. Elaborate on different types of array data structure

There are several different types of arrays:

- One-dimensional array: A one-dimensional array stores its elements in contiguous memory locations, accessing them using a single index value. It is a linear data structure holding all the elements in a sequence.

- Two-dimensional array: A two-dimensional array is a tabular array that includes rows and columns and stores data. An M × N two-dimensional array is created by grouping M rows and N columns into N columns and rows.

- Three-dimensional array: A three-dimensional array is a grid that has rows, columns, and depth as a third dimension. It comprises a cube with rows, columns, and depth as a third dimension. The three-dimensional array has three subscripts for a position in a particular row, column, and depth. Depth (dimension or layer) is the first index, row index is the second index, and column index is the third index.

## 16. What is a linked list data structure? What are the applications for the Linked list?

A linked list can be thought of as a series of linked nodes (or items) that are connected by links (or paths). Each link represents an entry into the linked list, and each entry points to the next node in the sequence. The order in which nodes are added to the list is determined by the order in which they are created.

Following are some applications of linked list data structure:

- Stack, Queue, binary trees, and graphs are implemented using linked lists.
- Dynamic management for Operating System memory.
- Round robin scheduling for operating system tasks.
- Forward and backward operation in the browser.

## 17. Elaborate on different types of Linked List data structures?

Following are different types of linked lists:

1. Singly Linked List: A singly linked list is a data structure that is used to store multiple items. The items are linked together using the key. The key is used to identify the item and is usually a unique identifier. In a singly linked list, each item is stored in a separate node. The node can be a single object or it can be a collection of objects. When an item is added to the list, the node is updated and the new item is added to the end of the list. When an item is removed from the list, the node that contains the removed item is deleted and its place is taken by another node. The key of a singly linked list can be any type of data structure that can be used to identify an object. For example, it could be an integer, a string, or even another singly linked list. Singly-linked lists are useful for storing many different types of data. For example, they are commonly used to store lists of items such as grocery lists or patient records. They are also useful for storing data that is time sensitive such as stock market prices or flight schedules.

2. Doubly Linked List: A doubly linked list is a data structure that allows for two-way data access such that each node in the list points to the next node in the list and also points back to its previous node. In a doubly linked list, each node can be accessed by its address, and the contents of the node can be accessed by its index. It's ideal for applications that need to access large amounts of data in a fast manner. A disadvantage of a doubly linked list is that it is more difficult to maintain than a single-linked list. In addition, it is more difficult to add and remove nodes than in a single-linked list.

3. Circular Linked List: A circular linked list is a unidirectional linked list where each node points to its next node and the last node points back to the first node, which makes it circular.

4. Doubly Circular Linked List: A doubly circular linked list is a linked list where each node points to its next node and its previous node and the last node points back to the first node and first node’s previous points to the last node.

5. Header List: A list that contains the header node at the beginning of the list, is called the header-linked list. This is helpful in calculating some repetitive operations like the number of elements in the list etc.

## 18. Difference between Array and Linked List.

## 19. What is an asymptotic analysis of an algorithm?

Asymptotic analysis of an algorithm defines the run-time performance as per its mathematical boundations. Asymptotic analysis helps us articulate the best case(Omega Notation, Ω), average case(Theta Notation, θ), and worst case(Big Oh Notation, Ο) performance of an algorithm.

## 20. What is hashmap in data structure?

Hashmap is a data structure that uses an implementation of a hash table data structure which allows access to data in constant time (O(1)) complexity if you have the key.

## 21. What is the requirement for an object to be used as key or value in HashMap?

- The key or value object that gets used in the hashmap must implement equals() and hashcode() method.
- The hash code is used when inserting the key object into the map and the equals method is used when trying to retrieve a value from the map.

## 22. How does HashMap handle collisions in Java?

- The java.util.HashMap class in Java uses the approach of chaining to handle collisions. In chaining, if the new values with the same key are attempted to be pushed, then these values are stored in a linked list stored in a bucket of the key as a chain along with the existing value.
- In the worst-case scenario, it can happen that all keys might have the same hashcode, which will result in the hash table turning into a linked list. In this case, searching a value will take O(n) complexity as opposed to O(1) time due to the nature of the linked list. Hence, care has to be taken while selecting hashing algorithm.

## 23. What is the time complexity of basic operations get() and put() in HashMap class?

The time complexity is O(1) assuming that the hash function used in the hash map distributes elements uniformly among the buckets.

## 1. What is binary tree data structure? What are the applications for binary trees?

A binary tree is a data structure that is used to organize data in a way that allows for efficient retrieval and manipulation. It is a data structure that uses two nodes, called leaves and nodes, to represent the data. The leaves represent the data and the nodes represent the relationships between the leaves. Each node has two children, called siblings, and each child has one parent. The parent is the node that is closest to the root of the tree. When a node is deleted from the tree, it is deleted from both its child and its parent.

Following are some applications for binary tree data structure:

- It's widely used in computer networks for storing routing table information.
- Decision Trees.
- Expression Evaluation.
- Database indices.

## 2. What is binary search tree data structure? What are the applications for binary search trees?

A binary search tree is a data structure that stores items in sorted order. In a binary search tree, each node stores a key and a value. The key is used to access the item and the value is used to determine whether the item is present or not. The key can be any type of value such as an integer, floating point number, character string, or even a combination of these types. The value can be any type of items such as an integer, floating point number, character string, or even a combination of these types. When a node is added to the tree, its key is used to access the item stored at that node. When a node is removed from the tree, its key is used to access the item stored at that node.

A binary search tree is a special type of binary tree that has a specific order of elements in it. It has three basic qualities:

- All elements in the left subtree of a node should have a value less than or equal to the parent node's value, and
- All elements in the right subtree of a node should have a value greater than or equal to the parent node's value.
- Both the left and right subtrees must be binary search trees too.

- It is used for indexing and multi-level indexing.
- It is used for implementing various search algorithms.
- It is helpful in organizing a sorted stream of data.

## 3. What are tree traversals?

Tree traversal is the process of visiting all the nodes of a tree. Since the root (head) is the first node and all nodes are connected via edges (or links) we always start with that node. There are three ways which we use to traverse a tree −

1. Inorder Traversal:

- Step 1. Traverse the left subtree, i.e., call Inorder(root.left)
- Step 2. Visit the root.
- Step 3. Traverse the right subtree, i.e., call Inorder(root.right)
- Inorder traversal in Java:
- Uses: In binary search trees (BST), inorder traversal gives nodes in ascending order.

2. Preorder Traversal:

- Step 1. Visit the root.
- Step 2. Traverse the left subtree, i.e., call Preorder(root.left)
- Step 3. Traverse the right subtree, i.e., call Preorder(root.right)
- Preorder traversal in Java:
- Preorder traversal is commonly used to create a copy of the tree.
- It is also used to get prefix expression of an expression tree.

3. Postorder Traversal:

- Step 1. Traverse the left subtree, i.e., call Postorder(root.left)
- Step 2. Traverse the right subtree, i.e., call Postorder(root.right)
- Step 3. Visit the root.
- Postorder traversal in Java:
- Postorder traversal is commonly used to delete the tree.
- It is also useful to get the postfix expression of an expression tree.

Consider the following tree as an example, then:

- Inorder Traversal => Left, Root, Right : [4, 2, 5, 1, 3]
- Preorder Traversal => Root, Left, Right : [1, 2, 4, 5, 3]
- Postorder Traversal => Left, Right, Root : [4, 5, 2, 3, 1]

## 4. What is a deque data structure and its types? What are the applications for deque?

A deque can be thought of as an array of items, but with one important difference: Instead of pushing and popping items off the end to make room, deques are designed to allow items to be inserted at either end. This property makes deques well-suited for performing tasks such as keeping track of inventory, scheduling tasks, or handling large amounts of data.

There are two types of deque:

- Input Restricted Deque: Insertion operations are performed at only one end while deletion is performed at both ends in the input restricted queue.

- Output Restricted Deque: Deletion operations are performed at only one end while insertion is performed at both ends in the output restricted queue.

Following are some real-time applications for deque data structure:

- It can be used as both stack and queue, as it supports all the operations for both data structures.
- Web browser’s history can be stored in a deque.
- Operating systems job scheduling algorithm.

## 5. What are some key operations performed on the Deque data structure?

Following are the key operations available deque:

- insertFront() : This adds an element to the front of the Deque.
- insertLast() : This adds an element to the rear of the Deque.
- deleteFront() : This deletes an element from the front of the Deque.
- deleteLast() :This deletes an element from the front of the Deque.
- getFront() : This gets an element from the front of the Deque.
- getRear() : This gets an element from the rear of the Deque.
- isEmpty() : This checks whether Deque is empty or not.
- isFull() : This checks whether Deque is full or not.

## 6. What is a priority queue? What are the applications for priority queue?

Priority Queue is an abstract data type that is similar to a queue in that each element is assigned a priority value. The order in which elements in a priority queue are served is determined by their priority (i.e., the order in which they are removed). If the elements have the same priority, they are served in the order they appear in the queue.

Following are some real-time applications for priority queue:

- Used in graph algorithms like Dijkstra, Prim’s Minimum spanning tree etc.
- Huffman code for data compression
- Finding Kth Largest/Smallest element

## 7. Compare different implementations of priority queue

The following table contains an asymptotic analysis of different implementations of a priority queue:

## 8. What is graph data structure and its representations? What are the applications for graphs?

A graph is a type of non-linear data structure made up of nodes and edges. The nodes are also known as vertices, and edges are lines or arcs that connect any two nodes in the graph.

The following are the two most common graph representations:

1. Adjacency Matrix : Adjacency Matrix is a two-dimensional array with the dimensions V x V, where V is the number of vertices in a graph. Representation is simpler to implement and adhere to. It takes O(1) time to remove an edge. Queries such as whether there is an edge from vertex 'u' to vertex 'v' are efficient and can be completed in O(1).

One of the cons of this representation is that even if the graph is sparse (has fewer edges), it takes up the same amount of space. Adding a vertex takes O(V^2). It also takes O(V) time to compute all of a vertex's neighbours, which is not very efficient.

2. Adjacency List: In this method, each Node holds a list of Nodes that are directly connected to that vertex. Each node at the end of the list is connected with null values to indicate that it is the last node in the list. This saves space O(|V|+|E|). In the worst-case scenario, a graph can have C(V, 2) edges, consuming O(V^2) space. It is simpler to add a vertex. It takes the least amount of time to compute all of a vertex's neighbours.

One of the cons of this representation is that queries such as "is there an edge from vertex u to vertex v?" are inefficient and take O (V) in the worst case.

## 9. What is the difference between the Breadth First Search (BFS) and Depth First Search (DFS)?

## 10. What is AVL tree data structure, its operations, and its rotations? What are the applications for AVL trees?

AVL trees are height balancing binary search trees named after their inventors Adelson, Velski, and Landis. The AVL tree compares the heights of the left and right subtrees and ensures that the difference is less than one. This distinction is known as the Balance Factor.

BalanceFactor = height(left-subtree) − height(right-subtree)

We can perform the following two operations on AVL tree:

- Insertion: Insertion in an AVL tree is done in the same way that it is done in a binary search tree. However, it may cause a violation in the AVL tree property, requiring the tree to be balanced. Rotations can be used to balance the tree.
- Deletion: Deletion can also be performed in the same manner as in a binary search tree. Because deletion can disrupt the tree's balance, various types of rotations are used to rebalance it.

An AVL tree can balance itself by performing the four rotations listed below:

- Left rotation: When a node is inserted into the right subtree of the right subtree and the tree becomes unbalanced, we perform a single left rotation.
- Right rotation: If a node is inserted in the left subtree of the left subtree, the AVL tree may become unbalanced. The tree then requires right rotation.
- Left-Right rotation: The RR rotation is performed first on the subtree, followed by the LL rotation on the entire tree.
- Right-Left rotation: The LL rotation is performed first on the subtree, followed by the RR rotation on the entire tree.

Following are some real-time applications for AVL tree data structure:

- AVL trees are typically used for in-memory sets and dictionaries.
- AVL trees are also widely used in database applications where there are fewer insertions and deletions but frequent data lookups are required.
- Apart from database applications, it is used in applications that require improved searching.

## 11. What is a B-tree data structure? What are the applications for B-trees?

The B Tree is a type of m-way tree that is commonly used for disc access. A B-Tree with order m can only have m-1 keys and m children. One of the primary reasons for using a B tree is its ability to store a large number of keys in a single node as well as large key values while keeping the tree's height relatively small.

A B-tree of order 4 is shown below in the image:

Following are the key properties of a B-tree data structure:

- All of the leaves are at the same height.
- The term minimum degree 't' describes a B-Tree. The value of t is determined by the size of the disc block.
- Except for root, every node must have at least t-1 keys. The root must contain at least one key.
- All nodes (including root) can have no more than 2*t - 1 keys.
- The number of children of a node is equal to its key count plus one.
- A node's keys are sorted in ascending order. The child of two keys k1 and k2 contains all keys between k1 and k2.
- In contrast to Binary Search Tree, B-Tree grows and shrinks from the root.

Following are real-time applications of a B-Tree data structure:

- It is used to access data stored on discs in large databases.
- Using a B tree, you can search for data in a data set in significantly less time.
- The indexing feature allows for multilevel indexing.
- The B-tree approach is also used by the majority of servers.

## 12. Define Segment Tree data structure and its applications.

A segment Tree is a binary tree that is used to store intervals or segments. The Segment Tree is made up of nodes that represent intervals. Segment Tree is used when there are multiple range queries on an array and changes to array elements.

The segment tree of array A[7] will look like this:

Following are key operations performed on the Segment tree data structure:

- Building Tree: In this step, we create the structure and initialize the segment tree variable.
- Updating the Tree: In this step, we change the tree by updating the array value at a point or over an interval.
- Querying Tree: This operation can be used to run a range query on the array.

Following are real-time applications for Segment Tree:

- Used to efficiently list all pairs of intersecting rectangles from a list of rectangles in the plane.
- The segment tree has become popular for use in pattern recognition and image processing.
- Finding range sum/product, range max/min, prefix sum/product, etc
- Computational geometry
- Geographic information systems
- Static and Dynamic RMQ (Range Minimum Query)
- Storing segments in an arbitrary manner

## 13. Define Trie data structure and its applications

The word "Trie" is an abbreviation for "retrieval." Trie is a data structure that stores a set of strings as a sorted tree. Each node has the same number of pointers as the number of alphabet characters. It can look up a word in the dictionary by using its prefix. Assuming that all strings are formed from the letters 'a' to 'z' in the English alphabet, each trie node can have a maximum of 26 points.

Trie is also referred to as the digital tree or the prefix tree. The key to which a node is connected is determined by its position in the Trie. Trie allows us to insert and find strings in O(L) time, where L is the length of a single word. This is clearly faster than BST. Because of how it is implemented, this is also faster than Hashing. There is no need to compute a hash function. There is no need to handle collisions (like we do in open addressing and separate chaining)

Another benefit of Trie is that we can easily print all words in alphabetical order, which is not easy with hashing. Trie can also perform prefix search (or auto-complete) efficiently.

The main disadvantage of tries is that they require a large amount of memory to store the strings. We have an excessive number of node pointers for each node

Following are some real-time applications for Trie data structure:

- Auto-Complete and Search for Search Engines
- Genome Analysis
- Data Analytics
- Browser History
- Spell Checker

## 14. Define Red-Black Tree and its applications

Red Black Trees are a type of self-balancing binary search tree. Rudolf Bayer invented it in 1972 and dubbed it "symmetric binary B-trees."

A red-black tree is a Binary tree in which each node has a colour attribute, either red or black. By comparing the node colours on any simple path from the root to a leaf, red-black trees ensure that no path is more than twice as long as any other, ensuring that the tree is generally balanced.

Red-black trees are similar to binary trees in that they both store their data in two's complementary binary formats. However, red-black trees have one important advantage over binary trees: they are faster to access. Because red-black trees are so fast to access, they are often used to store large amounts of data.

Red-black trees can be used to store any type of data that can be represented as a set of values.

Every Red-Black Tree Obeys the Following Rules:

- Every node is either red or black.
- The tree's root is always black.
- There are no two red nodes that are adjacent.
- There is the same number of black nodes on every path from a node to any of its descendant's NULL nodes.
- All of the leaf nodes are black.

Following are some real-time applications for the Red-Black Tree data structure:

- The majority of self-balancing BST library functions in C++ or Java use Red-Black Trees.
- It is used to implement Linux CPU Scheduling.
- It is also used to reduce time complexity in the K-mean clustering algorithm in machine learning.
- MySQL also employs the Red-Black tree for table indexes in order to reduce searching and insertion time.

## 15. Which data structures are used for implementing LRU cache?

LRU cache or Least Recently Used cache allows quick identification of an element that hasn’t been put to use for the longest time by organizing items in order of use. In order to achieve this, two data structures are used:

- Queue – This is implemented using a doubly-linked list. The maximum size of the queue is determined by the cache size, i.e by the total number of available frames. The least recently used pages will be near the front end of the queue whereas the most recently used pages will be towards the rear end of the queue.
- Hashmap – Hashmap stores the page number as the key along with the address of the corresponding queue node as the value.

## 16. What is a heap data structure?

Heap is a special tree-based non-linear data structure in which the tree is a complete binary tree. A binary tree is said to be complete if all levels are completely filled except possibly the last level and the last level has all elements as left as possible. Heaps are of two types:

- In a Max-Heap the data element present at the root node must be the greatest among all the data elements present in the tree.
- This property should be recursively true for all sub-trees of that binary tree.
- In a Min-Heap the data element present at the root node must be the smallest (or minimum) among all the data elements present in the tree.

## Data Structure Coding Interview Questions

1. write a program to remove duplicates from a sorted array in place.

- Input : {1, 1, 1, 2, 3, 3, 6, 6, 7}
- Output : {1, 2, 3, 6, 7}
- Explanation : The given input has only 1,2,3,6, and 7 as unique elements, hence the output only lists them out.
- Time Complexity : O(n)
- Space Complexity: O(1)

## 2. Write a function for zigzag traversal in a binary tree

- Output: [1, 3, 2, 4, 5, 6, 8, 7]
- Explanation: Zigzag Traversal first iterates the given level of the tree from left to right and then the next level as the right to the level.
- Space Complexity: O(n)

## 3. Write a function to sort a linked list of 0s, 1s and 2s

- Input: 0->1->0->2->1->0->2->1
- Output: 0->0->0->1->1->1->2->2
- Explanation : All 0’s will come first then 1s and then 2s. This can be done in O(n) time by counting the occurrences of all three and rearranging them in the linked list.

## 4. Write a function to detect cycle in an undirected graph

- Input: n = 4, e = 4 , 0 1, 1 2, 2 3, 3 1
- Output: Yes
- Explanation : The graph is represented as follows in adjacency list representation: 0->1 1->2 2->3 3->1

From the above representation, we can see that there exists a cycle: 1→2→3→1

- Time Complexity: O(V+E)
- Space Complexity: O(V)

## 5. Write a function to convert an infix expression to postfix expression

- Input: a+b*(c^d)
- Output: abcd^*+
- Time Complexity: O(n)

## 6. Write a function to find the maximum for each and every contiguous subarray of size k.

- Input: N = 9, K = 3 arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}
- Output: {3, 3, 4, 5, 5, 5, 6}
- Explanation : In the first subarray of size 3: {1,2,3}, the value 3 is maximum, similarly for all such subarrays for size 3.
- Space Complexity: O(k)

## 7. Write a function to merge two sorted binary search tree

/ \

5 9

Output: 3 4 5 6 7 9 12

- Time Complexity: O(m+n)
- Space Complexity: O(height of the first tree + height of the second tree)

## 8. Write a function to print all unique rows of the given matrix.

{{1, 1, 1, 0, 0},

{0, 1, 0, 0, 1},

{1, 0, 1, 1, 0},

{1, 1, 1, 0, 0}}

{{1, 1, 1, 0, 0},

{0, 1, 0, 0, 1},

{1, 0, 1, 1, 0}}

- Time Complexity: O( ROW x COL )
- Space Complexity: O( ROW )

## 9. Write a function to find number of subarrays with product less than K

- Input: arr = [1, 6, 2, 3, 2, 1], k = 12

## 10. Find the subsequence of length 3 with the highest product from a sequence of non-negative integers, with the elements in increasing order.

- Input: n = 8 arr[ ] = {6, 7, 10, 1, 2, 3, 11, 12}
- Output: {10, 11, 12}

The three increasing elements of the given arrays are 10, 11, and 12, which form a three-size subsequence with the highest product.

- Time Complexity: O(nlog(n))

## 11. Write a function to implement Quicksort on Doubly Linked List

- Input: 8<->10<->1<->7<->6
- Output: 1<->6<->7<->8<->10
- Time Complexity: O(n^2) in the worst case when the list is already sorted. O(nlog(n)) in the best and average case.

## 12. Write a function to connect nodes at the same level of a binary tree

Input: 100

/ \

13 15

/ \ \

14 1 20

Output: 100-> NULL

/ \

13 -> 15 -> NULL

/ \ \

14 -> 1 -> 20 -> NULL

## 13. Write a function to find number of structurally unique binary trees are possible

Input: N = 3

Output: 5 for N = 3, there are 5 possible BSTs:

1 3 3 2 1

\ / / / \ \

3 2 1 1 3 2

/ / \ \

2 1 2 3

- Time Complexity: O(n)

## 14. Implement LRU(Least Recently Used) Cache

- Time Complexity: O(1) to get an element

## 15. Write a function to determine whether duplicate elements in a given array are within a given distance of each other.

- Input: arr[] = {1, 2, 3, 4, 2, 1, 2} range=3
- Output: True

## 16. Write a recursive function to calculate the height of a binary tree in Java.

- Consider that every node of a tree represents a class called Node as given below:
- Then the height of the binary tree can be found as follows:

## 17. Write Java code to count number of nodes in a binary tree

int countNodes (Node root) { int count = 1 ; //Root itself should be counted if (root == null ) return 0 ; else { count += countNodes(root.left); count += countNodes(root.right); return count; } }

## 18. Print Left view of any binary trees.

- The main idea to solve this problem is to traverse the tree in pre order manner and pass the level information along with it. If the level is visited for the first time, then we store the information of the current node and the current level in the hashmap. Basically, we are getting the left view by noting the first node of every level.
- At the end of traversal, we can get the solution by just traversing the map.
- Consider the following tree as example for finding the left view:
- Left view of a binary tree in Java:

## 19. Given an m x n 2D grid map of '1’s which represents land and '0’s that represents water return the number of islands (surrounded by water and formed by connecting adjacent lands in 2 directions - vertically or horizontally).

Assume that the boundary cases - which are all four edges of the grid are surrounded by water., constraints are:, m == grid.length n == grid[i].length 1 <= m, n <= 300 grid[i][j] can only be ‘0’ or ‘1’., input: grid = [ [“1” , “1” , “1” , “0” , “0”], [“1” , “1” , “0” , “0” , “0”], [“0” , “0” , “1” , “0” , “1”], [“0” , “0” , “0” , “1” , “1”] ], 20. what is topological sorting in a graph.

- Topological sorting is a linear ordering of vertices such that for every directed edge ij, vertex i comes before j in the ordering.
- Topological sorting is only possible for Directed Acyclic Graph (DAG).
- jobs scheduling from the given dependencies among jobs.
- ordering of formula cell evaluation in spreadsheets
- ordering of compilation tasks to be performed in make files,
- data serialization
- resolving symbol dependencies in linkers.
- Topological Sort Code in Java:

In this post, we covered the most important and frequently asked Data Structures interview questions. We've also included some pointers and tricks to help you prepare for the interview. When preparing for the product-based companies interview, keep in mind that the Data Structures interview is a critical component of the process. It is critical that you are well prepared for the interview because it will determine whether or not you are hired. As a result, it is critical to begin planning as soon as possible.

## Additional Interview Resources

- Programming: DSA - https://www.interviewbit.com/courses/programming/
- Data Structure MCQ - https://www.interviewbit.com/data-structure-mcq/
- Best Books for Data Structures and Algorithms - https://www.interviewbit.com/blog/data-structures-and-algorithms-books/
- Best Data Structures and Algorithms Course - https://www.interviewbit.com/blog/best-courses-for-data-structures-and-algorithms/
- Free Java DSA Certification Course - https://www.scaler.com/topics/course/dsa-beginners-java/
- Algorithm Interview Questions - https://www.interviewbit.com/algorithm-interview-questions/
- Master Data Structures and Algorithms With the Scaler Academy Program - https://www.scaler.com/courses/data-structures-and-algorithms/
- Difference Between Array and Linked List - https://www.scaler.com/topics/difference-between-array-and-linked-list/

## Coding Problems

Which of the following is a non-linear data structure?

Which of the following data structures is linear?

Which data structure is used for implementing recursion?

Which of the following data structures are indexed structures?

Stack data structure cannot be used for

Which of the following data structures is preferred in the implementation of a database system?

How can memory be saved when storing colour information in a Red-Black tree?

Which of the following data structures is best for searching words in dictionaries?

Which of the following statement is true:

What is the worst-case time complexity of inserting n elements into an empty linked list that must be kept in sorted order?

Which of the following data structure can’t store the non-homogeneous data elements?

A directed graph is _______ if there is a path from each vertex to every other vertex in the graph.

In what traversal we process all of a vertex’s descendants before we move to an adjacent vertex?

In circular queue, the value of REAR would be?

Which of the following statement is true?

- Statement i) Using singly linked lists and circular list, it is not possible to traverse the list backwards.
- Statement ii) To find the predecessor, it is required to traverse the list from the first node in case of singly linked list.

The binary search method needs no more than ________ comparisons.

Which of the following are the properties of a binary tree?

Which of the following scenario is true for the statement - “Arrays are best data structures”?

Which of the following code snippet is used to convert decimal to binary numbers?

What will be the final elements on the stack if the following sequence of operations are executed?

Dijkstra’s Algorithm cannot be applied on which of the following?

- Privacy Policy

- Practice Questions
- Programming
- System Design
- Fast Track Courses
- Online Interviewbit Compilers
- Online C Compiler
- Online C++ Compiler
- Online Java Compiler
- Online Javascript Compiler
- Online Python Compiler
- Interview Preparation
- Java Interview Questions
- Sql Interview Questions
- Python Interview Questions
- Javascript Interview Questions
- Angular Interview Questions
- Networking Interview Questions
- Selenium Interview Questions
- Data Science Interview Questions
- System Design Interview Questions
- Hr Interview Questions
- Html Interview Questions
- C Interview Questions
- Amazon Interview Questions
- Facebook Interview Questions
- Google Interview Questions
- Tcs Interview Questions
- Accenture Interview Questions
- Infosys Interview Questions
- Capgemini Interview Questions
- Wipro Interview Questions
- Cognizant Interview Questions
- Deloitte Interview Questions
- Zoho Interview Questions
- Hcl Interview Questions
- Highest Paying Jobs In India
- Exciting C Projects Ideas With Source Code
- Top Java 8 Features
- Angular Vs React
- 10 Best Data Structures And Algorithms Books
- Best Full Stack Developer Courses
- Best Data Science Courses
- Python Commands List
- Data Scientist Salary
- Maximum Subarray Sum Kadane’s Algorithm
- Python Cheat Sheet
- C++ Cheat Sheet
- Javascript Cheat Sheet
- Git Cheat Sheet
- Java Cheat Sheet
- Data Structure Mcq
- C Programming Mcq
- Javascript Mcq

1 Million +

- HTML Cheat Sheet
- CSS Cheat Sheet
- JS Cheat Sheet
- Bootstrap Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro SDE Sheet
- Infosys SDE Sheet
- TCS SDE Sheet
- Cognizant SDE Sheet
- HCL SDE Sheet
- Mass Recruiters Sheet
- Product-Based Coding Sheet
- Company-Wise Practice Sheet
- Love Babbar Sheet

- Solve Coding Problems
- DSA Sheet by Love Babbar
- Commonly Asked Data Structure Interview Questions
- Java Collections Interview Questions and Answers
- Recently Asked Interview Questions in Product Based Companies
- Top 50 Problems on Heap Data Structure asked in SDE Interviews
- Top 25 Frequently Asked Interview Questions in Technical Rounds
- Top 50 Problems on Stack Data Structure asked in SDE Interviews
- Top 20 Backtracking Algorithm Interview Questions
- Puzzle | The Apocalypse
- Top 20 Hashing Technique based Interview Questions
- Top 20 Dynamic Programming Interview Questions
- What happens Array is not initialized?
- What is meant by dimensionality of an Array?
- Top 50 Problems on Linked List Data Structure asked in SDE Interviews
- Java Interview Questions and Answers
- Top 50 Problems on Recursion Algorithm asked in SDE Interviews
- Top 20 Greedy Algorithms Interview Questions
- Applications, Advantages and Disadvantages of Binary Search Tree
- Commonly Asked Algorithm Interview Questions | Set 1

## Top 100 Data Structure and Algorithms DSA Interview Questions Topic-wise

DSA has been one of the most popular go-to topics for any interview, be it college placements, software developer roles, or any other technical roles for freshers and experienced to land a decent job. If you are among them, you already know that it is not easy to find the best DSA interview questions among the vast pool of available problems. So here we are, with the Top 100 most asked DSA interview questions to help you sail through your technical rounds.

Top 100 Data Structure and Algorithms (DSA) Interview Questions Topic-wise

Table of Content

## DSA Interview Questions on Array

Dsa interview questions on matrix, dsa interview questions on string, dsa interview questions on linked list, dsa interview questions on stack & queue, dsa interview questions on tree, dsa interview questions on heap, dsa interview questions on graph, dsa interview questions on dynamic programming, dsa interview questions on bit manipulations.

In this Top 100 DSA interview questions, we have segregated the problems based on the Data structure or algorithm used to solve them . Without further delay, let us begin your interview preparations:

- Check if pair with the given Sum exists in Array
- Best Time to Buy and Sell Stock
- Find duplicates
- Product of Array Except Self
- Maximum Subarray
- Maximum Product Subarray
- Find Minimum in Rotated Sorted Array
- Search in Rotated Sorted Array
- Container With Most Water
- Find the Factorial of a large number
- Trapping Rain Water
- Chocolate Distribution Problem
- Insert Interval
- Merge Intervals
- Non-overlapping Intervals
- Set Matrix Zeroes
- Spiral Matrix
- Program to find the transpose of a matrix
- Word Search
- Longest Substring Without Repeating Characters
- Longest Repeating Character Replacement
- Smallest window in a String containing all characters of other String
- Check whether two Strings are anagram of each other
- print all anagrams together
- Check if given Parentheses expression is balanced or not
- Sentence Palindrome
- Longest Palindromic Substring
- Palindromic Substrings
- Longest Common Prefix
- Reverse a Linked List
- Detect Cycle in a Linked List
- Merge Two Sorted Lists
- Merge K Sorted Lists
- Remove Nth Node From End Of List
- Reorder List
- Add 1 to a number represented as linked list
- Find the middle of a given linked list
- Delete last occurrence of an item from linked list
- Convert Infix expression to Postfix expression
- Next Greater Element
- Delete middle element of a stack
- Check mirror in n-ary tree
- The Celebrity Problem
- Length of the longest valid substring
- Print Right View of a Binary Tree
- Find the first circular tour that visits all petrol pumps
- Maximum Depth of Binary Tree
- Check if two trees have same structure
- Invert/Flip Binary Tree
- Binary Tree Maximum Path Sum
- Binary Tree Level Order Traversal
- Serialize and Deserialize Binary Tree
- Subtree of Another Tree
- Construct Binary Tree from Preorder and Inorder Traversal
- Validate Binary Search Tree
- Kth Smallest Element in a BST
- Lowest Common Ancestor of BST
- Implement Trie (Prefix Tree)
- Add and Search Word
- Top K Frequent Elements
- Find Median from Data Stream
- Largest triplet product in a stream
- Connect n ropes with minimum cost
- Clone Graph
- Course Schedule
- Pacific Atlantic Water Flow
- Number of Islands
- Longest Consecutive Sequence
- Snake and Ladder Problem
- Detect Cycle in a Directed Graph
- Bridges in a graph
- Check whether a given graph is Bipartite or not
- Find size of the largest region in Boolean Matrix
- Flood fill Algorithm
- Strongly Connected Components
- Topological Sorting
- Count ways to reach the n’th stair
- Coin Change
- 0/1 Knapsack Problem
- Longest Increasing Subsequence
- Longest Common Subsequence
- Word Break Problem
- Dice Throw
- Egg Dropping Puzzle
- Matrix Chain Multiplication
- Combination Sum
- Subset Sum Problem
- Find maximum possible stolen value from houses
- Count Possible Decodings of a given Digit Sequence
- Unique paths in a Grid with Obstacles
- Cutting a Rod
- Maximum Product Cutting
- Count number of ways to cover a distance
- Number of 1 Bits
- Counting Bits
- Missing Number
- Reverse Bits
- Find XOR of all subsets of a set

Related posts:

- Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …

Some other important Tutorials:

- DSA Tutorial
- System Design Tutorial
- Software Development Roadmap
- Roadmap to become a Product Manager

## Please Login to comment...

- interview-preparation
- interview-questions
- RishabhPrabhu

## IMAGES

## VIDEO

## COMMENTS

Prepare Data Structures Data Structures Arrays - DS EasyProblem Solving (Basic)Max Score: 10Success Rate: 93.24% Solve Challenge 2D Array - DS EasyProblem Solving (Basic)Max Score: 15Success Rate: 93.16% Solve Challenge Dynamic Array EasyProblem Solving (Basic)Max Score: 15Success Rate: 86.77% Solve Challenge Left Rotation

6. List out the areas in which data structures are applied extensively. Following are the areas in which data structures are applied extensively. • Operating system- the data structures like priority queues are used for scheduling the jobs in the operating system. • Compiler design- the tree data structure is used in parsing the source program.

In this Beginner DSA Sheet for Data Structures and Algorithms, we have curated a selective list of problems for you to solve as a beginner for DSA. After learning the fundamentals of programming, choosing a programming language, and learning about Data Structure and Algorithms and their space-time complexity, it becomes necessary to practice the problem based on different data structures and ...

Policies There will be a weekly one-page assignment, 10 assignments in total. You may skip any one problem, or we will ignore the problem with the lowest grade. If you volunteered to scribe twice, we will ignore the lowest two grades. The answers must be typeset in LaTeX. The answers must fit in one page, or your solution will not be read.

Overview The fourth assignment is mostly about stacks and queues. For the former you'll build a simple calculator application, for the latter you'll implement the data structure in a way that satisfies certain performance characteristics (in addition to the usual correctness properties). Problem 1: Calculating Stacks (50%)

Top MCQs on Queue Data Structure with Answers. Heap. Top MCQs on Heap Data Strcuture with Answers. Hashing. Top MCQs on Hash Data Strcuture with Answers. Tree. Top MCQs on Tree Traversal with Interview Question and Answers. Top MCQs on Binary Search Tree (BST) Data Structure with Answers.

ESO207A: Data Structures and Algorithms End-semester exam Max marks: 120 Time: 180 mins. 17-July-2017 1.Answer all 7 questions. Questions 1 to 3 are from module 3 and questions 4 to 7 are from module 4. Each module is worth 60 marks. The question paper has 4 pages. 2. Answer all parts of a question together. Do not scatter them across the ...

Question 1 Show how to implement a queue using 2 stacks (no Java code is needed, just a sketch and pseudo code) (11 points). What are the complexities of enqueue() (2 points) and dequeue() operations (2 points)? Note: A stack is a data structure with push(), pop(), and isEmpty() operations; a queue is

Module 1 • 4 hours to complete. In this module, you will learn about the basic data structures used throughout the rest of this course. We start this module by looking in detail at the fundamental building blocks: arrays and linked lists. From there, we build up two important data structures: stacks and queues.

1 Example. You want to store the names of weekdays and access them by the number of a day within the week. Answer. An array, because the number of weekdays is xed, and access by index has to be cient. You want to store the stations of a public transportation line.

What is Data Structure: A data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently. A data structure is not only used for organizing the data. It is also used for processing, retrieving, and storing data.

Programming problem 1: Implement a stack using an array. Implement the stack interface defined . Use generics in Java to make sure that you can use the stack for any type of data. You may assume that the number of elements inserted into the stack never exceeds 100,000. Do use the inbuilt Stack class of java. Name your stack implementation as

NPTEL :: Computer Science and Engineering - Data Structures And Algorithms. Courses. Computer Science and Engineering. Data Structures And Algorithms (Video) Syllabus. Co-ordinated by : IIT Delhi. Available from : 2009-12-31. Lec : 1.

8. What do you understand by spanning tree? 9. Define hash table. 10 .Define sorting. Short Answer type Questions (4 X 5) Q1. Define STACK. Explain its operations Q2. Explain the concept of circular linked list. Q3. Define terms of tree: Parent, Degree of a node, Path, Depth , Degree of a node. Q4.

Data Structures - Assignments. In Emertxe each one of our Assignments will ensure you apply the concept you have leant in your classroom. By solving these assignments, you will go through a systematic problem-solving approach which include requirement understanding, algorithm design, pseudocode creation, dry run and final execution.

November 27, 2022 by veer Data Structures Question Bank With Answers PDF: Are you a student and facing trouble in finding the right questions for your preparation for data structures exam? Students can overcome this problem just by downloading the data structures question bank with answers PDF, and it will eliminate all the troubles.

Syllabus, Spring 2024 Welcome to Data Structures, CS112. After completing the course the student will be able to: Analyze runtime efficiency of algorithms related to data structure design. Select appropriate abstract data types for use in a given application.

Question 2 Which one of the following is an application of Queue Data Structure? When a resource is shared among multiple consumers. When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes Load Balancing All of the above

76 Data Structures and Algorithms Interview Questions [2024 Prep Guide] Algorithms and data structures are foundational to computer science. As the scaffolding for programming languages, tech recruiters place an emphasis on algorithms and data structures in interviews.

Data Structures are mainly classified into two types: Linear Data Structure: A data structure is called linear if all of its elements are arranged in the sequential order. In linear data structures, the elements are stored in a non-hierarchical way where each item has the successors and predecessors except the first and last element.

Question 1: What is an array? Answer: An array is a data structure consisting of a collection of elements, each identified by at least one array index or key. Question 2: Can an array be resized at runtime? Answer: In some programming languages, arrays can be resized dynamically, while in others, such as C, the size is fixed.

1. What are Data Structures? A data structure is a mechanical or logical way that data is organized within a program. The organization of data is what determines how a program performs. There are many types of data structures, each with its own uses. When designing code, we need to pay particular attention to the way data is structured.

DSA Interview Questions on Tree. Maximum Depth of Binary Tree. Check if two trees have same structure. Invert/Flip Binary Tree. Binary Tree Maximum Path Sum. Binary Tree Level Order Traversal. Serialize and Deserialize Binary Tree. Subtree of Another Tree. Construct Binary Tree from Preorder and Inorder Traversal.