Data structures allow programmers to organize and store data in their programs. There are two main categories of data structures: linear and non-linear. Linear data structures like arrays and linked lists store elements in a linear sequence, while non-linear structures like trees and graphs do not. Data structures can also be static or dynamic depending on whether their memory usage is fixed or can change at runtime. Common operations on data structures include insertion, deletion, searching, and traversal of elements. Linked lists are a dynamic data structure that are useful for representing polynomials and sparse matrices due to their flexible memory usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
20 views
Data Structure QB
Data structures allow programmers to organize and store data in their programs. There are two main categories of data structures: linear and non-linear. Linear data structures like arrays and linked lists store elements in a linear sequence, while non-linear structures like trees and graphs do not. Data structures can also be static or dynamic depending on whether their memory usage is fixed or can change at runtime. Common operations on data structures include insertion, deletion, searching, and traversal of elements. Linked lists are a dynamic data structure that are useful for representing polynomials and sparse matrices due to their flexible memory usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7
Data Structure QB
UNIT 1:
[1].What is data structure? Explain different categories of data structure.
Ans: --Data structures are introduced in order to store, organize and manipulate data in programming languages. --A data structure is a logical/mathematical model of oraganization. --Data structures are just a collection of similar or different data types in one. Categories/Classification of data structure:(**if this is not correct ,txt me**)
1)Linear and Non-Linear Data Structures:
• Linear Data Structure: --The elements in a linear data structure form a linear sequence. --Example are: Array, Linked list, Queue, Stack etc. •Non-Linear Data Structure: --The elements in a non-linear data structure do not form any linear sequence. --For example, Tree and Graph.
2)Static and Dynamic Data Structures:
• Static Data Structure: --Static data structures are those whose memory occupation is fixed. --The memory taken by these data structures cannot be increased or decreased at run time. --Example of the static data structure is an Array. --The size of an array isdeclared at the compile time and this size cannot be changed during the run time. • Dynamic Data Structure: --Dynamic data structures are those whose memory occupation is not fixed. --The memory taken by these data structures can be increased or decreased at run time. --Example of the dynamic data structure is Linked List. --The size of linked list can be changed during the run time.
3)Homogeneous and Non-Homogeneous Data Structures
• Homogeneous Data Structure: --Homogeneous data structures are those in which data of same type can be stored. --Example of the homogeneous data structure is an Array. • Non-Homogeneous Data Structure: --Non-Homogeneous data structures are those in which data of different types can be stored. --Example of the non-homogeneous data structure is linked list.
[2].List and explain different operations that can be performed on a data
structure. Ans:Operations performed on Linked list: A linked list is a linear data structure where each node contains a value and a reference to the next node. Here are some common operations performed on linked lists: • Initialization: --A linked list can be initialized by creating a head node with a reference to the first node. --Each subsequent node contains a value and a reference to the next node. • Inserting elements: --Elements can be inserted at the head, tail, or at a specific position in the linked list./OR/Adding a new element in data structure is known as insertion. • Deleting elements: --Elements can be deleted from the linked list by updating the reference of the previous node to point to the next node, effectively removing the current node from the list./OR/Removing an element from data structure is known as deletion. • Searching for elements: --Linked lists can be searched for a specific element by starting from the head node and following the references to the next nodes until the desired element is found./OR/Finding the position of a desired element in the data structure is known as searching. • Updating elements: --Elements in a linked list can be updated by modifying the value of a specific node. • Traversing elements: --The elements in a linked list can be traversed by starting from the head node and following the references to the next nodes until the end of the list is reached./OR/Accessing each elements exactly once in order to process it is known as traversing. • Reversing a linked list: --The linked list can be reversed by updating the references of each node so that they point to the previous node instead of the next node.
[3].Explain different types of Data Structures and their Classification.
Ans: Categories/Classification of data structure:
1)Linear and Non-Linear Data Structures:
• Linear Data Structure: --The elements in a linear data structure form a linear sequence. --Example are: Array, Linked list, Queue, Stack etc. • Non-Linear Data Structure: --The elements in a non-linear data structure do not form any linear sequence. --For example, Tree and Graph.
2)Static and Dynamic Data Structures:
• Static Data Structure: --Static data structures are those whose memory occupation is fixed. --The memory taken by these data structures cannot be increased or decreased at run time. --Example of the static data structure is an Array. --The size of an array isdeclared at the compile time and this size cannot be changed during the run time. • Dynamic Data Structure: --Dynamic data structures are those whose memory occupation is not fixed. --The memory taken by these data structures can be increased or decreased at run time. --Example of the dynamic data structure is Linked List. --The size of linked list can be changed during the run time.
3)Homogeneous and Non-Homogeneous Data Structures
• Homogeneous Data Structure: --Homogeneous data structures are those in which data of same type can be stored. --Example of the homogeneous data structure is an Array. • Non-Homogeneous Data Structure: --Non-Homogeneous data structures are those in which data of different types can be stored. --Example of the non-homogeneous data structure is linked list.
[4].What are the advantages if the Linked List?
Ans: Advantages of Linked List: Dynamic data structure: --A linked list is a dynamic arrangement so it can grow and shrink at runtime by allocating and deallocating memory. --So there is no need to give the initial size of the linked list. No memory wastage: --In the Linked list, efficient memory utilization can be achieved since the size of the linked list increase or decrease at run time so there is no memory wastage and there is no need to pre-allocate the memory. Implementation: --Linear data structures like stacks and queues are often easily implemented using a linked list. Insertion and Deletion Operations: --Insertion and deletion operations are quite easier in the linked list. --There is no need to shift elements after the insertion or deletion of an element only the address present in the next pointer needs to be updated. Flexible: --This is because the elements in Linked List are not stored in contiguous memory locations unlike the array. Efficient for large data: --When working with large datasets linked lists play a crucial role as it can grow and shrink dynamically. Scalability: --Contains the ability to add or remove elements at any position.
[5].e)Convert following infix expression into prefix and postfix expressions:
i)a × b × (c ˗ d) – (e ˆ 3 × f) + g/h ii)(a × b × c ˆ 2) + d – (c/d + e) Ans:
[6].Write a short note on double ended priority queue.
Ans: Deque (Double Ended Queue) --Double ended queue is the linear queue data structure in which insertion and deletion operations are not restricted to one end but rather insertion and deletion operations can be performed on either of the two ends. --These operations cannot be performed at any other position except the ends of the list. --Deque data structure is also known as Deck. --A deque can be categorized into two categories: Input Restricted Deque Output Restricted Deque --In case of input restricted deque, the insertion operation is restricted to one end but the deletion can take place at either end of the list. --In case of output restricted deque, the deletion operation is restricted to one end but the insertion can take place at either end of the list. [7].Explain types of Data Types. Ans: --There are two types of data types: • System defined data types (also called Primitive data types) --Data types that are defined by system are called primitive data types. --The primitive data types which are provide by many programming languages are: int, float, char, double, bool, etc…. --The number of bits allocated for each primitive data type depends on the programming languages, compiler and operating system. --For the same primitive data type, different languages may use different sizes. --Depending on the size of the data types the total available values (domain) will also changes. For example, "int" may take 2 bytes or 4 bytes. • User defined data types: --If the system defined data types are not enough then most programming languages allows the users to define their own data types called as user defined data types. --Good example of user defined data types are: structures in C/C++ and classes in Java.
[8].Explain application of Linked list like polynomial equations.
Ans: --Linked List is used in a wide range of applications. --Some of the application of linked list are: To represent the polynomials: --A polynomial can be represented in a linked list by simply storing the coefficient and exponent of each term. --However, for any polynomial operation , such as addition or multiplication of polynomials , you will find that the linked list representation is more easier to deal with. --First of all note that in a polynomial all the terms may not be present, especially if it is going to be a very high order polynomial. Consider 5 x (power 12)+ 2 x(power 9)+ 4x(power 7)+ 6x(power 5)+ x(power 2) + 12 x --Now this 12th order polynomial does not have all the 13 terms (including the constant term). --It would be very easy to represent the polynomial using a linked list structure, where each node can hold information pertaining to a single term of the polynomial. --Each node will need to store the variable x, the exponent and the coefficient for each term. To represent sparse matrices: -- The advantage of using a linked list to represent the sparse matrix is that the complexity of inserting or deleting a node in a linked list is lesser than the array. --Unlike the array representation, a node in the linked list representation consists of four fields. --The four fields of the linked list are given as follows - • Row - It represents the index of the row where the non-zero element is located. • Column - It represents the index of the column where the non-zero element is located. • Value - It is the value of the non-zero element that is located at the index (row, column). • Next node - It stores the address of the next node. To implement other data structures like Tress, Graph, Stack, Queues ets: --(**not found**) [9].What is data structure? Explain the categories in which data structure can be divided. Ans: --Data structures are introduced in order to store, organize and manipulate data in programming languages. --A data structure is a logical/mathematical model of oraganization. --Data structures are just a collection of similar or different data types in one. Categories/Classification of data structure:
1)Linear and Non-Linear Data Structures:
• Linear Data Structure: --The elements in a linear data structure form a linear sequence. --Example are: Array, Linked list, Queue, Stack etc. •Non-Linear Data Structure: --The elements in a non-linear data structure do not form any linear sequence. --For example, Tree and Graph.
2)Static and Dynamic Data Structures:
• Static Data Structure: --Static data structures are those whose memory occupation is fixed. --The memory taken by these data structures cannot be increased or decreased at run time. --Example of the static data structure is an Array. --The size of an array isdeclared at the compile time and this size cannot be changed during the run time. • Dynamic Data Structure: --Dynamic data structures are those whose memory occupation is not fixed. --The memory taken by these data structures can be increased or decreased at run time. --Example of the dynamic data structure is Linked List. --The size of linked list can be changed during the run time.
3)Homogeneous and Non-Homogeneous Data Structures
• Homogeneous Data Structure: --Homogeneous data structures are those in which data of same type can be stored. --Example of the homogeneous data structure is an Array. • Non-Homogeneous Data Structure: --Non-Homogeneous data structures are those in which data of different types can be stored. --Example of the non-homogeneous data structure is linked list.
[10].What are the disadvantages of Linked List?
Ans: Disadvantages of Linked List: Memory usage: --More memory is required in the linked list as compared to an array. --Because in a linked list, a pointer is also required to store the address of the next element and it requires extra memory for itself. Traversal: --In a Linked list traversal is more time-consuming as compared to an array. --Direct access to an element is not possible in a linked list as in an array by index. --For example, for accessing a node at position n, one has to traverse all the nodes before it. Reverse Traversing: --In a singly linked list reverse traversing is not possible, but in the case of a doubly-linked list, it can be possible as it contains a pointer to the previously connected nodes with each node. --For performing this extra memory is required for the back pointer hence, there is a wastage of memory. Random Access: --Random access is not possible in a linked list due to its dynamic memory allocation. Lower efficiency at times: --For certain operations, such as searching for an element or iterating through the list, can be slower in a linked list. Complex implementation: --The linked list implementation is more complex when compared to array. --It requires a complex programming understanding. Difficult to share data: --This is because it is not possible to directly access the memory address of an element in a linked list. Not suited for small dataset: --Cannot provide any significant benefits on small dataset compare to that of an array.
[11].What is a data type?
Ans: --A data type in a programming language is a set of data with values having predefined characteristics. --Examples of data types are: integer, floating point unit number, character, string etc.... Computer memory is all filled with zeros and ones. --If we have a problem and wanted to code it, it's very difficult to provide the solution in terms of zeros and ones. --To help users, programming languages and compilers are providing the facility of data types. --A data type reduces the coding effort.
[12].What is Abstract Data Types? Give Advantages.
Ans: --Abstract data types are the entities that are definitions of data and operations but do not have implementation details. --Absraction refers to the act of representing the essential features without including the details. --The term abstract stands for considering apart from detailed specification and implementation. --The reason for not having implementation details is that every programming language has a different implementation strategy. --for example; a C data structure is implemented using structures while a C++ data structure is implemented using objects and classes. --ADT uses the following principles: • Abstraction: It is a technique of hiding the internal details from the user and only showing the necessary details to the user. • Encapsulation: It is a technique of combining the data and the member function in a single unit is known as encapsulation. /OR/ Encapsulation is the process of wrapping together of data and information in a single unit and providing abstraction.
Grokking Algorithms An illustrated guide for programmers and other curious people 1st Edition Aditya Bhargava - The full ebook version is just one click away