Posts

Showing posts with the label Algorithms

Data Structures(DSA)

  1. Is it possible to find a loop in a Linked list ? a. Possible at O(n)  b. Not possible  c. Possible at O(n^2) only  d. Depends on the position of loop Solution: (a) Possible at O(n)  Have two pointers say P1 and P2 pointing to the first node of the list.  Start a loop and Increment P1 once and P2 twice in each iteration. At any point of time if P1==P2 then there is a loop in that linked list. If P2 reaches NULL (end of linked list) then no loop exists.   2. Two linked lists L1 and L2 intersects at a particular node N1 and from there all other nodes till the end are common. The length of the lists are not same. What are the possibilities to find N1?. a. Solution exist for certain cases only  b. No linear solution exist  c. Linear solution is possible  d Only Non-linear solution exist. Solution: c. Linear solution is possible Have two pointers say P1 pointing to the first node of L1 and P2 to that of L2. Traverse thr...

Introduction to Algorithm

Image
Everyday algorithms we have heard about  algorithms  in real life. Simply put, it is a step-by-step sequence of actions we need to perform to achieve a useful result. It can be an algorithm for cooking a sandwich described by a recipe or an algorithm for getting dressed according to today's weather and your mood. Among all algorithms, there is one special group called  computer algorithms.  These are ones that are usually created for and utilized by computers. In this topic, we will discuss in detail what computer algorithms are and will explain why it is important to learn them. Algorithms for computers Computer algorithms are everywhere around us. Our smartphone may guide us through a city from one point to another using a certain algorithm. Other algorithms can control the behavior of your enemies in a computer game. Services like Google or Yahoo apply sophisticated algorithms to provide you with the most relevant results when you use them to search for some infor...