• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Data structure Interview Questions Answers

Question - 31 : - How memory is reserved using a declaration statement ?

Answer - 31 : - Memory is reserved using data type in the variable declaration. A programming language implementation has predefined sizes for its data types. For example, in C# the declaration int i; will reserve 32 bits for variable i. A pointer declaration reserves memory for the address or the pointer variable, but not for the data that it will point to. The memory for the data pointed by a pointer has to be allocated at runtime. The memory reserved by the compiler for simple variables and for storing pointer address is allocated on the stack, while the memory allocated for pointer referenced data at runtime is allocated on the heap.

Question - 32 : - What is placement new?

Answer - 32 : - When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that’s already been allocated, and you need to construct an object in the memory you have. Operator new’s special version placement new allows you to do it. class Widget { public : Widget(int widgetsize); … Widget* Construct_widget_int_buffer(void *buffer,int widgetsize) { return new(buffer) Widget(widgetsize); } }; This function returns a pointer to a Widget object that’s constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.  

Question - 33 : - What is the quickest sorting method to use?

Answer - 33 : - The answer depends on what you mean by quickest. For most sorting problems, it just doesn't matter how quick the sort is because it is done infrequently or other operations take significantly more time anyway. Even in cases in which sorting speed is of the essence, there is no one answer. It depends on not only the size and nature of the data, but also the likely order. No algorithm is best in all cases. There are three sorting methods in this author's toolbox that are all very fast and that are useful in different situations. Those methods are quick sort, merge sort, and radix sort. The Quick Sort The quick sort algorithm is of the divide and conquer type. That means it works by reducing a sorting problem into several easier sorting problems and solving each of them. A dividing value is chosen from the input data, and the data is partitioned into three sets: elements that belong before the dividing value, the value itself, and elements that come after the dividing value. The partitioning is performed by exchanging elements that are in the first set but belong in the third with elements that are in the third set but belong in the first Elements that are equal to the dividing element can be put in any of the three sets the algorithm will still work properly. The Merge Sort The merge sort is a divide and conquer sort as well. It works by considering the data to be sorted as a sequence of already-sorted lists (in the worst case, each list is one element long). Adjacent sorted lists are merged into larger sorted lists until there is a single sorted list containing all the elements. The merge sort is good at sorting lists and other data structures that are not in arrays, and it can be used to sort things that don't fit into memory. It also can be implemented as a stable sort. The Radix Sort The radix sort takes a list of integers and puts each element on a smaller list, depending on the value of its least significant byte. Then the small lists are concatenated, and the process is repeated for each more significant byte until the list is sorted. The radix sort is simpler to implement on fixed-length data such as ints.

Question - 34 : - What is the relationship between a queue and its underlying array?

Answer - 34 : - Data stored in a queue is actually stored in an array. Two indexes, front and end will be used to identify the start and end of the queue. When an element is removed front will be incremented by 1. In case it reaches past the last index available it will be reset to 0. Then it will be checked with end. If it is greater than end queue is empty. When an element is added end will be incremented by 1. In case it reaches past the last index available it will be reset to 0. After incrementing it will be checked with front. If they are equal queue is full.

Question - 35 : - What is Linked List ?

Answer - 35 : - Linked List is one of the fundamental data structures. It consists of a sequence of? nodes, each containing arbitrary data fields and one or two (”links”) pointing to the next and/or previous nodes. A linked list is a self-referential datatype because it contains a pointer or link to another data of the same type. Linked lists permit insertion and removal of nodes at any point in the list in constant time, but do not allow random access.

Question - 36 : - Which file contains the definition of member functions?

Answer - 36 : - Definitions of member functions for the Linked List class are contained in the LinkedList.cpp file.

Question - 37 : - What method removes the value from the top of a stack?

Answer - 37 : - The pop() member method removes the value from the top of a stack, which is then returned by the pop() member method to the statement that calls the pop() member method.

Question - 38 : - How do you assign an address to an element of a pointer array ?

Answer - 38 : - We can assign a memory address to an element of a pointer array by using the address operator, which is the ampersand (&), in an assignment statement such as ptemployee[0] = &projects[2];

Question - 39 : - Minimum number of queues needed to implement the priority queue?

Answer - 39 : - Two. One queue is used for actual storing of data and another for storing priorities.

Question - 40 : - What does isEmpty() member method determines?

Answer - 40 : - isEmpty() checks if the stack has at least one element. This method is called by Pop() before retrieving and returning the top element.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners