answersLogoWhite

0


Best Answer

You cannot have recursion within a data structure:

struct foo {

int x;

foo y; // compiler error

};

This has to fail; there is no end point to the recursion. If a foo is member of a foo, then the member foo also requires a member foo, and so on to infinity...

If a structure needs to refer to another instance of itself, we can use a member pointer:

struct foo {

int x;

foo* y; // ok

};

A pointer works because all pointers are the same length regardless of the pointer's type (the type being referred to).

Using member pointers like this is fundamental to many data structures, such as linked lists:

struct node {

int data;

node* prev; // previous node in the sequence (may be NULL)

node* next; // next node in the sequence (may be NULL)

};

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the recursive solution in data structure?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why recursive solution is better for tree traversal?

Because a tree is a recursive data-structure. It's easier to write (and easier to understand) a recursive program for handling it.


When is it appropriate to use recursion?

In many problems the recursive solution is simple and elegant whereas the non-recursive solution is complex and difficult to code.In these cases the recursive solution can take advantage of the system stack for each function call, whereas in most non-recursive solutions, a stack in which to store data must be explicitly programmed


How are recursive rules different from explicit function rules for modeling linear data?

recursive rules need the perivius term explicit dont


Does the complexity of the solution to a problem depend upon the right choice of data structure?

perhaps...


What is recursive calls.which data structure is used in it?

A recursive call is any function that calls itself with modified parameters. There is no data structure associated with it, other than the call stack which is associated with all function calls, recursive or not. The stack is used to store the state of the current instance's local variables, the return address, and the arguments to be passed to the next instance. This allows recursive calls to "unwind" in the reverse order they were called. Recursive functions must have a terminating condition as all the recursive calls must eventually return to the original caller at some point. If they don't, they'll simply keep calling themselves until there's no more space on the stack. Recursive functions are commonly used in divide-and-conquer algorithms, gradually reducing larger problems down to smaller instances of the same problem until a terminating condition is satisfied. As the calls return, the larger problem is gradually solved until the function returns to the original caller, at which point the entire problem is fully resolved. Quicksort is a typical algorithm that makes use of recursion.


What are the subject-matters of data structure?

types of data structure types of data structure


What is the first no for sialkot?

Data structure is related to the algorithm, ie solution of the requirements.whereas Data Type is component of a programming language, which can be used to implement the required data structure (organization of data and format).For example if the requirement say that a LIST is required, and in C programming language , there is not LIST data type BUT LIST CAN BE REALISED(IMPLEMENTED ) in C.


How would you structure a database for tracking a family tree?

Identify the entities in the database Select the unique identifier/primary key Identify appropriate attributes Select the appropriate data types Create a recursive relationship Identify the cardinality of a relationship


How do you amend a data structure?

How do you amend a data structure?


What is the difference between allocation and search data structure?

difference between serch data structure and allocation data structure


What is recursive association?

a recursive association - as a aggregation is a special form of association, so recursive aggregation can be called as recursive association ... AKASH SISODIYA ......IT ...


What is the weakness of Data structure diagram?

weakness of data structure diagrams