Facebook

Computer Science

Big O Notation

  It gives rate of growth of step count function(f(n)) in terms of simple function(g(n)) and defines the asymptotic upper bound on function(Fig 1). To simplify the estimation for running time,constants and lower order terms are ignored. The function needs to satisfy following conditions in order to be in Big-O class.Given functions f(n) and g(n),we… read more »

Time and Space Complexity

Before defining the actual term complexity, let us discuss about few real life scenarios.Take an example of railway reservation counter.People go there to book their tickets.The time to book tickets will depend on  how many service windows are available, queue size and time taken by each representative.A person will either go in a lane which… read more »

Binary Search

Binary Search The binary search technique works only on sorted array.It works by comparing the input element to the middle element of array.The comparison determines whether the element is less than.greater than or equal to middle element.Subsequent steps to be followed are written and explained by the following program. Program #include <stdio.h> int main() {… 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 »

Strings

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 »

Sidebar