0 Up votes0 Down votes

9 views5 pagestest

Nov 14, 2013

© Attribution Non-Commercial (BY-NC)

PDF, TXT or read online from Scribd

test

Attribution Non-Commercial (BY-NC)

9 views

test

Attribution Non-Commercial (BY-NC)

- Steve Jobs
- The Woman Who Smashed Codes: A True Story of Love, Spies, and the Unlikely Heroine who Outwitted America's Enemies
- NIV, Holy Bible, eBook
- NIV, Holy Bible, eBook, Red Letter Edition
- Cryptonomicon
- Hidden Figures Young Readers' Edition
- Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are
- Make Your Mind Up: My Guide to Finding Your Own Style, Life, and Motavation!
- Console Wars: Sega, Nintendo, and the Battle that Defined a Generation
- The Golden Notebook: A Novel
- Alibaba: The House That Jack Ma Built
- Life After Google: The Fall of Big Data and the Rise of the Blockchain Economy
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- The 10X Rule: The Only Difference Between Success and Failure
- Autonomous: A Novel

You are on page 1of 5

Department of Computer Science & Engineering Programming and Data Structures (CS11001) Endsem (Autumn, 1st Year) Date: Tue, Nov 22, 2011 Students: 660 Time: 09:00-12:00pm Marks: 80

Answer ALL the questions. Write you name and roll number on ALL sheets. Do all rough work on separate rough sheets which you should NOT submit. Answer neatly, without overwriting on the question paper itself in the spaces provided.

Roll no:

Section:

Name:

1. Complete the following function which takes as input a given positive integer (representing a sum of money) and prints the number of currency notes of denominations 1, 10 and 50 required to pay that amount, so that the number of currency notes is minimised. Eg: 320650+210; 475950+210+51

void printPayment ( int n1, n10, n50; n50 = N/50 N = N - 50 * n50 n10 = N/10 n1 = N - 10 * n10 printf("Number of notes of 1, 10 and 50 denominations are: printf("%d, %d and %d\n", n1, n10, n50 } int N ) { 1

; ; ; ; "); );

1 1 1 1

2. A rabbit has found itself in a maze of tunnels connecting underground pits. Initially, each tunnel has one carrot in it and each pit has two or four tunnels connecting it to other pits. The rabbit intends to start at a pit, eat some of the carrots in the tunnels and denitely return to the starting pit. It can do so if: (i) it enters a tunnel only if there is a carrot there (assume there is some light to see), (ii) eat that carrot and (iii) go to the pit at the other end of the tunnel. Eventually, it will be at a pit from where there is no tunnel with a carrot in there. That pit is bound to be the starting pit! Let there be N pits numbered 0..(N 1)and M tunnels numbered 0..(M 1). Information on the pits and tunnels are represented as described below; ll in the missing parts. Information on the M tunnels is stored in an array tunTyp tunnel[M], where tunTyp is dened as:

typedef { int p1, p2; // index values of pits it connects int carrotCount; // initialised to } tunTyp; typedef { int tunnelCount; /* set to int tunVec[ } pitTyp;

1 2 3 4 5 6 T

(1:

carrot present, 0:

absent)

Information on the N pits is stored in an array pitTyp pit[N], where pitTyp is dened as:

or

, depending on connectivity */

1 1

]; /* vector of index values of maximum number tunnels to which this pit is connected */

1 of 5 pages

PDS (CS11001)

Roll:

Sec:

Now, complete the function that prints a possible round tour (returning to the starting point) of some of the pits and tunnels by the rabbit, starting at the pit with index of 0.

void printPitTunTour (int M, tunTyp tunnel[M], int N, pitTyp pit[N]) { int nTun_forPit, tunVecIdx, tunIdx, otherPitIdx, carrotsEaten=0, pitIdx=0; repeat { // keep looping, until the tour ends // check if there is a tunnel with a carrot... // first find out how many tunnels are there with this pit nTun_forPit = pit[pitIdx].tunnelCount // next, search for a tunnel with a carrot among tunnels in tunVec ; 1

for (tunVecIdx= 0 ; tunVecIdx< nTun_forPit ; tunVecIdx++) { // ...get the index of the tunnel to check for a carrot in tunIdx tunIdx = pit[pitIdx].tunVec[tunVecIdx] // ...check if this tunnel has a carrot if ( tunnel[tunIdx].carrotCount ;

1 1

otherPitIdx = tunnel[tunIdx].p1 + tunnel[tunIdx].p2 - pitIdx ; // carrot eaten, ...tour must continue from pit with index of otherPitIdx // first, display the move... printf("eating carrot and going from pit %d to pit %d\n", pitIdx, otherPitIdx // next, prepare to carry on from the new pit... pitIdx = otherPitIdx // dont forget to keep count of carrots eaten... carrotsEaten++ // finally, ...carry on! ); 2

break; ; } // end-if } // end-for } // check if the search done above for a tunnel with a carrot did fail... until ( tunVecIdx >= nTun_forPit ); // tour over! carrotsEaten , M );

1 2

The running time of the above function in the big-O notation is:

O(M ) OR O(N 2 )

2 of 5 pages

PDS (CS11001)

Roll:

Sec:

3. You are given a linked list of integers which are in ascending order. However, there may be duplicates, which should be removed. Complete the following piece of C code fragment that removes the duplicates and returns headP=n1P n2P headP n1P the number of distinct elements in the list. Eg: 1 1 n2P 1 3 3 2 2 2

typedef struct llNodeTag int val; // value stored in node struct llNodeTag { // ...via struct for linked list of ints

int removeDuplicates (llNodePtr headP) { int elemCount=0; // needs to be incremented when a new value is seen llNodePtr n1P, n2P; n1P = headP; if (n1P != NULL) { // list is not empty // n2P is initialised to point to the successor of n1P n2P = n1P->nextP elemCount++ } else return 0; // keep looping to find duplicates while ( // test for a duplicate n2P ! = NULL ) { ; ; 1 1 1

if (n1P->val == n2P->val // steps to remove the duplicate at n2P n1P->nextP = n2P->nextP free(n2P) n2P = n1P->nextP } else { // advance in the list n1P = n2P n2P n1P->nextP elemCount++ } } return elemCount }

) { // duplicate found

; ; ;

1 1 1

; ; ;

1 1 1

; // final step

4. Write a function charCount() to count the characters, corresponding only to the letters of the English alphabet, occurring in a NUL terminated string char s[] ignoring the case (upper or lower) of the letters. The count is to be maintained in an array counts[] of 26 integers corresponding to each letter of the alphabet. CM, PM, PSD Endsem, Autumn, 2011 3 of 5 pages

PDS (CS11001)

Roll:

Sec:

// the supplied string of characters is s[] // letter counts are maintained and returned via counts[] void charCount(char s[], int counts[]) { int i; // next, initialisations of locations in count[] for (i=0; i<26; i++) counts[i] = 0; for ( i=0;i<n;i++ ) { 2 2 2 2 2

if (a<=s[i] && s[i]<=z) count[s[i]-a] += 1; if (A<=s[i] && s[i]<=Z) count[s[i]-A] += 1; if (s[i] == \0) return; } }

5. A test for divisibility by 7 is stated as follows: Take the two left-most digits, multiply the left digit by 3 and add it to the second digit. Replace these two digits with the result. Then we can keep repeating, always dealing with only the two left-most digits, until we end up with a single digit number which is either divisible by 7 (if digit is 0 or 7) or not. Eg: 249 109 39 18 11 4 (not divisible by 7); 49 21 7 (divisible by 7). For the above divisibility test by 7, assume that a k digit number N (most signicant digit, Nk1 is non-zero) is available in the array int N[K]={Nk1 ,...,N1 , N0 }, suitably initialised with the digits of the number. Consider a function int isDiv7(int k, int N[]) to test divisibility by 7 of the k digit number whose digits are stored in the array N[k]. Giving single lines of C code (comparisons, assignments, etc), describe each of the following tests and actions for the Base and Inductive/recursive cases, in terms of k and entries in the array N[], C code fragments to support the case analysis of isDiv7(k, N): Base case N is a single digit number not divisible by 7 Condition code (CB1): k==1 && N[0]!=0 && N[0]!=7 Action code (AB1): return 0; // number is not divisible Base case N is a single digit number divisible by 7 Condition (CB2): k==1 && (N[0]==0 || N[0]==7) Action (AB2): return 1; // number is divisible Inductive/recursive case N is multi-digit and needs to be reduced (including the action if Nk1 becomes 0) Condition code (CI1): Action code (AI1a): Action code (AI1b): Action code (AI1c): Action code (AI1d): Action code (AI1e): CM, PM, PSD

k>1 t = 3*N[k-1] + N[k-2] N[k-2] = t % 10 N[k-1] = (t-N[k-2])/10; if ( N[k-1]==0 ) k=k-1 ; return isDiv7(k, N)

1 1 1 1 1 1 4 of 5 pages

PDS (CS11001)

Roll:

Sec:

Based on the above condition tests (CB1, CB2, CI1) and actions (AB1, AB2, AI1a, ... , AI1e) develop isDiv7(k, N) as a recursive routine. Instead of rewriting code, develop the routine in terms of the code aliases (short names for the code fragments): CB1, CB2, CI1, AB1, AB2, etc.

isDiv7(int k, int N[]) { int t; // declarations if ( if ( if ( } CB1 CB2 CI1 ) AB1; ) AB2; ) { AI1a; ... ; AI1e } 2 2 2

Now develop isDiv7(k, N) as an iterative routine. Instead of rewriting code, develop the routine in terms of the code aliases (short names for the code fragments): CB1, CB2, CI1, AB1, AB2, etc.

isDiv7(int k, int N[]) { int t; // declarations while(1) if (CI1) { AI1a; ... else break; } // end of the loop if (CB1) AB1; if (CB2) AB2; ; AI1d; } { // start the loop 1 2 1

2 2

6.

(a) The function call to open a text le data.txt for reading is:

fopen(data.txt, "r")

(b) The function call to open a text le data.txt for writing is:

fopen(data.txt, "w")

(c) The function call to open a text le data.txt in the directory dataDir under the current working directory, for appending is:

fopen(dataDir/data.txt, "a")

1 1

(d) When the function call to open a le fails, the return value of the function is: NULL (e) The function call to check whether the end of an open le FILE *fileP has been reached is:

feof(fileP)

5 of 5 pages

- lecture about c programmingUploaded byShohagh Shosagh
- Computer Science Manual for 2nd PUC, Karnataka boardUploaded bySalmaMubarakJ
- lec2Uploaded byKearrake Kuran
- awedia1571266655614Uploaded byGrant Herrix
- p60 0x07 Burning the Bridge Cisco IOS Exploits by FXUploaded byabuadzkasalafy
- orca_share_media157awdaw655614Uploaded byGrant Herrix
- C_for_M_Chapter_5E (1)Uploaded byAlex Barutis
- polyKKUploaded bySumeet Rayat
- c Structures RevisitedUploaded byLalithaMani
- Linked List BasicsUploaded bynidadavole534301
- 74_BD_Data Structures and Algorithms - Narasimha KarumanchiUploaded byTritonCPC
- Data StructureUploaded byAryan Verma
- syntelUploaded bypriyaaapalanisamy
- Comp 01Uploaded byMumraza
- CS1202 UNIX & C Programming SyUploaded byHIM1378
- Additional Notes on FunctionsUploaded byAnonymous IhmXvCHj3c
- cUploaded bysatya20000
- Lab Mannual.docUploaded byImran
- DcfmUploaded byGayatri
- CS 11 - Lesson 9.pdfUploaded byeduardo edrada
- AIMP3_MemoryManager_EventLog.txtUploaded byHerbert Abarca Jovel
- C Programming Session 07Uploaded byJASPER WESSLY
- Idst 2016 SA 05 HashingUploaded byA Sai Bhargav
- Notes on Algorithms by Sedgewick - Ch1 FundamentalsUploaded bysyl
- 03 Engg_ Computer Engg_.pdfUploaded bysssadangi
- MCQ'S DSTCUploaded byMonika Sethi
- 1303-1074-placement-paper-and-interview-questions-of-bel.pdfUploaded byrakesh
- Usage of Permits in SAP Plant MaintenanceUploaded byJawwad Ahmed Khan
- SIMPLEUploaded byChris Harry K
- dsMQUploaded byImran Khan

- MOCPVol2_Sample.pdfUploaded bynearurheart1
- Sample General Power of Attorney for Buying Property in India - For NRIs - LiveNRI for more info - Power of Attorney NRIsUploaded bydhaakchik
- ADM1272 (1)Uploaded bydhaakchik
- (BMA Olympiad Exams Resource Book Class 7 Math Brain Mapping Academy Hyderabad for IIT JEE Foundation) Brain Mapping Academy Hyderabad Teachers and Experts - Talent and Olympiad Exams Resource Book ClUploaded byPikkili Ramesh
- ET17Uploaded byAnonymous GF8PPILW5
- LeadershipCompass-ParticipantshandoutUploaded bydhaakchik
- 1 Induction SolnsUploaded byณัฐวิทย์ ธาราเงินวงส์
- Math Olympiad TutorialsUploaded byAnindya Mukherjee
- How Cleaning Your Bathroom as a Child Can Lead to Success in AdulthoodUploaded bydhaakchik
- Sample mUploaded bydhaakchik
- VREIC Zip Code Hack CheatsheetUploaded bydhaakchik
- Ufe2000 an PMBUS AppnoteUploaded bydhaakchik
- DrBMHegde Book RecommendationUploaded bydhaakchik
- God ExistsUploaded bydhaakchik
- Make Your Own Story BookUploaded bydhaakchik
- Etre Global 2017Uploaded bydhaakchik
- Commercial Realestate Out Look 2017Uploaded byOconnorassociate
- final pdf of standard specificationUploaded byBatepola Bac
- Kena Upanishad: Word-for-Word Translation with Transliteration and Grammatical NotesUploaded bysteph_987042576
- Frawley_David_-_Wisdom_of_the_Ancient_Seers__Mantras_Of_The_Rig_Veda.pdfUploaded bydhaakchik
- Spirent Hse Tmj 2011Uploaded bydhaakchik
- Spirent TestCenter REST API DatasheetUploaded bydhaakchik
- TTsuite ITS 1st StepsUploaded bydhaakchik
- Sales Rank ChartUploaded bydhaakchik
- AV02-0671EN_DS_AFBR-57J5APZ_29Jan2013%2C0Uploaded bydhaakchik
- D7634dfs2Uploaded byadarsh696969
- Amrita GitaUploaded byganesh59
- System Address Map Initialization in x86Uploaded bydhaakchik
- ultimate vimrcUploaded bydhaakchik

- b 52 Crash Andersen Air Force Base ReportUploaded bypgp000
- Math Question 1Uploaded byrahul rastogi
- Saw Gin MaintenanceSettingsUploaded byShankar V Iyer
- Dallas OEP Sales Agent Open House September 21stUploaded byPR.com
- Skoda Workshop Manuals _ Fabia Mk2 _ Power Unit _ 1,4_63 KW MPI Engine _ EngineUploaded byJose Antonio Jimenez Alvarez
- Refrigeration and Air-Conditioning ComponentsUploaded bydhongade1989
- 2000 Nissan Frontier VG33E MAUploaded byDavid Cervantes
- Landsat-Assisted Geostructural Analysis of Bacon-Manito Geothermal FieldUploaded byKurt Zepeda
- Digital CommunicationUploaded byJannah
- A Design of Miniaturized Built-In Penta Band Chip Antenna for EGSMGPSDCSUSPCSWCDMA Mobile HandseUploaded byCongly Nguyen
- Career Theory Model Super 20170501Uploaded byAnonymous jqkNKSc9
- (eBook - PDF)[Ciencia][Electronica][Ingenieria] Edicions Upc - 2004 - Redes, Sistemas y Servicios de Comunicacion (ProblemasUploaded byjcjordana
- Earth PitUploaded byvempadareddy
- European Commission Stagiaire Journal - 2008Uploaded byAlberto Ferreira
- Syllabus Deg EeUploaded bybidyutcurrent
- Smoothy Instructions v2(1)Uploaded bysklux
- 306252760-2-Span-PSC-Composite-Girder-Bridge.pdfUploaded byAnkitKeshri
- Phrasal Verbs LibreUploaded byPepe Castro Erre
- Unimate - The First Industrial RobotUploaded byFairuzy Qonitah
- ForewordUploaded byMuhammad Ikhlas Al Kutsi
- 3.12TriangleInequalityTheoremsInvestigationUploaded byrendie
- R-REC-BS.1770-3-201208-I!!PDF-EUploaded bymacielxflavio
- Bsi Bs Iso 13374-2 Monitoreo Por CondicionUploaded byareanas arias
- online shoppingUploaded byRenjith
- Pump Product Catalog EnglishUploaded byharry_ka
- Module Introduction Reservoir Engineering (B).pdfUploaded byRhuddy Rodrigo Galvez Terrazas
- Quantum Composers Product GuideUploaded byQuantum Composers, Inc.
- pandayUploaded byUmmm
- lesson plan 5Uploaded byapi-354338223
- ijciet0801068-170306052825.pdfUploaded byMakamYashwanth

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.