Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1. What pointer type is used to implement the heterogeneous linked list in C? Answer: Void pointer.

The heterogeneous linked list contains different data types in it's nodes and we need a link, pointer, to connect them. Since we can't use ordinary pointers for this, we use the void pointer. Void pointer is a generic pointer type, and capable of storing pointer to any type.

2. What is the minimum number of queues needed to implement the priority queue? Answer: Two. One queue is used for the actual storing of data, and the other one is used for storing the priorities.

3. Which data structure is used to perform recursion? Answer: The answer is Stack. Stack has the LIFO (Last In First Out) property; it remembers it's caller. Therefore, it knows to whom it should return when the function has to return. On the other hand, recursion makes use of the system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written explicit, stack is to be used.

4. What are some of the applications for the tree data structure? Answer: 1- Manipulation of the arithmetic expressions. 2- Symbol table construction. 3- Syntax analysis.

5. Which data strucutres algorithm used in solving the eight Queens problem? Answer: Backtracking

6. In an AVL tree, at what condition the balancing is to be done? Answer: If the "pivotal value", or the "height factor", is greater than one or less than minus one.

7. What is the bucket size, when the overlapping and collision occur at the same time? Answer: The answer is one. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values.

8. There are 8, 15, 13, and 14 nodes in 4 different trees. Which one of them can form a full binary tree? Answer: The answer is the tree with 15 nodes. In general, there are 2^n-1 nodes in a full binary tree. By the method of elimination: Full binary trees contain odd number of nodes, so there cannot be full binary trees with 8 or 14 nodes. Moreover, with 13 nodes you can form a complete binary tree but not a full binary tree. Thus, the correctanswer is 15.

List Data Structure


A list is a sequential data structure, i.e. a collection of items accessible one after another beginning at the head and ending at the tail. It is a widely used data structure for applications which do not need random access. It differs from the stack and queue data structures in that additions and removals can be made at any position in the list.

Operations
The main primitive operations of a list are known as: Add - adds a new node Set - updates the contents of a node Remove - removes a node

Get - returns the value at a specified index IndexOf -returns the index in the list of a specified element

Additional primitives can be defined:


IsEmpty - reports whether the list is empty IsFull - reports whether the list is full Initialise - creates/initialises the list Destroy - deletes the contents of the list (may be implemented by re-initialising the list)

What is Data Structure and Algorithms?


A data structure is an arrangement of data in a computer's memory or even disk storage. An example of several common data structures are arrays, linked lists, queues, stacks, binary trees, and hash tables. Algorithms, on the other hand, are used to manipulate the data contained in these data structures as in searching and sorting. Many algorithms apply directly to a specific data structures. When working with certain data structures you need to know how to insert new data, search for a specified item, and deleting a specific item.

Commonly used algorithms include are useful for: Searching for a particular data item (or record). Sorting the data. There are many ways to sort data. Simple sorting, Advanced sorting Iterating through all the items in a data structure. (Visiting each item in turn so as to display it or perform some other action on these items)

Characteristics of Data Structures


Array:

Advantages Quick Insert Fast access if index known Drawbacks Slow search Slow deletes Fixed size Ordered Array: Advantages Faster search than unsorted array Drawbacks Slow inserts Slow deletes Fixed size Stacks: Advantage Last-in, first-out acces Drawback Slow access to other items Queue: Advantage First-in, first-out access Drawback Slow access to other items Linked LIsts:

Advantage Quick inserts Quick deletes Drawback Slow search Binary Tree: Advantage Quick search Quick inserts Quick deletes (If the tree remains balanced) Drawback Deletion algorithm is complex Red-Black Tree Advantage Quick search Quick inserts Quick deletes (Tree always remains balanced) Drawback Complex to implement 2-3-4 Tree: Advantage Quick search Quick inserts Quick deletes (Tree always remains balanced) (Similar trees good for disk storage) Drawback

Complex to implement Hash Table Advantage Very fast access if key is known Quick inserts Drawback Slow deletes Access slow if key is not known Inefficient memory usage Heap Advantage Quick inserts Quick deletes Access to largest item Drawback Slow access to other items Graph Advantage Best models real-world situations Drawback Some algorithms are slow and very comples

What is Abstract Data Type?


An Abstract Data Type (ADT) is more a way of looking at a data structure: focusing on what it does and ignoring how it does its job. A stack or a queue is an example of an ADT. It is important to understand that both stacks and queues can be implemented using an array. It is also possible to implement stacks and queues using a linked list. This demonstrates the "abstract" nature of stacks and queues: how they can be considered separately from their implementation.

To best describe the term Abstract Data Type, it is best to break the term down into "data type" and then "abstract".
data type

When we consider a primitive type we are actually referring to two things: a data item with certain characteristics and the permissible operations on that data. An int in Java, for example, can contain any whole-number value from -2,147,483,648 to +2,147,483,647. It can also be used with the operators +, -, *, and /. The data type's permissible operations are an inseparable part of its identity; understanding the type means understanding what operations can be performed on it. In Java, any class represents a data type, in the sense that a class is made up of data (fields) and permissible operations on that data (methods). By extension, when a data storage structure like a stack or queue is represented by a class, it too can be referred to as a data type. A stack is different in many ways from an int, but they are both defined as a certain arrangement of data and a set of operations on that data.
abstract

Now lets look at the "abstract" portion of the phrase. The word abstract in our context stands for "considered apart from the detailed specifications or implementation". In Java, an Abstract Data Type is a class considered without regard to its implementation. It can be thought of as a "description" of the data in the class and a list of operations that can be carried out on that data and instructions on how to use these operations. What is excluded though, is the details of how the methods carry out their tasks. An end user (or class user), you should be told what methods to call, how to call them, and the results that should be expected, but not HOW they work. We can further extend the meaning of the ADT when applying it to data structures such as a stack and queue. In Java, as with any class, it means the data and the operations that can be performed on it. In this context, although, even the fundamentals of how the data is stored should be invisible to the user. Users not only should not know how the methods work, they should also not know what structures are being used to store the data. Consider for example the stack class. The end user knows that push() and pop() (amoung other similar methods) exist and how they work. The user doesn't and shouldn't have to know how push() and pop() work, or whether data is stored in an array, a linked list, or some other data structure like a tree.

The Interface

The ADT specification is often called an interface. It's what the user of the class actually sees. In Java, this would often be the public methods. Consider for example, the stack class - the public methods push() and pop() and similar methods from the interface would be published to the end user

You might also like