-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.html
More file actions
17 lines (14 loc) · 1.15 KB
/
string.html
File metadata and controls
17 lines (14 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<head><B>How to find middle element of linked list in one pass?</B></head><br><br>
<body>
<script language="javascript" type="text/javascript">
<!--
document.write("One of the most popular question from data structures and algorithm, mostly asked on telephonicinterview. Since many programmer know that, in order to find length of linked list we need tofirst traverse through linked list till we find last node, which is pointing to null, and then insecond pass we can find middle element by traversing only half of length. They get confused when interviewer ask him to do same job in one pass. In order to find middle element of linked list in one pass, you need to maintain two-pointer, one increment at each node while otherincrements after two nodes at a time, by having this arrangement, when first pointer reaches end,second pointer will point to middle element of linked list. See this trick to find middle element of linked list in single pass for more details.");
/*this chapter describes about one
interview question that I have faced
in my interviews */
//this is a data structures and algotrithem based question
//-->
</script>
<body>
<html>