Sie sind auf Seite 1von 4

Data Structure with C

Date:02/02/2012

Chapter 1: Instructor: Amit Kumar Gupta Topic: Introduction to Algorithm


-

Abstract data type:- It is a mathematical logical concept that defines a data type. Data type:- A method of interpreting a bit pattern is called a data type. Algorithm:- It is a step by step procedure to solve a given problem.
Representation of ve number is done by two ways- 1s complement & 2s complement, Concept of Logarithm & its properties. Date: 03/02/2012

Efficiency of Algorithm
It is determined by measuring the time and space required to execute the program. Amount of time taken (called time complexity) is calculated by finding the total no. of steps to be executed in the program. The space taken (called space complexity) is the no. of units required for memory storage.

- Time Complexity [T(n)]:-.


It deals with two calculations. a) Compilation Time (Error, declarative statements). b) Run Time (executable statements) Complexity is normally expressed as an order of magnitude of the input size. Such as O(n2),O(n),O(1) etc.

Categories: There are 3 types of cases.


1) Worst Case 2) Average Case 3) Best Case

Data Structure with C


1) Worst Case: The longest time taken by any algorithm to produce the desired result. T(n)=O(f(n)) 2) Average Case: The average time taken by any algorithm to produce the desired result. T(n)=A(f(n)) 3) Worst Case: The shortest time taken by any algorithm to produce the desried result. T(n)=(f(n))

- Space Complexity:It has three components. a) Instruction space (the space where compiled instructions are kept). b) Data space (variables, constants etc. are kept here). c) Environment space (space required in runtime).

Date: 06/02/2012

Asymptotic Notation:1) Big-Oh [O]:- Provides an upper limit for a function f. A function f(n)=O(g(n)) if there exists +ve constants c & n0 such that f(n)<=c.g(n), for all n>=n0 2) Big-Omega[]:- Provides lower limit of a function f. A function f(n)= (h(n)) if there exists +ve constants c & n0 such that f(n)>=c.h(n), for all n>=n0 3) Big-Theta[]:- Provides an upper limit as well as lower limit of a function f. A function f(n)= (g(n)) if there exists +ve constants C1,C2 & n0 such that C1.g(n)<=f(n)<=C2.g(n), for all n>=n0

- Big-Oh [O] Properties:a) b) c) d) If f(n) is a constant, then f(n)=O(1). If f(n)=O(h(n)) & g(n)=O(h(n)), then f(n)+g(n)=O(h(n)). All log functions are O(log n) ,independent of their bases. A polynomial function with a leading power k, C1.nk+C2.nk-1+.Ck.n+Ck+1=O (nk).

Data Structure with C


-

Timespace Tradeoff:- One algorithm may require more space but less time to complete its execution while the other algorithm requires less time space but takes more time to complete its execution. Thus, we may have to sacrifice one at the cost of the other. If the space is our constraint, then we have to choose a program that requires less space at the cost of more execution time. On the other hand, if time is our constraint such as in real time system, we have to choose a program that takes less time to complete its execution at the cost of more space. This is known as time space tradeoff.
Date: 07/02/2012

Topic: Arrays
-

Array:- An array is a collection of homogeneous data elements described by a single


name. Each element of an array is referenced by a subscripted variable or value, called subscript or index enclosed in parenthesis.

Accessing an array:-

2 basic operation are there that an array performs:1) Extraction 2) Storing

Array Bounds:- An array has upper bound as well as lower bound. We can find the
range of an array by following calculation. Range=Upper bond - lower bound+1.

Array Declaration:- We usually declare an array by following format.


data type=array_name[size]; ex:- int a[10];

Array can be represented in 2 way: a) 1-dimensional & b) Multi-dimensional. 2-D array is declared by int a[4][2] i.e in matrix form it has 4 row and 2 column. 2-D array can be represented in two ways: a) Row-major Order. b) Column-major Order.

Sparse matrix:- A sparse array is an array where nearly all of the elements have the
same value (usually zero) and this value is a constant. One-dimensional sparse array is called sparse vectors and two-dimensional sparse arrays are called sparse matrix. Identity matrix is the example of sparse matrix. 1 0 0 0 1 0 0 0 1

Data Structure with C


Date: 10/02/2012 LINKED LISTS:A linked list, or one way list, is a linear collection of data elements called nodes . where the linear order is given by means of pointers. i.e. Each node is divided into two parts: the firsts part contains the information of the element , and the second part called the link field or next pointer fields contains the address of the next node in the list, To overcome the drawbacks of sequential storage linked lists are used. One major drawback is that a fixed amount of storage remains allocated even when we are using a smaller amount or possibly no storage at all. Further , no more than fixed amount of storage may be allocated, thus introducing the possibility of over flow. info next node node LINEAR LINKED LIST. Each item in the list is called node and it contains two fields , an information fields and a next address fields. The information field hold the actual element on the list. The next address fields contain the address of next node in the list. Such an address , which is used to access a particular node, is known as a pointer. The entire linked list is accessed from an external pointer lists that points to the first node in the lists. (By an external pointer, we mean one that is not included within a node. Rather its value can be accessed directly by referencing a variable.) The next address field of the last node in the list contains a special value , known as null, which is not a valid address. This null pointer is used to signal the end of a list. The list with no nodes on it called the empty or the null list. info next null

info next

node

node

node

SOME Notations: Let P be a pointer to a node , then: Node (P) refers to the node pointed by P. Info (P) refers to the information content of that node P Next (P) refer to the address of the next node in the same linked list.

Das könnte Ihnen auch gefallen