Вы находитесь на странице: 1из 3

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. Or Data structures are used to store data in a computer in an organized fashion. 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. Stack: Works in first in last out order. The element inserted first in stack is removed last. Queue: First in First out order. The element inserted first is removed first. 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. 2.Define a linear and non linear data structure. Linear data structure: A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached. Ex: Arrays, Linked Lists Non-Linear data structure: Every data item is attached to several other data items in a way that is specific for reflecting relationships. The data items are not arranged in a sequential structure. Ex: Trees, Graphs 3.Define in brief an array. What are the types of array operations? An array is an arrangement of data arranged in a systematic order. An array usually has rows and columns. Each element of an array is accessed using the row and column id. Array operations:Initializing an array:- Specifies the array size. Example: Arr[10]; Assigning:- This operation assigns a value to an array. Example: arr[1]=5;

1
There are many other operators that can be used to assign. Other Operations are: Adding elements - Sorting elements - Searching elements - Re-arranging the elements Performing matrix operations - Pre-fix and postfix operations 4.What is a matrix? Explain its uses with an example A matrix is a representation of certain rows and columns, to persist homogeneous data. It can also be called as double-dimensioned array. Uses: To represent class hierarchy using Boolean square matrix For data encryption and decryption To represent traffic flow and plumbing in a network To implement graph theory of node representation 5.Define an algorithm. What are the properties of an algorithm? What are the types of algorithms? An algorithm is a series of steps or methodology to solve a problem. Or A step by step process to get the solution for a well defined problem. Properties of an algorithm:It is written in simple English. Each step of an algorithm is unique and should be self explanatory. An algorithm must have at least one input. An algorithm must have at least one output. An algorithm has finite number of steps. 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

City Classes: Sandeep Sirs Academy (98156-00235)

Data Structures
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). 6.What is an iterative algorithm? An iterative algorithm executes steps in iterations. It aims to find successive approximation in sequence to reach a solution. They are most commonly used in linear programs where large numbers of variables are involved. 7.What is an recursive algorithm? Recursive algorithm is a method of simplification that divides the problem into sub-problems of the same nature. The result of one recursion is the input for the next recursion. The repletion is in the self-similar fashion. The algorithm calls itself with smaller input values and obtains the results by simply performing the operations on these smaller values. Generation of factorial, Fibonacci number series are the examples of recursive algorithms. 8.What is the Huffman algorithm? In Huffman Algorithm, a set of nodes assigned with values if fed to the algorithm. Initially 2 nodes are considered and their sum forms their parent node. When a new element is considered, it can be added to the tree. Its value and the previously calculated sum of the tree are used to form the new node which in turn becomes their parent. 9.Explain quick sort, merge sort and bubble sort algorithms. Quick sort Divides the array elements in two halves or partitions. On dividing, the quick sort procedure is recursively called to sort the two halves. A pivot is used as the center point and elements less than the pivot are moved to the left or before the pivot and elements greater than pivot are moved to the right.

2
Merge sort- A comparison based sorting algorithm. Based on divide and conquer mechanism. The array elements are divided into partitions (n/2). Each partition is sorted recursively and then merged. Run time is T(n log n). Bubble Sort: - The simplest sorting algorithm. It takes two array elements at a time, compares them and swaps their positions if element on left is greater than right. Divides the array elements in two halves or partitions. On dividing, the quick sort procedure is recursively called to sort the two halves. A pivot is used as the center point and elements less than the pivot are moved to the left or before the pivot and elements greater than pivot are moved to the right. 10.What is the difference between a stack and a Queue? Stack Represents the collection of elements in Last In First Out order. Operations includes testing null stack, finding the top element in the stack, removal of top most element and adding elements on the top of the stack. Queue - Represents the collection of elements in First In First Out order. Operations include testing null queue, finding the next element, removal of elements and inserting the elements from the queue. Insertion of elements is at the end of the queue Deletion of elements is from the beginning of the queue. 11.Can a stack be described as a pointer? Explain. Stack can be described as a pointer as it contains a head pointer always pointing to the topmost element of the stack. The Push and Pop operations are performed using this pointer. 12.What is the recursion? Recursion is an approach in which a function calls itself with an argument. Upon reaching a termination condition, the control returns to the calling function.

City Classes: Sandeep Sirs Academy (98156-00235)

Data Structures
13.Explain the terms Base case, Recursive case, Binding Time, Run-Time Stack and Tail Recursion. Base case: A case in recursion, in which the answer is known when the termination for a recursive condition is to unwind back. Recursive Case: A case which returns to the answer which is closer. Run-time Stack: A run time stack used for saving the frame stack of a function when every recursion or every call occurs. Tail Recursion: It is a situation where a single recursive call is consisted by a function, and it is the final statement to be executed. It can be replaced by iteration. 14.Is it possible to insert different type of elements in a stack? How? Yes, it is possible to insert different types of elements in a stack. This is possible by implementing union / structure data type. It is efficient to use union rather than structure, as only one items memory is used at a time. Elements in a stack can be inserted using the Push operation. This operation writes an element on the stack and moving the pointer. 15.Explain in brief a linked list. A linked list a linear arrangement of data. It allows the programmer to insert data anywhere within the list. The pointer of the list always points to the first node and can be moved programmatically to insert, delete or update any data. Each node in the list contains a data value and the address or a reference to the adjoining node. 16.How would you sort a linked list? Different sorting algorithms can be used to sort the linked list. Merge sort is normally used to sort the linked list. 17.Explain the types of linked lists. The types of linked lists are: Singly linked list: It has only head part and corresponding references to the next nodes.

3
Doubly linked list: A linked list which both head and tail parts, thus allowing the traversal in bidirectional fashion. Except the first node, the head node refers to the previous node. Circular linked list: A linked list whose last node has reference to the first node. 18.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. 19.What is binary searching and Fibonacci search? Binary search is used to find an element of a sorted list only. For the element to be searched, the middle value is first compared. If it is same as the element to be sought, the search stops. Else, the same mechanism of search is performed on the left or right side elements of the middle elements depending on whether the sought value is greater than or less than the middle element. Fibonacci search is used to search an element of a sorted array with the help of Fibonacci numbers. It studies the locations whose addresses have lower dispersion. Fibonacci number is subtracted from the index thereby reducing the size of the list.

City Classes: Sandeep Sirs Academy (98156-00235)

Вам также может понравиться