Wednesday, 5 April 2017

Linked List



Problems:
  • Implement Stack using Linked List - 1.Problem.cpp
  • Find nth node from end of Linked List - Problem2
    • Implementation1 : Brute force method  using recursive_function. Complexity->O(n2)
    • Implementation2 : Get the total length of the list and use lenth-n+1 to find the node Complexity->O(n)
    •  Implementation3 : Best Method - To solve problem in one scan use two ptrs, move one till it reaches nth, then start 2nd one till first one hits end of list
  • Find if Linked List has loop and what is the length of loop - used slow_ptr and fast_ptr, Problem3

No comments:

Post a Comment

Array

Program for Array Rotation 1st Method - Using temp array  - Time complexity - O(n), Space - O(d) See algo and code 2nd Method - rotate...