DATA STRUCTURE

What is the difference between array and stack?

A stack and an array are two entirely different things. The number of elements in an array is fixed and is assigned by the declaration for the array. In general the user cannot change this number. A stack on the other hand, is fundamentally a dynamic object whose size is constantly changing as items are popped and pushed.

However although an array cannot be a stack, it can be the home of a stack. That is an array can be declared large enough for the maximum size of the stack.

Why the circular queue better than a linear queue?

If we delete element from the linear queue or normal queue then empty space is create there but we cannot insert any new element into this empty space because in a linear queue the insertion has to be done from one side and deletion has to be done from another side.

In circular queue the front and rear are adjacent to each other that means the insertion and deletion point is same. So if any element delete from the circular queue, we can insert a new element to this position.

When we make an array we must allocate memory for a certain number of elements. If we want to add more elements to the array then we allocated memory for create a new array and copy the old array into the new array. This can take lots of time and wasting the memory.

In a linked list we can start with space for just one element allocated and add on new elements easily without the needs to do coping and reallocating. It does not require any extra space therefore it does not waste extra memory.

The advantage of linked list is that it can quickly insert and delete items in a linked list. Inserting and deleting items in an array requires you to either make room for new items or fill the "hole" after deleting an item.

Linked list also allow you to have different sized nodes in the list.

The limitation of linked list is that it consumes extra space when compared to a array. Since each node must also contain the address of the next item in the list to search for a singly item in a linked list is cumbersome and time consuming.

Compare recursion and iteration. Which one is better and why?

Recursion
Iteration
Recursion refers to a situation where a function calls itself again and again until some base condition is not reached. Iteration refers to a situation where some statements are executed again and again using loops until some condition is true.
It is comparatively slower because before each function call the current state of function is stored in stack. After the return statement the previous function state is again restored from stack. Its execution is faster because it doesn’t use stack.
Memory usage is more as stack is used to store the current function state. Memory usage is less as it doesn’t use stack.
Size of code is comparatively smaller in recursion. Iteration makes the code size bigger.

What is B-Tree in Data Structure?

A B-Tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time. The B-Tree is a generalization of a binary search tree in that a node can have more than two children. Unlike self-balancing binary search trees, the B-Tree is well suited for storage systems that read and write relatively large blocks of data, such as discs. It is commonly used in databases and file systems.

How does Binary Search give benefit over Linear Search?

Linear search is iterative in nature and uses sequential approach. On the other hand, Binary search implements divide and conquer approach.

Linear search can be implemented in an array as well as in linked list whereas binary search can not be implemented directly on linked list because linked list is dynamic in nature and it is not known where the middle element is actually assigned.

A doubly linked list can be traversed in both directions (forward and backward). A singly linked list can only be traversed in one direction.

A node on a doubly linked list can be deleted with little trouble, since we have pointers to the previous and next nodes. A node on a singly linked list cannot be removed unless we have the pointer to its predecessor.

Doubly linked list occupied more space per node because extra field is required for pointer to previous node.

What is hashing? describe different hash functions.

RELATED TOPIC

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.

MORE TOPIC

WHAT WE DO