Data Structures

Arrays - ds easy problem solving (basic) max score: 10 success rate: 93.23%, 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.11%, 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.25%, 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%.

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).

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.

MIT Open Learning

Learn Python practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn python interactively, learn ds & algorithms.

A computer program is a collection of instructions to perform a specific task. For this, a computer program may need to store data, retrieve data, and perform computations on the data.

A data structure is a named location that can be used to store and organize data. And, an algorithm is a collection of steps to solve a particular problem. Learning data structures and algorithms allow us to write efficient and optimized computer programs.

Our DSA tutorial will guide you to learn different types of data structures and algorithms and their implementations in Python, C, C++, and Java.

Do you want to learn DSA the right way? Enroll in our Interactive DSA Course for FREE.

  • Introduction

Data Structures (I)

Data structures (ii), tree based dsa (i), tree based dsa (ii), graph based dsa.

  • Sorting and Searching

Greedy Algorithms

  • Dynamic Programming

Other Algorithms

  • How to learn DSA?

DSA Introduction

  • What is an algorithm?
  • Data Structure and Types
  • Why learn algorithms?
  • Asymptotic Notations
  • Master Theorem
  • Divide and Conquer Algorithm
  • Types of Queue
  • Circular Queue
  • Priority Queue
  • Linked List
  • Linked List Operations
  • Types of Linked List
  • Heap Data Structure
  • Fibonacci Heap
  • Decrease Key and Delete node from Fibonacci Heap
  • Tree Data Structure
  • Tree Traversal
  • Binary Tree
  • Full Binary Tree
  • Perfect Binary Tree
  • Complete Binary Tree
  • Balanced Binary Tree
  • Binary Search Tree
  • Insertion into B-tree
  • Deletion from B-tree
  • Insertion on a B+ Tree
  • Deletion from a B+ Tree
  • Red Black Tree
  • Insertion in Red Black Tree
  • Deletion from Red Black Tree
  • Graph Data Structure
  • Spanning Tree
  • Strongly Connected Components
  • Adjacency Matrix
  • Adjacency List
  • DFS Algorithm
  • Breadth-first Search
  • Bellman Ford's Algorithm

Sorting and Searching Algorithms

  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Counting Sort
  • Bucket Sort
  • Linear Search
  • Binary Search
  • Greedy Algorithm
  • Ford-Fulkerson Algorithm
  • Dijkstra's Algorithm
  • Kruskal's Algorithm
  • Prim's Algorithm
  • Huffman Code
  • Floyd Warshall Algorithm
  • Longest Common Subsequence
  • Backtracking Algorithm
  • Rabin-Karp Algorithm

Why Learn DSA?

  • Write optimized and scalable code - Once you have knowledge about different data structures and algorithms, you can determine which data structure and algorithm to choose in various conditions.
  • Effective use of time and memory - Having knowledge about data structures and algorithms will help you write codes that run faster and require less storage.
  • Better job opportunities - Data structures and algorithms questions are frequently asked in job interviews of various organizations including Google, Facebook, and so on.

How you can learn data structure and algorithms?

Interactive dsa course.

Want to learn DSA with Python by solving quizzes and challenges after learning each concept? Enroll in our DSA Interactive Course for FREE.

Learn DSA from Programiz

Programiz offers a complete series of easy to follow DSA tutorials along with suitable examples. These tutorials are targeted for absolute beginners who want to dive into the field of computer programming.

Learn DSA from Books

Learning from books is always a good practice. You will get the big picture of programming concepts in the book which you may not find elsewhere.

Here are some books we personally recommend.

  • Introduction to Algorithms, Thomas H. Cormen - it is one of the best books in algorithms and covers a broad range of algorithms in-depth
  • Algorithms, Robert Sedgewick - it is the leading textbook on algorithms and is widely used in colleges and universities
  • The Art of Computer Programming, Donald E. Knuth - this book is considered best if you know the subject and are looking for deeper understanding

Learn DSA through visualization

Once you have some idea about data structure and algorithms, there is a great resource at Data Structure Visualizations that lets you learn through animation.

BTech Geeks

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.

  • 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

Javatpoint Logo

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

binary search engine

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

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence Tutorial

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking Tutorial

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering Tutorial

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

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:

  • DSA Tutorial
  • Data Structures
  • Linked List
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Divide & Conquer
  • Mathematical
  • Backtracking
  • Branch and Bound
  • Pattern Searching

Related Articles

  • 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

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:

  • System Design Tutorial
  • Software Development Roadmap
  • Roadmap to become a Product Manager

Please Login to comment...

  • interview-preparation
  • interview-questions
  • RishabhPrabhu

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

data structure assignment questions

Online Embedded Systems Course with Placements

Advanced Embedded Course With Placements

Advanced Embedded Course With Placements

Online Embedded IoT Course

Online Embedded IoT Course

Advanced Embedded IoT Course With Placements

Advanced Embedded IoT Course With Placements

Linux Device Drivers

Linux Device Drivers

Embedded

IoT Internship

Campus Ambassador Program

Campus Ambassador Program

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

Schedule a Call

With Our Career Counsellor

Invalid value

  • Register now!

IMAGES

  1. Data Structure Assignment

    data structure assignment questions

  2. Solved TCSS 342

    data structure assignment questions

  3. Data Structure and Algorithm: RTU DAA Question Paper

    data structure assignment questions

  4. Top 22+ Data Structures Practice Questions

    data structure assignment questions

  5. Data structure multiple choice questions

    data structure assignment questions

  6. Solved This assignment involves the stack data structure and

    data structure assignment questions

VIDEO

  1. DATA STRUCTURES

  2. Introduction to Data Structures

  3. Lecture 8: Introduction to Data Structure

  4. DATA STRUCTURES

  5. DATA STRUCTURES

  6. Data Structure Revision ( Chapter 3 : Algorithms Complexity )

COMMENTS

  1. Solve Data Structures

    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

  2. PDF Cs8391-data Structures Question Bank Unit I

    3. What do you linear data structure? Give example. The linear data structure is the kind of data structure in which the data is linearly arranged. For example- stacks, queues, linked list. 4. List the various operations that can be performed on data structure. Various operations that can be performed on the data structure are • Create

  3. Top 50 Data Structures MCQs with Answers

    Question 1 Which one of the following is an application of Stack Data Structure? Top MCQs on Stack Data Strcuture with Answers Top MCQs on Stack Data Strcuture with Answers Top 50 Data Structures MCQs with Answers Discuss it Question 2 Which one of the following is an application of Queue Data Structure?

  4. Data Structures Tutorial

    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.

  5. PDF Data Structures and Algorithms: Assignment 3

    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 a data structure with enqueue(), dequeue() and isEmpty() operations. Question 2 (20 points) This question will require that you work on RPN.java skeleton file.

  6. Topic wise Quiz on Data Structures

    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.

  7. Assignment 4: Stacking Queues

    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%)

  8. Data Structures

    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.

  9. Assignments

    1 = Your solution was ultimately a good one, but the write-up contained significant errors or omissions. 2 = (We think) you got it. Assignments This section provides the problem sets assigned for the course, solutions, and assignment policies.

  10. PDF ESO207A: Data Structures and Algorithms End-semester exam

    ESO207A: Data Structures and Algorithms End-semester exam Max marks: 120 Time: 180 mins. 17-July-2017 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. Answer all parts of a question together. Do not scatter them across the answer script.

  11. Learn Data Structures and Algorithms

    For this, a computer program may need to store data, retrieve data, and perform computations on the data. A data structure is a named location that can be used to store and organize data. And, an algorithm is a collection of steps to solve a particular problem. Learning data structures and algorithms allow us to write efficient and optimized ...

  12. Data Structures

    Welcome to Data Structures, CS112. After completing the course the student will be able to: ... We use the Java programming language for all assignments and exams in the course. ... Rather than emailing questions to the teaching staff, we encourage you to post your questions on Piazza. If you have any problems or feedback for the developers ...

  13. Python Data Structure Exercise for Beginners

    This data structure exercise is for beginners to understand and practice basic data structure in Python. Practice Python List, Set, Dictionary, and Tuple questions. The data structure is widely used to hold any data. To perform any programming tasks in Python, good knowledge of data structure is a must. Solve this exercise to have a good ...

  14. 76 Data Structures and Algorithms Interview Questions ...

    Data Structures Interview Questions and Answers [General] Introduce Yourself. Make this answer short and pointed. Talk about your educational background and your expertise as a developer. Include some information on your passion for computer science and its applications. Refrain from going into your personal background or interests outside of ...

  15. PDF UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

    Q 2. Create a structure/class for a group of 50 students holding data for their Regn no., Name, Branch, CGPA a) Call linear search function to display data of student with a particular Regn no.. b) Call bubble sort function to arrange data of students according to Regn no. c) Apply binary search on the above output (part b) to display data of a

  16. Data Structures Question Bank With Answers PDF Free Download

    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.

  17. Commonly Asked Data Structure Interview Questions

    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.

  18. Computer Science and Engineering

    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.

  19. Data structure

    Very Short Answer type Questions (2 X 10) 1. Write a short note on abstract data structure. 2. Define array. 3. Write difference between linear array and linked list. 4. Define linked list? 5. What are two ways of representing binary trees in memory? Which one do you prefer and why? 6.

  20. Data Structure Interview Questions (2023)

    1) What is Data Structure? Explain. The data structure is a way that specifies how to organize and manipulate the data. It also defines the relationship between them.

  21. Data Structures Assignment 1

    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. Let S1 and S2 be the two stacks to be used in the implementation of our queue.

  22. Top 100 Data Structure and Algorithms DSA Interview Questions Topic

    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.

  23. Data Structures Assignments

    Learn how to apply the concept of data structures with sample exercises and solutions. Each assignment covers a different data structure, such as single linked list, circular linked list, and tree. Each exercise includes a description, prototype, and output for each function.