Welcome to Lets Learn CS

Computer Science at fingertips

Kruskal’s Algorithm

Kruskal’s algorithm is a greedy technique  used to find minimum spanning tree from the graph.It works on edges rather than on vertices in connected weighted graph.MST is obtained by finding global optimal choice. Technique Mark the minimum weight edge in the graph and mark the respective vertices. Now,mark the next minimum value in the graph. If there… read more »

Prim’s algorithm

Prim’s algorithm is a greedy algorithm as it  finds the global optimum answer from collecting locally optimum choices.It finds the minimum spanning tree and works for weighted,connected and undirected graph.Minimum spanning tree is a graph is edge weighted graph whose weight is smaller than any other spanning tree.A minimum spanning tree is obtained by combining all… read more »

Depth First Search in Graphs

DFS technique is used to traverse graphs.Any vertex is chosen as the starting vertex .Element is pushed into stack.One adjacent vertex is randomly picked from adjacent vertices.It is marked and pushed it into stack.If adjacent unvisited neighbors are present then same process is followed otherwise element is popped off from the stack.Now,again one element is… read more »

Breadth First Search in Graphs

Breadth First Search is a technique to visit all the nodes of graph in a well-defined way.This technique can be applied  to  directed,undirected,weighted or unweighted  graph.Queues are used as a data structure to store elements. BFS traverses all the nodes and edges of graph. BFS in graph with m vertices and n edges takes O(n+m) time…. read more »


String is a collection of characters that forms a word.It is stored in one dimensional array and terminated by null(\0) character.The size of array is one more than the length of string as it required to store null character.The compiler itself places a null character at the end of array during its initialization Syntax char… read more »

Loop Control Statements

Loop Control Statements alter  execution of a program from the normal execution sequence.The statements are as follows break continue goto break statement break statement terminates the execution of loop immediately ineffective of the condition status.The control is transferred to the first statement after the loop block.If break statement is used in nested loops      (Refer : Nesting of Loops) then innermost loop is… read more »

Nesting of loops

Loops can be nested if required.Nesting means to have one or more loops inside the main loop. Syntax of nested for loops for(initialization;condition;iteration) { for(……) { for(…) {… } ……. } } Syntax of nested while loops while(condition) { ….. while(condition) { …….. } …. } Syntax of nested do-while loop do { statements; …… read more »

do-while loop

The functionality of do-while is slightly different from while and for loop.The condition of do-while is at the bottom of loop and it executes at least once even if the condition is false.The initialization of a variable loop is done before the loop block. Syntax do { set_of_statements; } while(condition);   Example 1 Say we… read more »

while loop

While loop keeps on executing the given statements as long as the condition is true.When the condition  turns out to be false then set of statements in the block never gets executed and the control goes to first line after the while block. Syntax while(condition) { set_of_statements; iteration statement; } If the condition is true,then set… read more »

for loop

Loops are control structures that are used to execute a code several times.There may be situation when we need to print series from 1-100 or we need to print our name 1000 times on screen.It will be inappropriate to use 100 or thousand  times printf for this scenario.Loops can be used to efficiently perform the task as… read more »