17 views

Uploaded by Stephanie Johnson

- IGNOU MCA 1st Semster HTML Lab Record Solved MCSL 016
- mcs notes
- IGNOU MCA MCS-035 Free Solved Assignments 2010
- MCS-022(22)
- C in 7 days
- Buffering & Spooling
- MCS-015
- IGNOU MCA MCS-21 Solved Assignments 2011
- Cover Page [MCS-044]
- IGNOU MCA 2nd Semster Data Structure Lab Record Solved MCSL 025
- mcs-035
- MCS-014 Unit 1 - Introduction to SAD (System Analysis and Design)
- DS With C C++ Lab Manual VTU
- MCS-015
- MCS25
- IGNOU MCA MCS-015 Solved Assignment 2010
- 89 Jsp Interview Questions 1
- 3 MBA E-Business
- Data Stuctures Lab Manual
- MCS-015

You are on page 1of 14

http://ignoujaipur.blogspot.in/ Course Code : MCS-021 Course Title : Data and File Structures Assignment Number : MCA(2)/021/Assign/12 Question 1: Write an algorithm for multiplication of two sparse matrices using Linked Lists Solution #include<stdio.h> #include<conio.h> #include<alloc.h> #define MAX1 3 #define MAX2 3 #define MAXSIZE 20 #define TRUE 1 #define FALSE 2 struct sparse { int *sp ; int row ; int *result ; }; void initsparse ( struct sparse * ) ; void create_array ( struct sparse * ) ; int count ( struct sparse ) ;

http://ignoujaipur.blogspot.in/ void display ( struct sparse ) ; void create_tuple ( struct sparse*, struct sparse ) ; void display_tuple ( struct sparse ) ; void prodmat ( struct sparse *, struct sparse, struct sparse ) ; void searchina ( int *sp, int ii, int*p, int*flag ) ; void searchinb ( int *sp, int jj, int colofa, int*p, int*flag ) ; void display_result ( struct sparse ) ; void delsparse ( struct sparse * ) ; void main( ) { struct sparse s[5] ; int i ; clrscr( ) ; for ( i = 0 ; i<= 3 ; i++ ) initsparse ( &s[i] ) ; create_array ( &s[0] ) ; create_tuple ( &s[1], s[0] ) ; display_tuple ( s[1] ) ; create_array ( &s[2] ) ; create_tuple ( &s[3], s[2] ) ; display_tuple ( s[3] ) ; prodmat ( &s[4], s[1], s[3] ) ; printf ( "\nResult of multiplication of two matrices: " ) ;

http://ignoujaipur.blogspot.in/ display_result ( s[4] ) ; for ( i = 0 ; i<= 3 ; i++ ) delsparse ( &s[i] ) ; getch( ) ; } /* initialises elements of structure */ void initsparse ( struct sparse *p ) { p -> sp = NULL ; p -> result = NULL ; } /* dynamically creates the matrix */ void create_array ( struct sparse *p ) { int n, i ; /* allocate memory */ p -> sp = ( int * ) malloc ( MAX1 * MAX2 * sizeof ( int ) ) ; /* add elements to the array */ for ( i = 0 ; i< MAX1 * MAX2 ; i++ ) { printf ( "Enter element no. %d: ", i ) ; scanf ( "%d", &n ) ; * ( p -> sp + i ) = n ;

http://ignoujaipur.blogspot.in/ } } /* displays the contents of the matrix */ void display ( struct sparse s ) { int i ; /* traverses the entire matrix */ for ( i = 0 ; i< MAX1 * MAX2 ; i++ ) { /* positions the cursor to the new line for every new row */ if ( i % 3 == 0 ) printf ( "\n" ) ; printf ( "%d\t", * ( s.sp + i ) ) ; } } /* counts the number of non-zero elements */ int count ( struct sparse s ) { int cnt = 0, i ; for ( i = 0 ; i< MAX1 * MAX2 ; i++ ) { if ( * ( s.sp + i ) != 0 ) cnt++ ;

http://ignoujaipur.blogspot.in/ } return cnt ; } /* creates an array that stores information about non-zero elements */ void create_tuple ( struct sparse *p, struct sparse s ) { int r = 0 , c = -1, l = -1, i ; /* get the total number of non-zero elements */ p -> row = count ( s ) + 1 ; /* allocate memory */ p -> sp = ( int * ) malloc ( p -> row * 3 * sizeof ( int ) ) ; /* store information about total no. of rows, cols, and non-zero values */ * ( p -> sp + 0 ) = MAX1 ; * ( p -> sp + 1 ) = MAX2 ; * ( p -> sp + 2 ) = p -> row - 1 ; l=2; /* scan the array and store info. about non-zero values in the 3-tuple */ for ( i = 0 ; i< MAX1 * MAX2 ; i++ ) { c++ ; /* sets the row and column values */ if ( ( ( i % 3 ) == 0 ) && ( i != 0 ) ) {

http://ignoujaipur.blogspot.in/ r++ ; c=0; } /* checks for non-zero element, row, column and non-zero value is assigned to the matrix */ if ( * ( s.sp + i ) != 0 ) { l++ ; * ( p -> sp + l ) = r ; l++ ; * ( p -> sp + l ) = c ; l++ ; * ( p -> sp + l ) = * ( s.sp + i ) ; } } } /* displays the contents of the matrix */ void display_tuple ( struct sparse s ) { int i, j ; /* traverses the entire matrix */ printf ( "\nElements in a 3-tuple: " ) ; j = ( * ( s.sp + 2 ) * 3 ) + 3 ; for ( i = 0 ; i< j ; i++ )

http://ignoujaipur.blogspot.in/ { /* positions the cursor to the new line for every new row */ if ( i % 3 == 0 ) printf ( "\n" ) ; printf ( "%d\t", * ( s.sp + i ) ) ; } printf ( "\n" ) ; } /* performs multiplication of sparse matrices */ void prodmat ( struct sparse *p, struct sparse a, struct sparse b ) { int sum, k, position, posi, flaga, flagb, i , j ; k=1; p -> result = ( int * ) malloc ( MAXSIZE * 3 * sizeof ( int ) ) ; for ( i = 0 ; i< * ( a.sp + 0 * 3 + 0 ) ; i++ ) { for ( j = 0 ; j< * ( b.sp + 0 * 3 + 1 ) ; j++ ) { /* search if an element present at ith row */ searchina ( a.sp, i, &position, &flaga ) ; if ( flaga == TRUE ) { sum = 0 ;

http://ignoujaipur.blogspot.in/ /* run loop till there are element at ith row in first 3-tuple */ while ( * ( a.sp + position * 3 + 0 ) == i ) { /* search if an element present at ith col. in second 3-tuple */ searchinb ( b.sp, j, * ( a.sp + position * 3 + 1 ), &posi, &flagb ) ; /* if found then multiply */ if ( flagb == TRUE ) sum = sum + * ( a.sp + position * 3 + 2 ) * * ( b.sp + posi * 3 + 2 ) ; position = position + 1 ; } /* add result */ if ( sum != 0 ) { * ( p -> result + k * 3 + 0 ) = i ; * ( p -> result + k * 3 + 1 ) = j ; * ( p -> result + k * 3 + 2 ) = sum ; k=k+1; } } } } /* add total no. of rows, cols and non-zero values */ * ( p -> result + 0 * 3 + 0 ) = * ( a.sp + 0 * 3 + 0 ) ;

http://ignoujaipur.blogspot.in/ * ( p -> result + 0 * 3 + 1 ) = * ( b.sp + 0 * 3 + 1 ) ; * ( p -> result + 0 * 3 + 2 ) = k - 1 ; } /* searches if an element present at iith row */ void searchina ( int *sp, int ii, int *p, int *flag ) { int j ; *flag = FALSE ; for ( j = 1 ; j<= * ( sp + 0 * 3 + 2 ) ; j++ ) { if ( * ( sp + j * 3 + 0 ) == ii ) { *p = j ; *flag = TRUE ; return ; } } } /* searches if an element where col. of first 3-tuple is equal to row of second 3-tuple */ void searchinb ( int *sp, int jj, int colofa, int *p, int *flag ) { int j ; *flag = FALSE ;

http://ignoujaipur.blogspot.in/ for ( j = 1 ; j<= * ( sp + 0 * 3 + 2 ) ; j++ ) { if ( * ( sp + j * 3 + 1 ) == jj && * ( sp + j * 3 + 0 ) == colofa ) { *p = j ; *flag = TRUE ; return ; } } } /* displays the contents of the matrix */ void display_result ( struct sparse s ) { int i ; /* traverses the entire matrix */ for ( i = 0 ; i< ( * ( s.result + 0 + 2 ) + 1 ) * 3 ; i++ ) { /* positions the cursor to the new line for every new row */ if ( i % 3 == 0 ) printf ( "\n" ) ; printf ( "%d\t", * ( s.result + i ) ) ; } }

http://ignoujaipur.blogspot.in/ /* deallocates memory */ void delsparse ( struct sparse *s ) { if ( s -> sp != NULL ) free ( s -> sp ) ; if ( s -> result != NULL ) free ( s -> result ) ; } Question 2: Implement multiple stacks in a single dimensional array. Write algorithms for various stack operations for them. Solution Hint : to implement two stacks in a single array consider two stacks growing towards each other and take tos1=-1 andtos2=max as empty condition and for full condition take tos1=tos2-1 and to insert take push1 tos1++ and for push2 tos Question 3: Write a note of not more than 5 pages summarizing the latest research in the area of Shortest Path Algorithms for graphs. Refer to various journals and other online resources. Solution: Research By microsoft

http://ignoujaipur.blogspot.in/ SPA Shortest path problems are among the most fundamental optimization problems with many applications. The project is devoted to theoretical and experimental study of algorithms for the shortest path and related problems, including single-source, feasibility, minimum mean cycle, and point-to-point shortest paths.

Overview The problem of finding shortest paths in graphs is a fundamental optimization problem with many applications. The problem has several variants. Algorithms with near-optimal efficiency, either in theory or in practice, are known for some problem variants, such as the single-source problem. For other variants, significant improvement over the current state of the art may be possible.

A significant effort of the SPA project is devoted to the following variant of the shortest path problem. Given a graph, we preprocess it subject to the restriction that the space for the preprocessing results is limited (e.g., a small constant times the space used to store the graph). Then we would like to quickly answer queries on single-pair shortest paths. This is a natural variant of the problem as in many applications, such as that of computing driving directions (e.g., Google Maps, Yahoo! Maps, Bing Maps).

We developed several techniques for speeding up classical algorithms for the problem. These include landmark-based A* search, reach-based pruning, and their combinations. The resulting algorithms are very practical and can be used on servers, desktops, or portable devices (e.g., car navigation systems). Some of these algorithms are being used by Bing Maps. With Hub Labels, we have the fastest known point-to-point shortest path queries on road networks.

More recently, within our Customizable Route Planning project, we have been looking at even more flexible approaches, which allow for real-time traffic updates, blocked roads, personalized (customized) driving directions, reasonable alternative paths, and many other features. To achieve this, we use our own state-of-the-art graph partitioning algorithm, PUNCH.

http://ignoujaipur.blogspot.in/ Other problems we have studied include shortest path feasibility, minimum cycle mean problems, and hardware-accelerated shortest path trees (PHAST), using both multicore and GPUs. Our research lead to better understanding the practical performance of existing algorithms and the development of new algorithms with good practical performance.

Additional details about our results can be found in project publications. Related Resources Links http://goo.gl/D8AJO http://goo.gl/GND4c Question 4: What are the applications of Red-Black Trees. Solution: A red-black tree is a particular implementation of a self-balancing binary search tree, and today it seems to be the most popular choice of implementation.

Binary search trees are used to implement finite maps, where you store a set of keys with associated values. You can also implement sets by only using the keys and not storing any values.

Balancing the tree is needed to guarantee good performance, as otherwise the tree could degenerate into a list, for example if you insert keys which are already sorted.

The advantage of search trees over hash tables is that you can traverse the tree efficiently in sort order.

AVL-trees are another variant of balanced binary search trees. They where popular before red-black trees where known. They are more carefully balanced, with a maximal difference of one between the heights of the left and right subtree (RB trees guarantee at most a factor of two). Their main drawback is that rebalancing takes more effort.

http://ignoujaipur.blogspot.in/

So red-black trees are certainly a good but not the only choice for this application.

Note: We are not the Copyright Owner of these solutions, we found some solution from the web, This Assignment is

- IGNOU MCA 1st Semster HTML Lab Record Solved MCSL 016Uploaded byfajer007
- mcs notesUploaded byNayan Malde
- IGNOU MCA MCS-035 Free Solved Assignments 2010Uploaded byDeepti Saini
- MCS-022(22)Uploaded bykktamang09
- C in 7 daysUploaded byvksgyt
- Buffering & SpoolingUploaded byPrasad Shitole
- MCS-015Uploaded bySunny Gupta
- IGNOU MCA MCS-21 Solved Assignments 2011Uploaded bySyedkareem_hkg
- Cover Page [MCS-044]Uploaded byAvinash Dubey
- IGNOU MCA 2nd Semster Data Structure Lab Record Solved MCSL 025Uploaded byfajer007
- mcs-035Uploaded byAshutosh Ranjan
- MCS-014 Unit 1 - Introduction to SAD (System Analysis and Design)Uploaded bydhabalia_kirit
- DS With C C++ Lab Manual VTUUploaded byManohar NV
- MCS-015Uploaded bySunnyVerma
- MCS25Uploaded byapi-3703813
- IGNOU MCA MCS-015 Solved Assignment 2010Uploaded byAmithabh Soman
- 89 Jsp Interview Questions 1Uploaded byPriyaabhashini Devarajan
- 3 MBA E-BusinessUploaded byKapil Sen
- Data Stuctures Lab ManualUploaded bykarthimuthu
- MCS-015Uploaded byRosy Mathew
- Tally Practical QuestionUploaded byBarani Dharan
- 34482554 IGNOU MCA 2nd Semster DBMS Lab Record Solved MCSL 025 14Uploaded bySumanta Das
- programmingUploaded bypelangibiru14
- 3D Path Planning for Autonomous Aerial Vehicles in Constrained SpacesUploaded bynmyagaa
- C LanguageUploaded byoopsanuj
- EX2CPPUploaded byBacalaureat Iorga
- Raport 5Uploaded byIon
- Data StructureUploaded byPKSachan
- acbUploaded byĐể Mai Tính
- Technical Aptitude Questions eBookUploaded bypratishkhedekar

- IEEE projects 2012 MATLABUploaded bytemasolution
- Comparison and Analysis of Channel Estimation Algorithms in Ofdm SystemsUploaded byYannick Roswilo
- 00601654Uploaded bySidik Harijadi
- 1-s2.0-S0957417411016393-mainUploaded bylge_eng
- syllabus-1Uploaded byZijian Huang
- Telecom OpticUploaded byasif ali
- z TransformationUploaded bySaimir Lleshi
- Full Report Exp 10Uploaded byRenu Sekaran
- S8 RESULTSUploaded bykannan.ur
- A New Multi-criteria Scenario-based Solution ApproachUploaded byCarlos Cervantes
- Solving the Optimal Trading Trajectory Problem Using a Quantum AnnealerUploaded byRoss80
- Computer CodesUploaded byAbdul Hameed
- A2 1st Sem Exam Review 2011Uploaded byklb925
- צפינה- מצגת 5 | BCH CodesUploaded byRon
- 245057Uploaded bymari_eu
- A Simple Refutation of Special RelativityUploaded byConexão Terra Plana
- DIFFERENTIAL QUADRATURE SOLUTIONS OF THE GENERALIZED BURGERS–FISHER EQUATION WITH A STRONG STABILITY PRESERVING HIGH-ORDER TIME INTEGRATIONUploaded byHamid Mojiry
- A Simple Laplace Transform is Conducted While Sending Signals Over Any TwoUploaded byhamry
- Accurate Information Extraction From Research Papers Using Conditional Random FieldsUploaded byJason Brown
- On the Complexity of Sphere DecodingUploaded byapi-3851401
- Optimisation ProblemsUploaded bylarasmoyo
- DSP Important Questions Unit-WiseUploaded byRasool Reddy
- Intrusion Detection System by using SVM and Ant ColonyUploaded byEditor IJRITCC
- Securing Mechanism of Healthcare Data on CloudUploaded byEditor IJTSRD
- Identification Problem of Source Term of a Reaction Diffusion EquationUploaded byEditor IJACSA
- Document.docxUploaded byuthayakumar j
- Artificial Intelligence - WikipediaUploaded bySanjaya Kumar Panda
- Image Processing Pattern Recognition Fundamentals 0470404612Uploaded byHadeelAl-hamaam
- hashsUploaded byAadithya Sujit
- Nonlinear Predictive Control of a Benchmark CstrUploaded byYuri Zopelario Mareli