GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 356 of 453    Print  
Explian Floyd Cycle finding algorithm for circular link list?

  
Total Answers and Comments: 1 Last Update: March 03, 2008     Asked by: pbchaudhari 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 03, 2008 07:39:22   #1  
kundanthebest Member Since: March 2008   Contribution: 1    

RE: Explian Floyd Cycle finding algorithm for circular link list?
Simultaneously go through the list by ones (slow iterator) and by twos (fast iterator). If there is a loop the fast iterator will go around that loop twice as fast as the slow iterator. The fast iterator will lap the slow iterator within a single pass through the cycle. Detecting a loop is then just detecting that the slow iterator has been lapped by the fast iterator.

// Best solution function boolean hasLoop(Node startNode)
{ Node slowNode Node fastNode1 Node 
fastNode2 startNode; 
while (slowNode && fastNode1 fastNode2.next() && 
fastNode2 fastNode1.next()){  
if (slowNode fastNode1 || slowNode fastNode2) return true;  
slowNode slowNode.next(); } return false; }

 
Is this answer useful? Yes | No

 Related Questions

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 
Latest Answer : The algorithms which follows divide and qunquer technique provides fastest implementation. ...

A binary search, such as bsearch() performs, is much faster than a linear search. A hashing algorithm can provide even faster searching. One particularly interesting and fast method for searching is to 
Latest Answer : quick short method is a best one ...

To hash means to grind up, and that’s essentially what hashing is all about. The heart of a hashing algorithm is a hash function that takes your nice, neat data and grinds it into some random-looking 
Latest Answer : hash is actually using a maping function to map the items to keys,  if two different items map to one key, a collision solution is needed. ...

Both the merge sort and the radix sort are good sorting algorithms to use for linked lists.  
Latest Answer : For this no need to write sepate function. We can arrage the elements in order by using some comaprisons in creation of list.venkatesh_ch@fastmail.fm ...

Unfortunately, the only way to search a linked list is with a linear search, because the only way a linked list’s members can be accessed is sequentially. Sometimes it is quicker to take the data 
Latest Answer : hai here am writing a simple ex for searchina linked list for specific valuestruct link{int data;struct link *node;}if the above struct is a node such that in a node u can store a data and pointer to the next node.if u have the pointer the beginning of ...

The stack is where all the functions’ local (auto) variables are created. The stack also contains some information used to call and return from functions. A “stack trace” is a list of 
Latest Answer : Please tell me, how I can extract stack information(runtime) of the code being executed using C. The program is running on Windows machine. ...

The heap is where malloc(), calloc(), and realloc() get memory. Getting memory from the heap is much slower than getting it from the stack. On the other hand, the heap is much more flexible than the stack. 
Latest Answer : Heap is a dynamic memory of main memory. In main memory there are several type of memory management like fixed, static, dynamic (it is just memory area which can be used by any task or process but it is not contiguous memory location). Now the point ...

What is a “null pointer assignment” error? What are bus errors, memory faults, and core dumps?
These are all serious errors, symptoms of a wild pointer or subscript. Null pointer assignment is a message you might get when an MS-DOS program finishes executing. Some such programs can arrange for 
Tags : Pointer

Latest Answer : Hi,I agree with Ashtosh , since linked list nodes are stored dynamically in memory wherever it has space so the simple addition wont give track of nodes but a junk value.we can construct this only by combining two pointer nodes for single data value.its ...
Tags : Pointer

The questions are as follows: 1. Write a 'c' program to read the age of 100 persons and count the number of persons in the age group 50 to 60.use for loop and continue statements.(10 marks)2. Write a program to read a positive integer and print its binary equivalent.(10 marks)3. Given two one dimensional arrays a and b which are sorted in ascending order. write a program to merge them into a single sorted array ,c that contains every item from arrays a and b, in ascending order.(10 marks)4.
Read Answers (11) | Asked by : Arka chakraborty


 Sponsored Links

 
Related Articles

High Level Data Link Control (HDLC)

High Level Data Link Control HDLC The High Level Data Link Control protocol was developed by the International Organization for Standardization ISO It is used for switched and non switched networks and is a bit oriented architecture The High Level Data Link Control has been accepted and used widel
 

Synchronous Data Link Control (SDLC)

Synchronous Data Link Control SDLC The SDLC or the Synchronous Data Link Control was first developed by IBM It is basically a linked layer protocol which can be used with systems network architecture or the SNA environment In this system all the functions in a network can be defined and slotted into
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

What is Systems Development Life Cycle

Introduction Developers worldwide will agree that building software takes more than just writing complex codes and implementing them in an environment. Developers usually start out their career in programming by developing programs or software according to their own plan and hope that someone will
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

What is Software Development Life Cycle?

What is Software Development Life Cycle? In this chapter we’ll be looking on SDLC as a tool for development, what are the factors for its proper implementation and special section on software security from the point of view of SDLC. These topics will guide us in knowing the important of S
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Finding a New Job as a Senior

The days when almost everyone safely retired between 60 and 65 and went on to safely live off their pensions and social security are over. Over 60 percent of retirement-age employees are currently continuing to work full or part time, and 15 percent of the American workforce is currently over the ag
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape