Data Structures Through C. Student Handout Book
|
|
- Vernon Burns
- 5 years ago
- Views:
Transcription
1 Data Structures Through C Student Handout Book
2 Contents Lecture : C Revision I Importance of data structures Data types in C Instructions and its types The decision control instruction Working of logical operators Different types of loops Difference between break, continue and exit Case control instruction Lecture : C Revision II Pointers and their usage Function call by value and by reference Arrays and their working Lecture : Searching Operations performed on an array What are algorithms Important features of an algorithm Conventions to be followed while writing an algorithm Linear search and Binary search Lecture 4: Searching and Frequency count Analyzing an algorithm Rate of increase for growth rate with respect to Big Oh notation Lecture 5: Analysis of Searching Method Tools to calculate time complexity Cases to be considered while analyzing an algorithm Analysis of Linear search and Binary search Lecture 6: Hashing Hashing techniques: o Division method o Mid-Square method o Folding method o Digit analysis method Linear and Quadratic probing i
3 Lecture 7: Sorting Selection sort and its analysis Bubble sort and its analysis Radix sort Lecture 8: Sorting and Recursion Insertion sort Recursive functions Lecture 9: Quick Sort Splitting mechanism Quick sort algorithm Quick sort program Lecture 0: Structures Defining and using structures Array of structures Copying structure variables Nested structures Passing structure elements Passing structures Lecture : Structures and Polynomials Polynomial representation Passing array of structures General operations on polynomials Lecture : Two Dimensional Arrays Using two dimensional arrays Saddle point of an array Lecture : Sparse Matrices Sparse matrices Passing arrays tuple conversion Lecture 4: Transpose of Sparse Matrices Transpose of a sparse matrix Lecture 5: Addition of Sparse Matrices Addition of sparse matrices Lecture 6: Multiplication of Sparse Matrices Matrix multiplication ii
4 Multiplication of sparse matrices Lecture 7: Storage Storage - two dimensional arrays dimensional arrays 4 dimensional arrays n - dimensional arrays Lecture 8: Dynamic memory allocation Limitations of arrays Dynamic memory allocation Steps involved in memory allocation Lecture 9: Linked Lists Memory leaks Linked lists Creation of linked lists Lecture 0: Operations on Linked Lists I Appending a new node to a link list Adding a new node at the beginning of a linked list Adding a new node at a specified position in a linked list Deleting a node from a linked list Deleting all the nodes in a list Lecture : Operations on Linked Lists II Arranging the elements in a linked list in ascending order Sorting the elements in a linked list Lecture : Operations on Linked Lists - III Reversing a linked list Merging two linked lists Lecture : Operations on Linked Lists - IV Concatenating two linked lists Addition of polynomials using linked lists Lecture 4: Circular Linked Lists Circular linked lists Adding a new node to a circular list Deleting an existing node from a circular list Counting the nodes of a circular linked list Displaying the nodes in a circular linked list iii
5 Lecture 5: Doubly Linked Lists Doubly linked lists Common operations on a doubly linked list Lecture 6: Sparse Matrices as Linked Lists I Representing sparse matrices in the form of linked lists Lecture 7: Sparse Matrices as Linked Lists II Add new node to linked Lists Display contents of Linked List Delete all nodes in the Linked List Program to implement sparse matrices as linked lists Lecture 8: Recursive LL Recursive count( ) Recursive compare( ) Recursive copy( ) Recursive append( ) Lecture 9: Linked Lists Using Unions What are unions Declaring unions Using unions Generalized linked lists Lecture 0: Generalized Linked Lists Copying generalized linked lists Depth of generalized linked lists Comparing generalized linked lists Lecture : Stacks Stack and its utilities Program to implement stack as an array Lecture : Stack as a Linked List Program to implement stack as a linked list Lecture : Stack Expressions Different form of expressions Lecture 4: Stack Operations Infix to Postfix conversion Lecture 5: Postfix Evaluation of Postfix form iv
6 Lecture 6: Infix To Prefix Infix to Prefix conversion Lecture 7: Postfix To Prefix Evaluation of Prefix form Postfix to Prefix conversion Lecture 8: Postfix To Infix Postfix to Infix conversion Lecture 9: More Conversions Prefix to Postfix conversion Prefix to Infix conversion Lecture 40: Queue I Queue Program to implement queue as an array Lecture 4: Queue II Limitations of queue Circular queue Lecture 4: Deque and Priority Queue Deque Program to implement deque Priority queue Lecture 4: Trees What are trees Tree terminology Strictly and complete trees Lecture 44: Tree Traversal Preorder, Postorder and Inorder traversal Reconstruction of trees Lecture 45: Binary Search Trees I Representing trees using arrays Linked representation of trees Binary search trees Lecture 46: Binary Search Trees II Traversing of trees using Inorder, Preorder and Postorder Non recursive Inorder traversal of trees Non recursive Preorder traversal of trees v
7 Non recursive Postorder traversal of trees Comparison of two trees Lecture 47: Binary Tree Successor and predecessor Insertion of a node in a binary search tree Deleting an existing node from a binary search tree Searching a node in a binary search tree Lecture 48: Threaded Binary Tree Threaded binary trees Representation of threaded binary trees Inserting a node in a threaded binary tree Traversing the threaded binary tree in inorder Lecture 49: Heap Heap Creation of a heap Heap sort Lecture 50: AVL Trees and B Tree Program to create a heap AVL tree - tree B tree Lecture 5: Graphs Graphs Terminology associated with graphs Representation of graphs Adjacency list Lecture 5: Adjacency Multilist Adjacency matrices Adjacency multilist Orthogonal representation of graphs Lecture 5: Depth First Search Depth first search Program to implement depth first search algorithm Lecture 54: Breadth First Search Breadth first search vi
8 Program to implement breadth first search algorithm Lecture 55: Spanning Tree What is a spanning tree Cost of spanning tree Kruskal s algorithm to determine minimum cost spanning tree Lecture 56: Dijkstra s Algorithm Dijkstra s algorithm to determine minimum cost spanning tree AOV network Lecture 57: Memory Management I Memory management First fit algorithm Best fit algorithm Lecture 58: Memory Management II Next fit algorithm Lecture 59: Garbage Collection Garbage Collection Marking algorithm Compaction Lecture 60: File Organization Files File Organization vii
9 C Revision - I Yashavant Kanetkar Objectives The importance of data structures The data types in C What are instructions and its types The decision control instruction Working of logical operators Different types of loops Difference between break, continue and exit Case control instruction Data Structures What are they Way of organizing data and opns. performed on it Where are they used - Car Parking - File Storage - Dictionary - Shortest route - Searching Law Books - Sorting - Device Drivers - Evaluation of expression - Networking Ô ²¹«¹» Data Structures Through C / Lecture 0
10 C Data Types int char float Size: Bytes Specifier: %i %d Size: Byte Specifier: %c Size: 4 Bytes Specifier: %f C Instructions Type Declaration Instructions int i, j ; char ch, dh ; float a, b ; Arithmetic Instructions c = 5 / 9.0 * ( f - ) ; + - * / % - Arithmetic operators Input / Output Instructions printf( ), scanf( ) Control Instructions Control the sequence of execution of instructions Types - Sequence - Default - Decision - Repetition - Case Decision Control Instruction Implementation - if-else,? : General Form if ( condition ) Relational Operators statement ; else Logical Operators statement ; Cond. is usually built using <, >, <=, >=, = =,!= else block is optional Condition True Replaced by Condition False Replaced by 0 Truth in C is nonzero Falsity is zero &&! Data Structures Through C / Lecture 0
11 Working of && And cond cond cond && cond cond cond True True True True False False False False True False False True False False True True cond && cond cond executed only if cond is true cond cond cond executed only if cond is false Repetition Control Instruction for ( i = ; i <= 0 ; i++ ) printf ( "Hi" ) ; i = ; while ( i <= 0 ) printf ( "Hi" ) ; i++ ; i = ; do printf ( "Hi" ) ; i++ ; while ( i <= 0 ) ; Tips for - Finite no. of times while - Unknown no. of times do - while - At least once Loop counters can be int, long int, float or char Loop counters can be incremented or decremented by any suitable step value Effects of break & continue while (. ) if ( cond ) break ; if ( cond ) continue ; for (.. ;.. ; ) if ( cond ) break ; if ( cond ) continue ; do if ( cond ) break ; if ( cond ) continue ; while (. ) ; break - Terminates Loop exit( ) - Terminates Program Data Structures Through C / Lecture 0
12 Case Control Instruction n + / a + main( ) 4 + / 5 + switch ( expression ) case constant expression : case constant expression : + % 5 case constant expression : default : Data Structures Through C / Lecture 0 4
13
14
15
16 Searching Yashavant Kanetkar Objectives Operations performed on an array What are algorithms Important features of algorithms Conventions to follow while writing an algorithm Linear search and Binary search Algorithm Method of accomplishing a task in a finite number of steps Origin - Persian Mathematician - Abu Jaffer Al-Khowarizmi Aka - Recipe, Method, Technique, Procedure, Routine Important Features: Input- Must have zero or more inputs Output - Must have one or more outputs Finiteness - Must terminate after finite no. of steps Definiteness- Each step must be unambiguously defined Effectiveness - All operations must be sufficiently basic Types: Iterative - Repetition using loop Recursive- Divide and Conquer Data Structures Through C / Lecture 0
17 Array Operations Operations Traversal Search Insertion Deletion Sorting Merging Description Processing each element in the array Finding the location of an element with a given value Adding a new element to an array Removing an element from an array Organizing the elements in some order Combing two arrays into a single array Linear Search main( ) int a[ ] =,, 9,, 57, 5, 7,, 90, ; int i, num ; printf ( "Enter no. to search: " ) ; scanf ( "%d", &num ) ; for ( i = 0 ; i <= 9 ; i++ ) if ( a[ i ] == num ) break ; if ( i == 0 ) printf ( "No such number in array" ) ; else printf ( "Number is at position %d", i ) ; Binary Search main( ) int a[ ] =,,, 9,,, 7, 5, 57, 90 ; l m u int l = 0, u = 9, m, num ; printf ( "Enter number to search: " ) ; scanf ( "%d", &num ) ; 57 while ( l <= u ) m = ( l + u ) / ; if ( a[m] == num ) printf ( "No. is at position %d ", m ) ; exit( ) ; a[m] > num? ( u = m - ) : ( l = m + ) ; printf ( "Element is not present in the array." ) ; Data Structures Through C / Lecture 0
18 Searching & Frequency Count Yashavant Kanetkar Objectives Analyzing an algorithm Rate of increase for growth rate with respect to Big Oh notation Analysis Of Algorithms Determining Time Requirement Space Requirement Difficulty Machine dependent Language dependent Compiler dependent Solution Cheaper - Not so relevant Iterative - WD in loop Recursive - WD in break & make Don t calculate exact time Calculate approx. no. of operns. for given input No,. of opns Time Data Structures Through C / Lecture 04
19 Algorithm if ( a > b ) if ( a > c ) if ( a > d ) return a else return d end if else if ( c > d ) return c else return d end if end if Example - Biggest of 4 comparisons else if ( b > c ) if ( b > d ) return b else return d end if else if ( c > d ) return c else return d end if end if end if Algorithm big = a if ( b > big ) big = b end if if ( c > big ) big = c end if if ( d > big ) big = d end if return big What To Count Multiplication of Matrices- Number of multiplications Searching Sorting Count chars in a file for ( i = 0 ; i <= 55 ; i + + ) a[ i ] = 0 ; while ( ( ch = getc ( fp ) )!= EOF ) a[ ch ] + + ; N Opns. in Loop - Number of comparisons - Number of comparisons Opns. in Loop Total ( %) ( 66%) ( %) ( 99%) Fibonacci Series fibonacci ( ) old = ; 4 new = ; 5 n = 0 ; 6 for ( i = ; i < n ; i + + ) 7 8 a = old + new ; 9 printf ( "%d ", a ) ; 0 old = new ; new = a ; Ignoring the const 5 & complexity -> O( n ) Line no. No. of execution Data Structures Through C / Lecture 04
20 Determine the frequency counts for all statements in the following two program segments: for ( i = 0 ; i < n ; i + + ) for ( j = 0 ; j < i ; j + + ) 4 5 for ( k = 0 ; k < j ; k + + ) 6 7 x + + ; i = 0 while ( i < n ) 4 x = x + ; 5 i = i + ; 6 Exercise O ( n ) Line no. No. of exec. n ( + i + i j ) O ( n ) Line no. No. of exec. Rate of Increase n log n n log n n n n O( ) - const., O( n ) - linear, O( n ) - quadratic, O( n ) - cubic O( n ) - exponential O( log n ) is faster than O( n ) O( n log n ) is faster than O( n ) but not as good as O( n ) Exercise For which range of values would the algorithm whose order of magnitude is n be better than an algorithm who order of magnitude is n n n n Range Better Data Structures Through C / Lecture 04
21 Analysis Of Searching Methods Yashavant Kanetkar Objectives Tools to calculate time complexity Cases to be considered while analyzing algorithms Analysis of Linear search and Binary search Classification Of Growth Rate of growth is dominated by largest term in an equation Neglect terms that grow more slowly Leftover is known as order of the algorithm Algos. are grouped into categories based on their order Big Omega - ( f ) If g( x ) ( f ), g( n ) >= cf( n ) for all n >= n 0 (c = const.) Represents class of funcns that grow at least as fast as f Big Oh - O( f ) If g( x ) O( f ), g( n ) <= cf( n ) for all n >= n 0 (c = const.) Represents class of funcns that grow no faster than f Big Theta - ( f ) ( f ) = ( f ) O( f ) Represents class of funcns that grow as fast as f Data Structures Through C / Lecture 05
22 Analysis Of Linear Search linearsearch ( int *list, int value, int n ) Best Worst Avg. for ( i = 0 ; i < n ; i + + ) N N + if ( value == list [ i ] ) return i ; Possible inputs return - ; Probability of each input The value being searched is found in first location The value being searched matches the last elements in the list The value being searched is not present in the list A( N ) = Probability A( N ) = A( N ) = Average Case N i + N N + * i = N N + i + i = N + * N N + * N ( N + ) + N N + A( N ) = N N N + = + _ N + N + N + A( N ) (As n gets very large, becomes almost 0) N + bisearch ( int *a, int x ) lower = 0 ; upper = 0 ; while ( lower <= upper ) mid = ( lower + upper ) / ; switch ( compare ( x, a[ mid ] ) ) case '>' : lower = mid + ; break ; case '<' : upper = mid - ; break ; case '= : printf ( "%d ", mid ) ; exit( ) ; Analysis Of Binary Search Best Worst log ( N + ) Halving nature of algo. N = k - k - -,, k - - K =, - = 7, N = 7 - -,, - -,, K =, - =, N = - -,, - -,, N = k - log k = log ( N + ) k log = log ( N + ) k = log ( N + ) Data Structures Through C / Lecture 05
23 Hashing Yashavant Kanetkar Objectives Hashing Techniques Division method Mid Square method Folding method Digit Analysis method Linear and quadratic probing Hashing Functions Division Mid - Square Folding Digit Analysis Data Structures Through C / Lecture 06
24 Division Store elements as per hash value Hash value - index based Hash value = no. % 0 If hash value clashes - collision - chaining (not efficient) - rehashing Linear Probing Mid - Square Identifiers - A =,..., Z = 6, 0 = 7, = 8,..., 9 = 6 Find octal equivalent of each character Square the octal equivalent Use middle bits of square as hash value Table size = r, r is no. of middle bits X X (X ) A 0 B Y 70 Z A A 5 07 CAT Folding Distribute digits in multiple partitions Excluding last make all partitions equal Add partition values to get hash value No. Of Digits Partition, 4,, 5,, 6,,,, 7,, 8,, 9,,,, CAT Data Structures Through C / Lecture 06
25 Digit Analysis Each identifier is interpreted as a no. using some radix r Same radix is used for other identifiers Digits in each identifier is examined Digits with skewed distribution are deleted Digits are deleted till balance digits are in range of HT More Hashing Hash table contains buckets Each buckets may contain several slots Each slot can hold one record Collision - when two identifiers hash into same bucket Overflow - when new identifier is hashed into a full bucket If number of slots = then Collision = Overflow Collision handling techniques: Linear probing - search the bucket ( f ( x ) + i ) % b, for 0 <= i <= b - Quadratic probing - search the bucket f ( x ) ( f ( x ) + i ) % b ( f ( x ) - i ) % b, for <= i <= ( b - ) / Linear Probing f ( x ) = no. % 0 f ( int no, int *arr, int b ) int i, j, initialpos ; j = no % 0 ; intialpos = j ; for ( i = ; arr[ j ]!= no && arr[ j ]!= 0 ; i + + ) j = ( no % 0 + i ) % b ; if ( j == initialpos ) printf ( "Array full" ) ; return ; arr [ j ] = no ; key = ( f( x ) + i ) % b Data Structures Through C / Lecture 06
26 Quadratic Probing f ( x ) = no. % 0 key = f( x ) = f( x ) + i ) % b = f( x ) - i ) % b for <= i <= ( b - ) / Data Structures Through C / Lecture 06 4
27 Sorting Yashavant Kanetkar Objectives Selection Sort and its Analysis Bubble Sort and its Analysis Radix Sort Selection Sort main( ) int a[ ] = 7, 6,,, ; int i, j, t ; for ( i = 0 ; i <= ; i + + ) for ( j = i + ; j <= 4 ; j + + ) if ( a[ i ] >a[ j ] ) t = a[ i ] ; a[ i ] = a[ j ] ; a[ j ] = t ; for ( i = 0 ; i <= 4 ; i + + ) printf ( "%d", a[ i ] ) ; 7 6 i j Data Structures Through C / Lecture 07
28 Analysis Of Selection Sort selectionsort ( int *a, int n ) for ( i = 0 ; i < n - ; i + + ) for ( j = i + ; j < n ; j + + ) if ( a[ i ] > a[ j ] ) t = a[ i ] ; a[ i ] = a[ j ] ; a[ j ] = t ; i 7, 6,,, No. of comp. 0 4 N - i = N ( N - ) i = = O ( N ) main( ) Bubble Sort int a[ ] = 7, 6,,, ; int i, j, t ; for ( j = 0 ; j <= ; j + + ) for ( i = 0 ; i <= - j ; i + + ) if ( a[ i ] > a[ i + ] ) t = a[ i ] ; a[ i ] = a[ i + ] ; a[ i + ] = t ; for ( i = 0 ; i <= 4 ; i + + ) printf ( "%d", a[ i ] ) ; 7 6 i i bubblesort ( int *a, int n ) for ( j = 0 ; j < n - ; j + + ) for ( i = 0 ; i < ( n - ) - j ; i + + ) if ( a[ i ] > a[ i + ] ) t = a[ i ] ; Analysis Of Bubble Sort a[ i ] = a[ i + ] ; a[ i + ] = t ; 7, 6,,, j No. of comp. 0 4 N - i = N ( N - ) i = = O ( N ) Data Structures Through C / Lecture 07
29 Q 0 Q Q Q Q 4 Q 5 Q 6 Q 7 Q 8 Q 9 Radix Sort Add elements in Q respective Q. Initially, w.r.t units Q 6 place then w.r.t tens Q 7 9 place and so on... Q Q Q 5 Q 6 Q 7 Q 8 Q main( ) int a[ ] = 9, 47,,, 5,, 7, 4, 54, 76 ; int arr[ 0 ][ ], k, dig ; dig = ; for ( k = 0 ; k <= ; k + + ) initq ( arr ) ; radix ( a, arr, 0, dig ) ; combine ( a, arr ) ; dig *= 0 ; for ( i = 0 ; i < 0 ; i + + ) printf ( "%d", a [ i ] ) ; Program initq ( int arr[ 0 ][ ] ) int i, j ; for ( i = 0 ; i < 0 ; i + + ) for ( j = 0 ; j < ; j + + ) arr[ i ][ j ] = 0 ; Contd......Contd. radix ( int a[ ], int arr[ ][ ], int n, int dig ) int i, j, key ; for ( i = 0 ; i < n ; i + + ) key = ( a [ i ] / dig ) % 0 ; for ( j = 0 ; j < ; j + + ) if ( arr[ key ][ j ] == 0 ) arr[ key ][ j ] = arr[ i ] ; break ; combine ( int *a, int arr[ ][ ] ) int i, j, x = 0 ; for ( i = 0 ; i < 0 ; i + + ) for ( j = 0 ; j < ; j + + ) if ( arr[ i ][ j ]! = 0 ) a[ x ] = arr[ i ][ j ] ; x + + ; Data Structures Through C / Lecture 07
30 Sorting & Recursion Yashavant Kanetkar Objectives Insertion Sort Recursive Functions Insertion Sort main( ) int a[ ] = 0,, 8, 9, 4, ; for ( i = 0 ; i <= 5 ; i ++ ) int i, j, k, t ; printf ( "%d\t", a[ i ] ) ; for ( i = ; i <= 5 ; i ++ ) t = a[ i ] ; a[0] a[] a[] a[] a[4] a[5] for ( j = 0 ; j < i ; j++ ) if ( t < a[ j ] ) t for ( k = i ; k >= j ; k-- ) a[ k ] = a[k - ] ; a[ j ] = t ; break ; a[0] a[] a[] a[] a[4] a[5] a[0] a[] a[] a[] a[4] a[5] Data Structures Through C / Lecture 08
31 Simple Form main( ) printf ( Hi ) ; main( ) ; One More Form main( ) f( ) ; f( ) printf ( Hi ) ; f( ) ; More General main( ) int num, sum ; printf ( Enter a number ) ; scanf ( %d, &num ) ; sum = sumdig ( num ) ; printf ( %d, sum ) ; sumdig ( int n ) int d ; int s = 0 ; while ( n!= 0 ) d = n % 0 ; n = n / 0 ; s = s + d ; return ( s ) ; 698 d5 485 d n s d main( ) int num, sum ; printf ( Enter a number ) ; scanf ( %d, &num ) ; sum = rsum ( num ) ; printf ( %d, sum ) ; rsum ( int n ) int d ; int s ; if ( n!= 0 ) d = n % 0 ; n = n / 0 ; s = d + rsum ( n ) ; else return ( 0 ) ; 4! 4 * * * 4 *! *! *! return ( s ) ; Data Structures Through C / Lecture 08
32 rsum ( int n ) if ( n!= 0 ) d = 7 % 0 ; n = 7 / 0 ; s = 7 + rsum ( ) ; else return ( 0 ) ; return ( s ) ; rsum ( int n ) if ( n!= 0 ) d = % 0 ; n = / 0 ; s = + rsum ( ) ; else return ( 0 ) ; return ( s ) ; rsum ( int n ) if ( n!= 0 ) d = % 0 ; n = / 0 ; s = + rsum ( 0 ) ; else return ( 0 ) ; return ( s ) ; rsum ( int n ) if ( n!= 0 ) d = n = s = else return ( 0 ) ; return ( s ) ; Recursive Factorial main( ) Recursion Tips int num, fact ; Make recursive call in an if printf ( Enter no. ) ; scanf ( %d, &num ) ; else block is escape route fact = refact ( num ) ; else contains end cond. logic printf ( %d, fact ) ; return may not be present refact ( int n ) int p ; if ( n!= 0 ) p = n * refact ( n - ) ; else return ( ) ; return ( p ) ; Data Structures Through C / Lecture 08
33 Quick Sort Yashavant Kanetkar Objectives Splitting mechanism in quick sort Quick sort algorithm Quick sort program Split Array Data Structures Through C / Lecture 09
34 Quick Sort void quicksort ( int *, int, int ) ; int split ( int *, int, int ) ; main( ) int arr[ 0 ] =,, 9,, 57, 5, 7,, 90, ; int i ; quicksort ( arr, 0, 9 ) ; for ( i = 0 ; i <= 9 ; i++ ) printf ( "%d\t", arr[ i ] ) ; void quicksort ( int *a, int lower, int upper ) int i ; if ( upper > lower ) i = split ( a, lower, upper ) ; quicksort ( a, lower, i - ) ; quicksort ( a, i +, upper ) ; Cont..Contd p - L to R int split ( int a[ ], int lower, int upper ) int i, p, q, t ; p = lower + ; q = upper ; i = a[ lower ] ; while ( p <= q ) while ( a[ p ] < i ) p + + ; while ( a[ q ] > i ) q - - ; q - R to L if ( p < q ) t = a[ p ] ; a[ p ] = a[ q ] ; a[ q ] = t ; t = a[ lower ] ; a[ lower ] = a[ q ] ; a[ q ] = t ; return q ; Problem Show the steps for sorting the following numbers using Quick Sort Algorithm [ 4,, 74,, 65, 58, 94, 6, 99, 87 ] Data Structures Through C / Lecture 09
35 Exercise Wrtie the steps for quick sort of following elements: [ 4,, 74,, 65, 58, 94, 6, 99, 87 ] p q p q p q p q p q pq q p Contd... Contd q p p q 6 4 p q 6 q p p q p q p q p q q p Complexity Algorithm Worst Case Best Case Bubble sort O (n ) O (n ) Selection Sort O (n ) O (n ) Quick Sort O (n ) log n Insertion sort O (n ) n Binary Tree Sort O (n ) O (n log n) Heap Sort O (n log n) O (n log n) Merge Sort O (n log n) O (n log n) Data Structures Through C / Lecture 09
36 Structures Yashavant Kanetkar Objectives Defining and using structures Creating an array of structures How to copy one structure variable into another Using nested structures Passing structure elements Passing structures main( ) char n[ ] = A, X, Y, \0 ; int a[ ] =, 7, 8 ; float s[ ] = , , ; int i ; Handling Data for ( i = 0 ; i <= ; i ++ ) printf ( "%c %d %f", n[ i ], a[ i ], s[ i ] ) ; Data Structures Through C / Lecture 0
37 main( ) struct employee. structure char n ; operators int a ; float s ; ; struct employee e = A,, ; struct employee e = X, 7, ; struct employee e = Y, 8, ; printf ( "%c %d %f", e. n, e. a, e. s ) ; printf ( "%c %d %f", e.n, e.a, e.s ) ; printf ( "%c %d %f", e.n, e.a, e.s ) ; Structures main( ) struct employee char n ; int a ; float s ; ; struct employee e[ ] Array of Structures = A,, , X, 7, , Y, 8, ; int i ; for ( i = 0 ; i <= ; i++ ) printf ( "%c %d %f", e[ i ].n, e[ i ].a, e[ i ].s ) ; Keyword Terminology Structure struct employee name/tag char n ; Structure int a ; elements/ members float s ; ; struct employee e, e, e[ 0 ] ; Structure variables Array of structures Data Structures Through C / Lecture 0
38 Conclusion A structure is usually a collection of dissimilar elements. Structure elements are always stored in adjacent memory locations. struct employee e[ ] =.. ; A X Y struct employee e[ ] =... ; char *p ; struct employee *q ; struct employee (*r )[ ] ; Array of Structures A X Y Ptr. to structure Ptr. to array of structures p = e ; q = e ; r = e ; p++ ; q++ ; r++ ; printf ( "%u", p ) ; printf ( "%u", q ) ; printf ( "%u", r ) ; struct employee *z[] ; Array of Ptrs to structures Copying e Rahul piecemeal copying main( ) struct emp char n[0] ; int a ; float s ; ; Rahul e e struct emp e = "Rahul",, ; struct emp e, e ; e.n = e.n ; e.a = e.a ; e.s = e.s ; Rahul strcpy ( e.n, e.n) ; copying at one shot e = e ; printf ( "%s %d %f", e.n, e.a, e.s ) ; Data Structures Through C / Lecture 0
39 main( ) struct address char city[0] ; long int pin ; ; Nested Structures Rahul Ngp struct emp char n[0] ; int age ; struct address a ; float s ; ; struct emp e= "Rahul",, "Ngp", 4400, ; printf ( "%s %d %s %ld %f", e.n, e.age, e.city, e.pin, e.s ) ; e.a.city a.city e.a.pin printf ( %d, a.b.c.d.e.f ) ; f - int e a Passing Structure Elements main( ) struct book Basic 50 b char n[0] ; int nop ; float pr ; ; struct book b = "Basic", 45, 5.00 ; display (b.n, b.nop, b.pr ) ; show ( b.n, &b.nop, b.pr ) ; display ( char *n, int pg, float p ) printf ( "%s %d %f", n, pg, p ) ; show ( char *n, int *pg, float *p ) printf ( "%s %d %f", n, *pg, *p ) ; Passing Structures b Basic main( ) struct book char n[0] ; int nop ; float pr ; ; struct book b = "Basic", 45, 5.00 ; display ( b ) ; show ( &b ) ; display ( struct book bb ) printf ("%s %d %f", bb.n, bb.nop, bb.pr ) ; show ( struct book *bb ) printf ( "%s %d %f", ( * bb ).n,( * bb ).nop,( * bb ).pr ); printf ( "%s %d %f", bb -> n, bb -> nop, bb -> pr ) ; Data Structures Through C / Lecture 0 4
40
41
42
43
44 Two Dimensional Arrays Yashavant Kanetkar Objectives Declaring and using two dimensional arrays How to write a program to find the saddle point main( ) int a[ ][ 5 ] =, 6,, 8, 4, optional,, 5, 6, 8, compulsory 7, 9, 8, 7,, 4, 5, 6, 8, 0 ; int i, j ; printf ( "%d", a[ ][ 4 ] ) ; printf ( "%d %d", sizeof ( a ), a ) ; for ( i = 0 ; i <= ; i + + ) for ( j = 0 ; j <= 4 ; j + + ) printf ( "%d", a [ i ][ j ] ) ; printf ( \n ) ; Two Dimensional Array optional int b[ ][][][] compulsory Data Structures Through C / Lecture
45 main( ) int a[ ][ 5 ] = 5,,, 6, 5, 4, 9,, 4, 8, 9, 4,,, 9, 7,, 0, 8, 7, 6,,, 5, 9 ; for ( i = 0 ; i <= 4 ; i++ ) small = a[ i ][ 0 ] ; for ( j = 0 ; j <= 4 ; j++) if ( a[ i ][ j ] < small ) small = a[ i ][ j ] ; col = j ; Saddle Point big = small ; for ( r = 0 ; r <= 4 ; r++ ) if ( a[ r ][ col ] > big ) big = a[ r ][ col ] ; row = r ; if ( big == small ) printf ( "%d", big ) ; printf ( "%d %d", row, col ); break ; Define variables Problem Given matrices A & B of the order ( n x n ) Upper triangle = 0, Lower triangle = Non-zero Generate C of n x ( n + ) t o accommodate A and B a[ 4 ][ 4 ] b[ 4 ][ 4 ] c[ 4 ][ 5 ] A 0, 0, 0, 0, 0,,,,,, C 0, 0, 0, 0, 0,,,,,, B 0, 0, 0, 0, 0,,,,,, C 0, 0, 0, 0, 4,,, 4,, 4, 4 main( ) int a[ ][ 4 ] =, 0, 0, 0, 5,, 0, 0, 6, 7,, 0, 8, 9, 0, 4 ; int b[ ][ 4 ] = ; int c[ 4 ][ 5 ], i, j ;, 0, 0, 0, 5,, 0, 0, 6, 7,, 0, 8, 9, 0, 4 for ( j = 0 ; j <= ; j++ ) for ( i = j ; i <= ; i++ ) c[ i ][ j ] = a[ i ][ j ] ; A 0, 0, 0, 0, 0,,,,,, C 0, 0, 0, 0, 0,,,,,, B 0, 0, 0, 0, 0,,,,,, C 0, 0, 0, 0, 4,,, 4,, 4, 4 for ( i = 0 ; i <= ; i ++ ) for ( j = i + ; j <= 4 ; j++ ) c[ i ][ j ] = b[ j - ][ i ] ; Cont Data Structures Through C / Lecture
46 Cont for ( i = 0 ; i <= ; i ++ ) for ( j = 0 ; j <= 4 ; j++ ) printf ( "%d ", c[ i ][ j ] ) ; printf ( "\n" ) ; Determine Determine values of a[ i ][ j ] and b[ i ][ j ] from matrix c Determine a[ i ][ j ] Determine b[ i ][ j ] if ( j > i ) element = 0 ; else element = c[ i ] [ j ] ; if ( j > i ) element = 0 ; else element = c[ j ] [ i + ] ; a[ ][ ] = c[ ][ ] b[ ][ ] = c[ ][ 4 ] x x x 5 Problem A magic square of 4 rows x 4 columns contains different elements. Write a function to verify whether the sum of each individual column elements, sum of each individual row elements and sum of diagonal elements is equal or not Data Structures Through C / Lecture
47 Sparse Matrices Yashavant Kanetkar Objectives Sparse matrices How to pass arrays Performing tuple conversion Sparse Matrices r c Non-zero Tuple Form Data Structures Through C / Lecture
48 Passing Arrays main( ) int a[ ][ 4 ] =, 0,, 8, 5,, 0, 7 ; fun ( a, 4, 5 ) ; fun ( a, 4, 5 ) ; fun ( int ( *p )[ 4 ], int r, int c ) int i, j ; for ( i = 0 ; i < r ; i++ ) for ( j = 0 ; j < c ; j++ ) printf ( "%d", p[ i ][ j ] ) ; fun ( int *pa, int r, int c ) General int i, j ; for ( i = 0 ; i < r ; i++ ) for ( j = 0 ; j < c ; j++ ) printf ( "%d", *pa ) ; pa++ ; a[ ] p[ ][ ] * ( * ( p + ) + ) -Tuple Conversion # include <alloc.h> main( ) int a[ ][ 4 ] = 4, 0, 0,,, 0, 0, 9, 6,, 0, 0 ; int *ta ; ta = create ( a,, 4 ) ; display ( ta ) ; free ( ta ) ; r c Non-zero Cont int * create ( int *pa, int r, int c ) int rows, *p, i, j, k ; rows = count ( pa, r, c ) + ; p = ( int * ) malloc ( rows * * sizeof ( int ) ) ; pa p[ 0 ] = r ; p[ ] = c ; p[ ] = rows - ; k = ; p for ( i = 0 ; i < r ; i++ ) for ( j = 0 ; j < c ; j++ ) if ( *pa!= 0 ) p[ k ] = i ; k++ ; p[ k ] = j ; k++ ; p[ k ] = *pa ; k++ ; pa ++ ; return p ; Data Structures Through C / Lecture
49 Cont int count ( int *pa, int r, int c ) int count = 0, i, j ; for ( i = 0 ; i < r ; i++ ) for ( j = 0 ; j < c ; j++ ) if ( *pa!= 0 ) pa count ++ ; pa++ ; return count ; Cont void display ( int *p ) int i, rows ; rows = p[ ] + ; for ( i = 0 ; i < rows * ; i++ ) if ( i % == 0 ) printf ( "\n" ) ; printf ( "%d\t", p[ i ] ) ; p Data Structures Through C / Lecture
50 Transpose of Sparse Matrices Yashavant Kanetkar Objectives How to get the transpose of a sparse matrix Transpose Hint Search for 0,,, etc. in first column of matrix A and then set matrix B Data Structures Through C / Lecture 4
51 Program - Transpose #include <alloc.h> main( ) int a[ 5 ][ 4 ] = 4, 0, 0,,, 0, 0,, 0, 0,, 5,, 0, 0, 0,, 0, 0, ; int *ta, *tb ; ta = create ( a, 5, 4 ) ; tb = transpose ( ta ) ; display ( tb ) ; free ( ta ) ; free ( tb ) ; int * transpose ( int *ta ) int rows, c, nz, p, q, cols ; int *tb ; rows = ta[ ] + ; tb = ( int * ) malloc ( rows * * sizeof ( int ) ) ; tb[ 0 ] = cols = ta[ ] ; tb[ ] = ta[ 0 ] ; tb[ ] = nz = ta[ ] ; q = ; for (c = 0 ; c < cols ; c++ ) for ( p = ; p <= nz; p++) if ( ta[ p * + ] == c ) tb[ q* ] = ta[ p*+ ] ; tb[ q*+ ] = ta[ p* ] ; tb[ q*+ ] = ta[ p*+ ]; q++ ; return tb ; Problem Write a program to verify whether transpose of a give sparse matrix is same as the original sparse matrix. Data Structures Through C / Lecture 4
52 Addition of Sparse Matrices Yashavant Kanetkar Objectives How to perform addition of two sparse matrices Addition of SM = = Data Structures Through C / Lecture 5
53 = Tips Rows in C = Rows in A + Rows in B - Sometimes True Row of A < Row of B - Copy from A Row of B < Row of A - Copy from B Row A = Row B Check columns Addition of SM # include <alloc.h> main( ) int a[ 5 ][ 4 ] = 4, 0, 0,,, 0, 0,, 0, 0,, 5,, 0, 0, 0,, 0, 0, ; int b[ 5 ][ 4 ] = 7, 0, 0, 0, 0,,, 0, 0, 5, 0,, 0, 0, 0, 0, 0, 0, 0 ; int *ta, *tb, *tc ; ta = create ( a, 5, 4 ) ; tb = create ( b, 5, 4 ) ; tc = add ( ta, tb ) ; display ( tc ) ; free ( ta ) ; free ( tb ) ; free ( tc ) ; else rowa = cola = BIGNUM ; #define BIGNUM 00 int * add ( int *s, int *s ) int *p, i, j, k ; int max, maxa, maxb ; if ( j <= maxb ) int rowa, cola, vala ; int rowb, colb, valb ; maxa = s[ ] ; maxb = s[ ] ; max = maxa + maxb + ; p = ( int * ) malloc ( max * * sizeof (int) ) ; i = j = k = ; while ( k <= max ) if ( i <= maxa ) rowa = s[ i * + 0 ] ; cola = s[ i * + ] ; vala = s[ i * + ] ; rowb = s[ j * + 0 ] ; colb = s[ j * + ] ; valb = s[ j * + ] ; else rowb = colb = BIGNUM ; Data Structures Through C / Lecture 5
54 Cont if ( rowa < rowb ) p[ k * + 0 ] = rowa ; p[ k * + ] = cola ; p[ k * + ] = vala ; i++ ; if ( rowa > rowb ) p[ k * + 0 ] = rowb ; p[ k * + ] = colb ; p[ k * + ] = valb ; j++ ; = Cont.. Cont if ( rowa == rowb ) if ( cola == colb ) p[ k*+0 ] = rowa ; p[ k* + ] = cola ; p[ k*+ ] = vala + valb ; i++ ; j++ ; max- - ; if ( cola < colb ) p[ k * + 0 ] = rowa ; p[ k * + ] = cola ; p[ k * + ] = vala ; i++ ; if ( cola > colb ) p[ k * + 0 ] = rowb ; p[ k * + ] = colb ; p[ k * + ] = valb ; j++ ; // if k++ ; // end of while loop Cont p[ 0 ] = s[ 0 ] ; p[ ] = s[ ] ; p[ ] = max ; return p ; // end of add( ) = Cont.. Data Structures Through C / Lecture 5
55 Multiplication of Sparse Matrices Yashavant Kanetkar Objectives Matrix multiplication Multiplication of sparse matrices Matrix Multiplication x for ( i = 0 ; i < ; i + + ) for ( j = 0 ; j < ; j + + ) s = 0 ; for ( k = 0 ; k < 4 ; k + + ) s = s + a[ i ][ k ] * b[ k ][ j ] ; x 4 4 x x c[ i ][ j ] = s ; = i k k j i k k j Data Structures Through C / Lecture 6
56 Multiplication of SM # include <alloc.h> main( ) int a[ ][ 4 ] = 4, 0, 0,,, 0, 0, 9, 6,, 0, 0 ; int b[ 4 ][ ] =, 0,, 0, 0, 0, 0, ; int *ta, *tb, *tc ; ta = create ( a,, 4 ) ; tb = create ( b, 4, ) ; tc = mul ( ta, tb ) ; display ( tc ) ; free ( ta ) ; free ( tb ) ; free ( tc ) ; Cont int* mul ( int *x, int *y ) int *c, i, j, k, px ; k = x[ 0 ] * y[ ] + ; z = ( int * ) malloc ( k * * sizeof ( int ) ) ; k = ; for ( i = 0 ; i < x[ 0 ] ; i++ ) for ( j = 0 ; j < y[ ] ; j++ ) px = s_in_x ( x, i ) ; p To be Continued... s_in_x ( int *p, int i ) int j ; for ( j = ; j <= p[ ] ; j++ ) if ( p[ j * ] == i ) return j ; return - ; int* mul ( int *x, int *y ) /* Existing Code */ for ( i = 0 ; i < x[ 0 ] ; i++ ) for ( j = 0 ; j < y[ ] ; j++ ) px = s_in_x ( x, i ) ; if ( px!= - ) py = s_in_y ( y, j, x[ px * + ] ) ; s_in_x ( int *p, int j, int colx ) int i ; for ( i = ; i <= p[ ] ; i++ ) if ( p[ i * + ] == j && p[ i * ] == colx ) return i ; return - ; col X = row Y Data Structures Through C / Lecture 6
57 int* mul ( int *x, int *y ) for ( i = 0 ; i < x[ 0 ] ; i++ ) for ( j = 0 ; j < y[ ] ; j++ ) px = s_in_x ( x, i ) ; if ( px!= - ) s = 0 ; while ( x[ px * ] == i ) py = s_in_y ( y, j, x[ px*+ ] ); if ( py!= - ) s = s + x[ px * + ] * y[ py * + ] ; px++ ; int* mul ( int *x, int *y ) int *z, i, j, k, px, py, s ; for ( i = 0 ; i < x[ 0 ] ; i + + ) for ( j = 0 ; j < y[ ] ; j + + ) px = s_in_x ( x, i ) ; if ( px!= - ) s = 0 ; while ( x[ px * ] == i ) py = s_in_y (... ) ; if ( py!= - ) s = s +... ; px++ ; if ( s!= 0 ) z[ k * + 0 ] = i ; z[ k * + ] = j ; z[ k * + ] = s ; k++ ; // if // j loop // i loop z[ 0 ] = x[ 0 ] ; z[ ] = y[ ] ; z[ ] = k - ; return z ; Data Structures Through C / Lecture 6
58 Storage Yashavant Kanetkar Objectives How two dimensional arrays are stored -D arrays 4-Darrays N-D arrays Storage - D Array Row major x 4 matrix a 00 a 0 a 0 a 0 a 0 a a a a 0 a a a a 00 a 0 a 0 a 0 a 0 a a a a 0 a a a int a[ ][ 4 ] ; a int a[ m ][ n ] a ij Col major a 00 a 0 a 0 a 0 a a a 0 a a a 0 a a int a[ ][ 4 ] ; int a[ m ][ n ] a aij Data Structures Through C / Lecture 7
59 -D Array a[ u, u, u ] u u u Row major a[ i ][ j ][ k ] Column major a[ i ][ j ][ k ] 4-D Array a[ u, u, u, u 4 ] Row major a[ i ][ j ][ k ][ l ] Column major a[ i ][ j ][ k ][ l ] n-dimensional Array a[ u, u, u,, u n ] Row major a[ i ][ i ][ i ][.. ][ i n ] + ( i ) * u u u 4 u n + ( i ) * u u 4 u n + ( i ) * u4u5 un + ( i 4 ) * u 5u 6 u n ( i n - ) * u n + ( i n ) Column major a[ i ][ i ][ i ][.. ][ i n ] + ( i ) * u u u 4 u n + ( i ) * u u 4 u n + ( i ) * u4u5 un + ( i 4 ) * u 5u 6 u n ( i n ) * u n - + ( i n - ) Data Structures Through C / Lecture 7
60 Row major Col major Problem Find location of element A[ 6 ][ ][ ][ 8 ] relative to first element of the array A[ :8][ :4][ :6 ][ 6:9 ] + ( 6 ) * ( ( 4 + ) * ( 6 + ) * ( ) ) + ( ) * ( ( 6 + ) * ( ) ) + ( ) * ( ) ( 6 ) * ( ( 4 + ) * ( 6 + ) * ( ) ) + ( ) * ( ( 6 + ) * ( ) ) + ( 8 6 ) * ( 6 + ) + Problem Find the location of an element A[ 7 ][ 8 ][ ][ 5 ] relative to the first element of the array A[ 6:8 ][ 7:0 ][ :5 ][ 5:8 ] Data Structures Through C / Lecture 7
61 Dynamic Memory Allocation Yashavant Kanetkar Objectives Limitations on arrays Dynamic memory allocation How the memory allocation is done Arrays No Flexibility main( ) int m, m, m, i, per [ 0 ] ; for ( i = 0 ; i <= 9 ; i++ ) printf ( "Enter marks" ) ; scanf ( "%d %d %d", &m, &m, &m ) ; per [ i ] = ( m + m + m ) / ; printf ( "%d", per [ i ] ) ; Data Structures Through C / Lecture 8
62 Memory p n * Dynamic Allocation # include "alloc.h" main( ) int *p ; int m, m, m, i, per ; printf ( "Enter no. of students" ) ; scanf ( "%d", &n ) ; malloc ( n * ) ; for ( i = 0 ; i < n ; i++ ) scanf ( "%d%d%d", &m, &m, &m ) ; per = ( m + m + m ) / ; * ( p + i ) = per ; for ( i = 0 ; i < n ; i++ ) printf ( "%d", *( p + i ) ) ; Memory Allocation Array malloc( ) Static Dynamic Compile Time Execution Time Variables are created only during execution Static - Arrangement made at compilation time - Arrangement - Offset + Instruction to create var Dynamic - Arrangement made at execution time - Arrangement - Call to malloc( ) int x, y ; main( ) int j ; float k ; int *p ; p = ( int * ) malloc ( 0 ) ; Compiler Symbol table entries for variables - Name, Scope, Length - Offset from DS (global), SS (local) Instructions for local variables Call to malloc( ) Creates OBJ and discards Symbol Table Our object code + Library s object code Create EXE file format (Header to help loader) If too many globals - Loader fails Fatal If too many locals - Stack overflow If too much dynamic demand - Heap full Allocation Linker Loader Data Structures Through C / Lecture 8
63 Better Still...? int *p[ ] ; char ch = Y ; while ( ch = = Y ) scanf ( "%d %d %d", &m, &m, &m ) ; per = ( m + m + m ) / ; malloc ( ) ; p p p *p = per ; printf ( "Another student y/n" ) ; ch = getche( ) ; Memory Leaks Best... NULL node data link Linked List struct node int data ; struct node *link ; ; NULL Data Structures Through C / Lecture 8
64 Linked List Yashavant Kanetkar Objectives What are memory leaks What are linked lists How to create a linked list of records Linked List p q r s main( ) struct node int data ; N struct node *link ; ; struct node *p, *q, *r, *s ; malloc ( sizeof ( struct node ) ) ; q = ( struct node * ) malloc ( sizeof ( struct node ) ) ; r = s = p data = 55 ;q data = 6 ;r data = 8 ;s data = 45 p link = q ; q link = r ; r link = s ; s link = NULL ; Cont... Data Structures Through C / Lecture 9
65 ..Cont # include "alloc.h" main( ) t t t printf ( "%d %d %d %d", p data, q data, r data, s data ) ; printf ( "%d %d %d", p data, p link data, p link link data ) ; t = p ; while ( t!= NULL ) printf ( "%d", t data ) ; t = t link ; p q r s N Most General # include "alloc.h" struct node int per ; struct node *link ; ; main( ) struct node *p ; char ch = Y ; int pp, m, m, m ; p = NULL ; while ( ch == Y ) scanf ( "%d %d %d", &m, &m, &m ) ; pp = ( m + m + m ) / ; add ( &p, pp ) ; printf ( "Another student y/n" ) ; ch = getche( ) ; add ( struct node **q, int pp ) struct node *r ; struct node *t ; r = ( struct node * ) malloc ( sizeof ( struct node ) ) ; r -> per = pp ; r -> link = NULL ; if ( *q == NULL ) *q = r ; Empty linked list r else 45 N t = *q ; while ( t -> link!= NULL ) t = t -> link ; *q t -> link = r ; Non-empty linked list *q r N 90 N t t t Data Structures Through C / Lecture 9
66 Variety N N Anil 4 Sunil Anuj N struct node char name[ 0 ] ; int age ; struct node *link ; ; # include "alloc.h" struct node char name [ 0 ] ; int age ; struct node *link ; ; main( ) struct node *p ; struct node t ; char ch = Y ; p = NULL ; while ( ch == Y ) Linked List Of Records printf ( "\nenter name & age: " ) ; scanf ( "%s%d", t.name, &t.age ) ; add ( &p, t ) ; printf ( "Another student Y/N" ) ; ch = getche( ) ; Contd... add ( struct node **q, struct node n ) struct node *r ; struct node *t ; r = ( struct node * ) malloc ( sizeof ( struct node ) ) ; *r = n ; r -> link = NULL ; if ( *q == NULL ) *q = r ; Empty linked list else r t = *q ; Anil 4 N while ( t -> link!= NULL ) t = t -> link ; *q t -> link = r ; Non-empty linked list *q r Anil 4 Sunil N Anuj N t t Data Structures Through C / Lecture 9
67 Operations on Linked List - I Yashavant Kanetkar Objectives How to perform various operations on linked lists How to append a new node to a link list How to add a new node at the beginning of a linked list How to add a new node at a specified position in a linked list How to delete a node from a linked list How to delete all nodes in the list #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *p ; p = NULL ; int c ; append ( &p, 4 ) ; append ( &p, 0 ) ; append ( &p, 5 ) ; append ( &p, 7 ) ; display ( p ) ; LL Operations addatbeg ( &p, 7 ) ; addatbeg ( &p, 58 ) ; display ( p ) ; addafter ( p, 7, 0 ) ; addafter ( p,, ) ; addafter ( p, 5, 99 ) ; display ( p ) ; c = count ( p ) ; printf ( "\nno. of eles. %d", c ) ; del ( &p, 0 ) ; del ( &p, 0 ) ; display ( p ) ; c = count ( p ) ; printf ( "\nno. of eles. %d, c ) ; deleteall ( &p ) ; Data Structures Through C / Lecture 0
68 Append append ( struct node **q, int n ) struct node *r, *t ; r = ( struct node * ) malloc ( sizeof ( struct node ) ) ; r -> data = n ; r -> link = NULL ; Empty List if ( *q == NULL ) *q = r ; *q r else 4 N t = *q ; while ( t -> link!= NULL ) t = t -> link ; t -> link = r ; Non-Empty List *q t t r N 7 N Add At Beginning addatbeg ( struct node **q, int n ) struct node *t ; t = ( struct node * ) malloc ( sizeof ( struct node ) ) ; t -> data = n ; t -> link = *q ; *q = t ; t *q N New node addafter ( struct node *q, int pos, int n ) struct node *t, *r ; q t t int i ; t = q ; for ( i = 0 ; i < pos ; i++ ) if ( t -> link == NULL ) break ; r t = t -> link ; r = ( struct node * ) malloc ( sizeof ( struct node ) ) ; r -> data = n ; r -> link = t -> link ; t -> link = r ; N Data Structures Through C / Lecture 0
69 q N display ( struct node *q ) while ( q!= NULL ) printf ( "%d\t", q->data ) ; q = q -> link ; int count ( struct node *q ) int c = 0 ; while ( q!= NULL ) q = q -> link ; c++ ; return c ; del ( struct node **q, int n ) Node to be Deleted = 4 struct node *t, *prev ; t = *q ; *q t while ( t!= NULL ) if ( t -> data == n ) if ( t == *q ) *q = t -> link ; 4 0 N else prev -> link = t -> link ; Node to be Deleted = free ( t ) ; return ; *q t prev = t ; N t = t -> link ; prev printf ( "\nele. not found." ) ; *q t Delete All Nodes 4 0 N deleteall ( struct node **q ) struct node *t ; while ( *q!= NULL ) t = *q ; *q = ( *q ) -> link ; free ( t ) ; Data Structures Through C / Lecture 0
70 Operations On Linked List II Yashavant Kanetkar Objectives How to arrange the linked list elements in ascending order How to sorting the elements in the linked list #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *p ; int c ; p = NULL ; add ( &p, 5 ) ; add ( &p, ) ; add ( &p, 6 ) ; add ( &p, 4 ) ; add ( &p, 7 ) ; display ( p ) ; c = count ( p ) ; printf ( "\nno. of eles. %d", c ) ; Ascending Order LL Data Structures Through C / Lecture
71 add( ) Function add ( struct node **q, int n ) struct node *r, *t ; t = *q ; r = ( struct node * ) malloc ( sizeof ( struct node ) ) ; r -> data = n ; Empty LL if ( *q == NULL ( *q ) -> data > n ) *q r *q = r ; ( *q ) -> link = t ; 5 N Addition At Beginning New node r *q t Cont New node N Cont *q t 4 6 N else 5 while ( t!= NULL ) r if ( ( t -> data <= n && t -> link -> data > n ) ( t -> data <= n && t -> link == NULL ) ) r -> link = t -> link ; t -> link = r ; return ; t = t -> link ; *q t r 4 5 N 6 N #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *p = NULL ; append ( &p, 7 ) ; append ( &p, 6 ) ; append ( &p, ) ; append ( &p, ) ; append ( &p, ) ; Sorting display ( p ) ; ssort ( p ) ; display ( p ) ; deleteall ( p ) ; Data Structures Through C / Lecture
72 ssort ( struct node *q ) struct node *a, *b ; int n, i, j, t ; a = q ; n = count ( a ) ; for ( i = 0 ; i < n - ; i++ ) b = a -> link ; for ( j = i + ; j < n ; j++ ) if ( a -> data > b -> data ) t = a -> data ; a -> data = b -> data ; b -> data = t ; b = b -> link ; a = a -> link ; q a b 7 6 N Data Structures Through C / Lecture
73 Operations On Linked List - III Yashavant Kanetkar Objectives How to perform various operations on linked lists How to reversing a linked list How to merge two linked lists Reversing LL *q N 7 N 4 5 Data Structures Through C / Lecture
74 #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *p = NULL ; append ( &p, 7 ) ; append ( &p, 4 ) ; append ( &p, ) ; append ( &p, ) ; append ( &p, 5 ) ; Reversing LL display ( p ) ; reverse ( &p ) ; display ( p ) ; deleteall ( p ) ; reverse ( struct node **q ) struct node *r, *prev, *t ; r = *q ; prev = NULL ; while ( r!= NULL ) t = prev ; prev = r ; r = r -> link ; prev -> link = t ; *q = prev ; *q N f Merging LL N s N t N Data Structures Through C / Lecture
75 #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *f, *s, *t ; f = s = t = NULL ; add ( &f, 9 ) ; add ( &f, ) ; add ( &f, 4 ) ; add ( &f, 7 ) ; add ( &f, 79 ) ; printf ( "First LL: " ) ; display ( f ) ; Merging LLs add ( &s, ) ; add ( &s, 7 ) ; add ( &s, 4 ) ; add ( &s, 64 ) ; add ( &s, 87 ) ; printf ( "\nsecond LL: " ) ; display ( s ) ; merge ( f, s, &t ) ; printf ( "\nmerged LL: " ) ; display ( t ) ; deleteall ( f ) ; deleteall ( s ) ; deleteall ( t ) ; merge ( struct node *p, struct node *q, struct node **s ) struct node *z ; Empty List while ( p!= NULL && q!= NULL ) *s z if ( *s == NULL ) z = *s = ( struct node * ) malloc ( else sizeof ( struct node ) ) ; z -> link = ( struct node *) malloc ( sizeof ( struct node ) ) ; z = z -> link ; Non-Empty List z *s 4 if ( p -> data <= q -> data ) z -> data = p -> data ; p = p -> link ; else z -> data = q -> data ; q = q -> link ; // while First List p 9 4 N Third List z 9 Second List q 7 4 N Data Structures Through C / Lecture
76 while ( p!= NULL ) z -> link = ( struct node * ) malloc ( sizeof ( struct node ) ) ; z = z -> link ; z -> data = p -> data ; p = p -> link ; while ( q!= NULL ) z -> link = ( struct node * ) malloc ( sizeof ( struct node ) ) ; z = z -> link ; Third List z -> data = q -> data ; q = q -> link ; z -> link = NULL ; // merge( ) N z Data Structures Through C / Lecture 4
77 Operations On Linked List - IV Yashavant Kanetkar Objectives How to concatenate two linked lists How to perform the addition of polynomials by using linked lists #include "alloc.h" struct node int data ; struct node *link ; ; main( ) struct node *f, *s ; Concatenation Of LL f = s = NULL ; append ( &f, ) ; append ( &f, 4 ) ; append ( &f, ) ; append ( &f, 9 ) ; printf ( "\nfirst LL: " ) ; display ( f ) ; append ( &s, 7 ) ; append ( &s, ) ; append ( &s, ) ; append ( &s, 84 ) ; printf ( "\nsecond LL: " ) ; display ( second ) ; concat ( &f, &s ) ; printf ( "\nconcatenated LL: " ) ; display ( f ) ; deleteall ( f ) ; deleteall ( s ) ; Data Structures Through C / Lecture
Data Structures Through C. Student Workbook
Data Structures Through C Student Workbook Contents Lecture 1: C Revision I 01 Importance of data structures Data types in C Instructions and its types The decision control instruction Working of logical
More informationCourse Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.
Course Name: B.Tech. 3 th Sem. Subject: Data Structures No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours Paper Code: ETCS-209 Topic Details No of Hours Planned
More informationTable of Contents. Chapter 1: Introduction to Data Structures... 1
Table of Contents Chapter 1: Introduction to Data Structures... 1 1.1 Data Types in C++... 2 Integer Types... 2 Character Types... 3 Floating-point Types... 3 Variables Names... 4 1.2 Arrays... 4 Extraction
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))
ASSIGNMENTS Chapter Q. No. Questions Course Outcom e (CO) Progra m Outcom e I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) 2 3. What is the time complexity of the algorithm? 4
More informationDATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305
Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n
More informationDYNAMIC MEMORY ALLOCATION AND DEALLOCATION
COURSE TITLE DATA STRUCTURE DETAILED SYLLABUS SR.NO NAME OF CHAPTERS & DETAILS HOURS ALLOTTED 1 USER DEFINED DATATYPE /STRUCTURE About structure Defining structure Accessing structure element Array of
More informationPROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)
B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2009 EC 2202 DATA STRUCTURES AND OBJECT ORIENTED Time: Three hours PROGRAMMING IN C++ Answer ALL questions Maximum: 100 Marks 1. When do we declare a
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech
More information1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \
BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,
More informationEnd-Term Examination Second Semester [MCA] MAY-JUNE 2006
(Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours
TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART
More informationDC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link
More informationR13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)
SET - 1 II B. Tech I Semester Supplementary Examinations, May/June - 2016 PART A 1. a) Write a procedure for the Tower of Hanoi problem? b) What you mean by enqueue and dequeue operations in a queue? c)
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the
More information1. Attempt any three of the following: 15
(Time: 2½ hours) Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Make suitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written
More informationPreface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS
Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...
More informationAnswers. 1. (A) Attempt any five : 20 Marks
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more
More informationAPJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)
D B3D042 Pages: 2 Reg. No. Name: APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 Max. Marks: 100 CS205: DATA STRUCTURES (CS, IT) PART A Answer all questions.
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE - 1 & 2 Subject Code : CS6202 Subject Name : Programming and Data Structures-I Degree & Branch : B.E C.S.E. 2 MARK
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationPrepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1
QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer
More informationData Structures in C++ Using the Standard Template Library
Data Structures in C++ Using the Standard Template Library Timothy Budd Oregon State University ^ ADDISON-WESLEY An imprint of Addison Wesley Longman, Inc. Reading, Massachusetts Harlow, England Menlo
More informationReg. No. : Question Paper Code : 27157
WK 3 Reg. No. : Question Paper Code : 27157 B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2015. Time : Three hours Second Semester Computer Science and Engineering CS 6202 PROGRAMMING AND DATA STRUCTURES
More informationAlgorithms and programs, basic idea of pseudo-code.algorithm efficiency and analysis, time and space analysis of algorithms order notations.
B. P. Poddar Institute of Management & Technology Department of Information Technology Course Syllabus : Data Structure & Algorithm Academic Year:.18-19... Semester:...3rd... Module -I. [8L] Linear Data
More informationIntroduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis
Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis p. 5 Statement Constructs p. 5 Pseudocode Example p.
More informationGUJARAT TECHNOLOGICAL UNIVERSITY COMPUTER ENGINEERING (07) / INFORMATION TECHNOLOGY (16) / INFORMATION & COMMUNICATION TECHNOLOGY (32) DATA STRUCTURES
GUJARAT TECHNOLOGICAL UNIVERSITY COMPUTER ENGINEERING () / INFMATION TECHNOLOGY (6) / INFMATION & COMMUNICATION TECHNOLOGY (32) DATA STRUCTURES Type of course: Compulsory SUBJECT CODE: 2302 B.E. 3 rd Semester
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationCode No: R Set No. 1
Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationFINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard
FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures
More informationINSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : DATA STRUCTURES Course Code : A30502 Class : II B.
More informationMLR Institute of Technology
MLR Institute of Technology Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad 500 043 Phone Nos: 08418 204066 / 204088, Fax : 08418 204088 TUTORIAL QUESTION BANK Course Name : DATA STRUCTURES Course
More informationBachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24
Prepared By ASCOL CSIT 2070 Batch Institute of Science and Technology 2065 Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass
More informationData Structures Question Bank Multiple Choice
Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution
More informationCS301 - Data Structures Glossary By
CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK III SEMESTER CS8391-Data Structures Regulation 2017 Academic Year 2018 19(odd Semester)
More informationDATA STRUCTURES THROUGH C++
II Year I Semester DATA STRUCTURES THROUGH C++ L T P C 4 0 0 3 OBJECTIVES: To be familiar with basic techniques of object oriented principles and exception handling using C++ To be familiar with the concepts
More informationCOSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)
COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back
More informationS.E. (Computer) (First Semester) EXAMINATION, 2011 DATA STRUCTURES AND ALGORITHM (2008 PATTERN) Time : Three Hours Maximum Marks : 100
Total No. of Questions 12] [Total No. of Printed Pages 7 [4062]-204 S.E. (Computer) (First Semester) EXAMINATION, 2011 DATA STRUCTURES AND ALGORITHM (2008 PATTERN) Time : Three Hours Maximum Marks : 100
More informationE.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.
17CA 104DATA STRUCTURES Academic Year : 018-019 Programme : MCA Year / Semester : I / I Question Bank Course Coordinator: Mrs. C.Mallika Course Objectives The student should be able to 1. To understand
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may
More informationSAURASHTRA UNIVERSITY
SAURASHTRA UNIVERSITY RAJKOT INDIA Accredited Grade A by NAAC (CGPA 3.05) CURRICULAM FOR B.Sc. (Computer Science) Bachelor of Science (Computer Science) (Semester - 1 Semester - 2) Effective From June
More informationMID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.
MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
Code No: R21051 R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS UNIT 1 - LINEAR DATASTRUCTURES 1. Write down the definition of data structures? A data structure is a mathematical or logical way of organizing data in the memory that consider
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE
TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)
More informationDepartment of Computer Science and Technology
UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the
More informationDS ata Structures Aptitude
DS ata Structures Aptitude 1. What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge
More informationCourse goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance
Course goals exposure to another language C++ Object-oriented principles knowledge of specific data structures lists, stacks & queues, priority queues, dynamic dictionaries, graphs impact of DS design
More informationQUESTION BANK. Prepared by,mrs.d.maladhy AP/IT,RGCET. Page 1
UNIT I 1.Write statements to declare integer Pointer and Float Pointer. Also write the statement to convert float pointer.(apr/may 2016) 2. What is a Stack? Mention the order followed to add or delete
More informationVALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 0 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK III SEMESTER CS89- DATA STRUCTURES Regulation 07 Academic Year 08 9 Prepared by
More informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
More informationBRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam
BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE CSI33 Sample Final Exam NAME Directions: Solve problems 1 through 5 of Part I and choose 5 of the
More informationSyllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE0301. Subject Name: Data Structure. B.Tech. Year - II
Subject Code: 01CE0301 Subject Name: Data Structure B.Tech. Year - II Objective: Data structure has high importance in the field of Computer & IT. Organization of data is crucial for implementation and
More informationTypes of Data Structures
DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data
More information17CS33:Data Structures Using C QUESTION BANK
17CS33:Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C Learn : Usage of structures, unions - a conventional tool for handling a group of logically
More informationCS8391-DATA STRUCTURES QUESTION BANK UNIT I
CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those
More informationComputer Science E-22 Practice Final Exam
name Computer Science E-22 This exam consists of three parts. Part I has 10 multiple-choice questions that you must complete. Part II consists of 4 multi-part problems, of which you must complete 3, and
More informationCLASSIC DATA STRUCTURES IN JAVA
CLASSIC DATA STRUCTURES IN JAVA Timothy Budd Oregon State University Boston San Francisco New York London Toronto Sydney Tokyo Singapore Madrid Mexico City Munich Paris Cape Town Hong Kong Montreal CONTENTS
More informationPESIT Bangalore South Campus Department of MCA Course Information for
1. GENERAL INFORMATION: PESIT Bangalore South Campus Department of MCA Course Information for Data Structures Using C(13MCA21) Academic Year: 2015 Semester: II Title Code Duration (hrs) Lectures 48 Hrs
More informationLECTURE NOTES ON DATA STRUCTURES USING C
LECTURE NOTES ON DATA STRUCTURES USING C Revision 4.0 1 December, 2014 L. V. NARASIMHA PRASAD Professor Department of Computer Science and Engineering E. KRISHNA RAO PATRO Associate Professor Department
More informationDiscuss the following operations on One-Dimensional array with algorithms.
(i). Searching (ii). Sorting (iii). Traversing (16CS503) DATA STRUCTURES THROUGH C UNIT-I Discuss the following operations on One-Dimensional array with algorithms. 2.Discuss the following operations on
More informationDarshan Institute of Engineering & Technology for Diploma studies Unit 4
Pointer A pointer is a variable that contains address or location of another variable. Pointer is a derived data type in C. Pointers contain memory address as their values, so they can also be used to
More informationS.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C
S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 (a) Attempt any SIX of the following : [12] Q.1 (a) (i) Define time complexity
More informationCSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid
CSCE 20/220 Data Structures and Algorithms Prof. Amr Goneid Fall 208 / Spring 209 CSCE 20/220 DATA STRUCTURES AND ALGORITHMS Prof. Amr Goneid Instructor: Prof. Amr Goneid E-mail: goneid@aucegypt.edu Office:
More informationWhat is recursion. WAP to find sum of n natural numbers using recursion (5)
DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.
More informationa) State the need of data structure. Write the operations performed using data structures.
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationCS 445: Data Structures Final Examination: Study Guide
CS 445: Data Structures Final Examination: Study Guide Java prerequisites Classes, objects, and references Access modifiers Arguments and parameters Garbage collection Self-test questions: Appendix C Designing
More informationTotal No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC First Semester CSE/IT DATA STRUCTURES USING C
CSE/IT 216 (CR) Total No. of Questions :09] [Total No. of Pages : 02 Time: Three Hours 1. a. ADT II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC- 2015 First Semester CSE/IT DATA STRUCTURES USING C Answer Question
More informationS.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear
S.E. Sem. III [INFT] Data Structures & Analysis Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data
More informationDC54 DATA STRUCTURES DEC 2014
Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as
More informationCSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018
CSCE 20/220 Data Structures and Algorithms Prof. Amr Goneid Fall 208 CSCE 20/220 DATA STRUCTURES AND ALGORITHMS Dr. Amr Goneid Course Goals To introduce concepts of Data Models, Data Abstraction and ADTs
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given
More informationS.Y. B.Sc. (IT) : Sem. III. Data Structures
S.Y. B.Sc. (IT) : Sem. III Data Structures Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1Attempt the following (any THREE) [15] Q.1(a) What is an algorithm? Write down characteristics of
More informationCS8391-DATA STRUCTURES
ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined
More informationData Structures and Algorithm Analysis in C++
INTERNATIONAL EDITION Data Structures and Algorithm Analysis in C++ FOURTH EDITION Mark A. Weiss Data Structures and Algorithm Analysis in C++, International Edition Table of Contents Cover Title Contents
More informationVisit ::: Original Website For Placement Papers. ::: Data Structure
Data Structure 1. What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship
More informationCP2 Revision. theme: dynamic datatypes & data structures
CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;
More information1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?
Review for Final (Chapter 6 13, 15) 6. Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B. To
More informationAryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9
Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths
More informationDraw a diagram of an empty circular queue and describe it to the reader.
1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 1
Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:
More informationMultiple Choice. Write your answer to the LEFT of each problem. 3 points each
CSE 0-00 Test Spring 0 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose f ( x) is a monotonically increasing function. Which of the
More informationSymbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management
Hashing Symbol Table Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management In general, the following operations are performed on
More informationCS 8391 DATA STRUCTURES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as
More information( ) 1 B. 1. Suppose f x
CSE Name Test Spring Last Digits of Student ID Multiple Choice. Write your answer to the LEFT of each problem. points each is a monotonically increasing function. Which of the following approximates the
More informationVALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK
VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK Degree & Branch : B.E E.C.E. Year & Semester : II / IV Section : ECE 1, 2 &
More informationCS DATA STRUCTURES AND ALGORITHMS
Computer Science and Engineering Third Semester CS1211 - DATA STRUCTURES AND ALGORITHMS UNIT-I - INTRODUCTION TO DATASTRUCTURES 1.Write down the definition of data structures? PART -A A data structure
More informationA. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS
Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization
More informationDEPARTMENT OF COMPUTER APPLICATIONS B.C.A. - FIRST YEAR ( REGULATION) SECOND SEMESTER LESSON PLAN SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
DEPARTMENT OF COMPUTER APPLICATIONS B.C.A. - FIRST YEAR (2015-2016 REGULATION) SECOND SEMESTER LESSON PLAN SRM INSTITUTE OF SCIENCE AND TECHNOLOGY FACULTY OF SCIENCE AND HUMANITIES SRM NAGAR, KATTANKULATHUR
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationAlgorithms & Data Structures
GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key
More information& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n
CSE Name Test Summer Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n " n matrices is: A. " n C. "% n B. " max( m,n, p). The
More informationDelhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:
Serial : 1PT_CS_A+C_Programming & Data Structure_230918 Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: E-mail: info@madeeasy.in Ph: 011-45124612 CLASS TEST 2018-19
More informationTribhuvan University Institute of Science and Technology Computer Science and Information Technology (CSC. 154) Section A Attempt any Two questions:
Tribhuvan University 2065 Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSC. 154) Pass Marks: 24 (Data Structure and Algorithm) Time:
More information