Skip to main content

Posts

Showing posts from August, 2011

Conditional Operator: ? : and its use on C++

The conditional operator is the only C++ ternary operator (working on three values). Other operators you have seen are called binary operators (working on two values). It is that is part of the syntax for a basic conditional expression in several programming languages. It is commonly referred to as the conditional operator or inline if (iif). ?: is used as follows: condition ? value if true : value if false The condition is evaluated true or false as a Boolean expression. On the basis of the evaluation of the Boolean condition, the entire expression returns value if true if condition is true, but value if false otherwise. Usually the two sub-expressions value if true and value if false must have the same type, which determines the type of the whole expression. The importance of this type-checking lies in the operator's most common use—in conditional assignment statements. Conditional Operator Implementation on C++: #include <iostream> using namespace std; int main() {

Data Structures Using C for you

Data Structures Using C is a module book for you. After working through this module you should be able to create and use new and complex data types within C programs. Learning objectives After working through this module you should be able to:  Manipulate character strings in C programs.  Declare and manipulate single and multi-dimensional arrays of the C data types.  Create, manipulate and manage C pointers to data elements.  Create and manage complex data types in C.  Use unions to define alternate data sets for use in C programs.  Allocate memory to variables dynamically.  Manipulate characters and bits. Content of this module: Strings. Arrays. Pointers. Data definitions – Structures. Data definitions – Unions. Dynamic allocation of data Character and bit manipulation Download Data Structures Using C

What is a linked list and why linked list?

What is a linked list ?       A linked list is a linear data structure used to organize the data in the memory. As its name indicates linked list is a list of items called the 'NODE' linked using  pointers. A 'NODE' is a structure of List containing  two or more fields called the 'data /Info' field and 'Link/address' field. A linked list can be of any of the following type. L inked list used for collecting a sequence of objects, which allows efficient addition, removal and retrieval of elements from any position in the sequence. It is implemented as nodes, each of which contains a reference (i.e., a  link ) to the next and/or previous node in the sequence. Singly-Linked Lists Doubly-Linked Lists or Two way Linked List Circularly-Linked Lists Circularly-Doubly Linked Lists Fig: Simple Linked List. Why Linked lists ?             Let us consider an example of implementation of a STACK or a QUEUE using a linear array then it is necessary to decl

Algorithm and its Runtime Analysis

Algorithm: An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output. Simple  Algorithm Run-time algorithm specialization  is a methodology for creating efficient algorithms for costly computation tasks of certain kinds. The methodology originates in the field of  automated theorem proving  and, more specifically, in the Vampire theorem prover project. One of the most important aspects of an algorithm is how fast it is. It is often easy to come up with an algorithm to solve a problem, but if the algorithm is too slow, it's back to the drawing board. Since the exact speed of an algorithm depends on where the algorithm is run, as well as the exact details of its implementation, computer scientists typically talk about the runtime relative to the size of the input. Approximate completion time for algorithms, N = 100 O(Log(N)) 10 -7  seconds O(N) 10 -6  seconds O(N*Log(N)) 10