1.what Is A Data Structure? What Are The Types of Data Structures?
1.what Is A Data Structure? What Are The Types of Data Structures?
The scheme of organizing related information is known as data structure. The types of data structure are: Lists: A group of similar items with connectivity to the previous or/and next data items. Arrays: A set of homogeneous values Records: A set of fields, where each field consists of data belongs to one data type. Trees: A data structure where the data is organized in a hierarchical structure. This type of data structure follows the sorted order of insertion, deletion and modification of data items. Tables: Data is persisted in the form of rows and columns. These are similar to records, where the result or manipulation of data is reflected for the whole table.
5.Define an algorithm. What are the properties of an algorithm? What are the types of algorithms?
Algorithm: A step by step process to get the solution for a well defined problem. Properties of an algorithm: - Should be written in simple English - Should be unambiguous, precise and lucid - Should provide the correct solutions - Should have an end point - The output statements should follow input, process instructions - The initial statements should be of input statements - Should have finite number of steps - Every statement should be definitive Types of algorithms: -- Simple recursive algorithms. Ex: Searching an element in a list Backtracking algorithms Ex: Depth-first recursive search in a tree Divide and conquer algorithms. Ex: Quick sort and merge sort Dynamic programming algorithms. Ex: Generation of Fibonacci series Greedy algorithms Ex: Counting currency Branch and bound algorithms. Ex: Travelling salesman (visiting each city once and minimize the total distance travelled) Brute force algorithms. Ex: Finding the best path for a travelling salesman Randomized algorithms. Ex. Using a random number to choose a pivot in quick sort)
17.What is sequential search? What is the average number of comparisons in a sequential search?
Sequential search: Searching an element in an array, the search starts from the first element till the last element. The average number of comparisons in a sequential search is (N+1)/2 where N is the size of the array. If the element is in the 1st position, the number of comparisons will be 1 and if the element is in the last position, the number of comparisons will be N.
21. Write an algorithm to show the postfix expression with the input given as : a b + c d +*f ? .
The postfix expression deals with the expression where the operators are being written after their operands. The evaluation of these operators is being done from left-to-right. The algorithm that is used to show the input of a b + c d +*f ? is as follows: Stack is cleared for the use, symbol = insert input character while(not end of input) { if (symbol is an operand) push in stack; else { pop two operands from the stack; result=op1 symbol op2; push result in stack; } symbol = next input character; } return (pop (stack));
22. Write an algorithm through which the inserting and deleting of elements can take place in circular queue?
Circular queues are very important as it allows the element to circulate. In this queue rear end reaches the end and the first element in the list will become the rear of that queue. In this queue the front element can only become the rear element if and only if front has moved forward in the array. The algorithm that is used to represent it is as follows: insert(queue,n,front,rear,item) This procedure inserts an element item into a queue. 1. If front = 1 and rear = n, or if front = rear + 1, then: Write: overflow, and return 2. [find new value of rear] If front = NULL , then : [queue initially empty.] Set front = 1 and rear=1. Else if rear = n, then:
Set rear=1. Else: Set rear = rear + 1. [end of structure.] 3. Set queue[rear] = item. [this inserts new element.] 4.Return to the beginning.
25. What is the difference between B tree and Binary search tree?
Binary tree consists of only fixed number of keys and children, whereas B tree consists of variable number of keys and children. Binary tree keys are stored in decreasing order, whereas B tree consists of the keys and children in non-decreasing order. Binary tree doesn't consists of associated child properties whereas B tree consists of keys has an association with all the nodes with the keys that are less than or equal to the preceding key. Binary tree doesn't have minimization factor concept, whereas B tree has the concept of minimization factor where each node has minimum number of allowable children.
28. Explain the sorting algorithm that is most suitable to be used with single linked list?
The sorting algorithm that is most suitable with the single link list is the simple insertion sort. This consists of an array and link of pointers, where the pointers are pointing to each of the element in the array. For example: l[i] = i + 1 for 0 < = i < n-1 and l[n-1] = -1. The linear link list can be pointed by the external pointer which initialized it to 0. To insert the nth element in the list the traversing time gets reduced and until the list is being sorted out completely the process doesn't end. The array that has to be traversed x[k] to sort the element and put them in the list. If the sorting is done then it reduces the time of the insertion of an element and time for searching for a particular element at proper position.
29. What are the standard ways in which a graph can be traversed?
There are two standard ways through which a graph can be traversed and these are: i. The depth-first traversal: allow the graph to be traversed from a given point and then goes to the other points. The starting position is being defined as it doesn't consist of any root so, there is a specific point that is chosen to begin the traversing. In this the visits takes place at each vertex and then recursive action is taken to visit all the vertices adjacent to the node that is being visited. The graph can consists of cycles, but there is always a condition that the vertex has to be visited only once. ii. The breadth-first traversal: allow the graph to be traverse one level by another level. Breadth-first visits all the nodes from the depth 0 and it consists of a root. The vertex that has to be visited has to be specified that will be traversed. The length of the vertex has to be defined to find the shortest path to the given vertex. Breadth-first traverse the starting vertex and then all the vertices that is been adjacent to it.
can be accessed. It defines the new type of instance that is been created by operating on different data types. There is always some additional information on which ADT acts upon. It specifies the instance of the creation time. The abstract data type can be declared as: LIST<data type> variable name;
33. Write an algorithm to show various operations on ordered list and arrays
Ordered list is a container holding the sequence of objects. In this each object is having a unique position in a particular sequence. The operations that are being provided and performed on the ordered list include: FindPosition: is used to find the position of the object in an ordered list. Operator[]: is used to access the position of the object in the ordered list. withdraw(Position&): is used to remove the object from a given position in an ordered list. InsertAfter: is used to insert an object after some other object or on some position in the ordered list. InsertBefore: is used to insert the object in an ordered list at a defined position in an array of the ordered list.
34. Write a program to show the insertion and deletion of an element in an array using the position
To insert the element or delete the element, there is a requirement to find out the exact location as array is a group of linear characters, so it is very important to find the position of the element in an array before performing the actions on them. The program explains the insertion and deletion operations performed on an array of elements: void insert ( int *arr, int pos, int num ) /* This inserts an element at a given position*/ { int i ; for ( i = MAX - 1 ; i > = pos ; i-- ) arr[i] = arr[i - 1] ; arr[i] = num ; // This tells about the shifting of an element to the right }// function of the insertion ends here void del ( int *arr, int pos ) /* This function is used to delete the element at a given position*/ { int i ; for ( i = pos ; i < MAX ; i++ ) arr[i - 1] = arr[i] ; arr[i - 1] = 0 ; }
36. Write an algorithm that counts number of nodes in the circular linked list
Circular linked list is a list in which the insertion and deletion can be done in two ways. There is a provision to count the number of nodes just by keeping a count variable to count the data that is being inserted in the circular list. The algorithm is given to show the count of the nodes in the circular linked list. Keep a circular header list in memory. Keep a count to traverse the whole list and to keep a count of the data element set COUNT: = 0
1. Set PTR: = LINK [START]. {Initializes the pointer PTR} 2. Repeat steps 3, 4, 5 while PTR = START; 3. COUNT = COUNT + 1 4. Set PTR = LINK [PTR]. [PTR now points to next node] [End of step 2 loop] 5. Exit
39. List out the areas in which data structures are applied extensively?
1. 2. 3. 4. 5. 6. 7. 8. Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation
40. What are the major data structures used in the following areas : RDBMS, Network data model and Hierarchical data model.
1. RDBMS = Array (i.e. Array of structures)
41. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.
44. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
Polish and Reverse Polish notations.
45. Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.
1. Prefix Notation: - * +ABC ^ - DE + FG 2. Postfix Notation: AB + C * DE - FG + ^ -
46. Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)
Sorting is not possible in Deletion. Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.
49. List out few of the applications that make use of Multilinked Structures?
1. Sparse matrix, 2. Index generation.
50. In tree construction which is the suitable efficient data structure? (Array, Linked list, Stack, Queue)
Linked list is the suitable efficient data structure.
51. What is the type of the algorithm used in solving the 8 Queens problem?
Backtracking.
53. What is the bucket size, when the overlapping and collision occur at same time?
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.