Algorithm to count number of nodes, Data Structure & Algorithms

Assignment Help:

Write an algorithm to count number of nodes in the circular linked list.                           

Ans.

Counting No of Nodes in Circular List

Let list be a circular header list in memory. This algorithm traverse and counts number of nodes in a LIST.

0.   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

 


Related Discussions:- Algorithm to count number of nodes

State in brief about assertion, State  in brief about assertion Asser...

State  in brief about assertion Assertion: A statement which should be true at a designated point in a program.

Branch and bound algorithm, Suppose we have a set of N agents and a set of ...

Suppose we have a set of N agents and a set of N tasks.Each agent can only perform exactly one task and there is a cost associated with each assignment. We would like to find out a

Depth of complete binary tree, What will be depth do , of complete binary t...

What will be depth do , of complete binary tree of n nodes, where nodes are labelled from 1 to n with root as node and last leaf node as node n

Explain stacks, What are stacks? A stack is a data structure that organ...

What are stacks? A stack is a data structure that organizes data similar to how one organizes a pile of coins. The new coin is always placed on the top and the oldest is on the

Creation of a circular linked list, Program: Creation of a Circular linked ...

Program: Creation of a Circular linked list ALGORITHM (Insertion of an element into a Circular Linked List) Step 1        Begin Step 2      if the list is empty or new

Disadvantages of the lifo costing method, The disadvantages or limitations ...

The disadvantages or limitations of the last in first out costing method are: The election of last in first out for income tax purposes is binding for all subsequent yea

Applications of binary trees, In computer programming, Trees are utilized ...

In computer programming, Trees are utilized enormously. These can be utilized for developing database search times (binary search trees, AVL trees, 2-3 trees, red-black trees), Gam

Generate a single sorted list of all n elements, Q. Assume that we have sep...

Q. Assume that we have separated n elements in to m sorted lists. Explain how to generate a single sorted list of all n elements in time O (n log m )?

Doubly linked list having n nodes, The time required to delete a node x fro...

The time required to delete a node x from a doubly linked list having n nodes is O (1)

Program segment for insertion of an element into the queue, Program: Progra...

Program: Program segment for insertion of an element into the queue add(int value) { struct queue *new; new = (struct queue*)malloc(sizeof(queue)); new->value = val

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd