3 views

Uploaded by Pooja Sinha

some c questions

- A Reliable Randomized Algorithm for the Closest-Pair Problem
- Counting & Radix Sort
- Divide And Conquer Strategy
- java programming questions
- ExternalSort
- Parallel Sorting
- Sorting Insertion Sort Merge Sort
- Information Retrieval from A Large Database using Query Co-Processing on a Graphics Processing Unit
- Vlookup Shark Week Video04
- C++ ASSIGNMENT
- 2005 Software Design and Development
- Manual
- District1_2010
- IGNOUMCAMCS-031SolvedAssignments2011
- Practical 312
- c Lab Syllabus
- Heap
- Approx Subdiff
- FUNDAMENTALS
- A896104065_12427_4_2018_ds 3-Sorting

You are on page 1of 8

CS41 - Design and Analysis of Algorithm Assignment Questions Unit II 1. What is divide and conquer strategy? 2. Give the complexity of divide and conquer algorithm in recurrence form? 3. Define Binary search. 4. Describe the computing time of binary search for successful searches. 5. Describe the computing time of binary search for unsuccessful searches. 6. Write the straight forward algorithm to find max and min elements in array of n elements. 7. Design an algorithm to find the position of maximum element among N numbers using divide and conquer. 8. Design an algorithm to find the minimum element among N numbers using divide and conquer. 9. Define merge sort. 10. Write algorithm for merge sort. 11. Write algorithm for merging two sorted arrays. 12. Give the computing time of merge sort in recurrence relation. 13. Write the greedy method control abstraction for the subset paradigm. 14. What is container loading problem? 15. State the Knapsack problem using Greedy approach.

Keys: 1. Divide and conquer strategy: divide problem into sub problems recursively solve sub problems combine solutions to sub problems to get solution to original problem

2. Complexity of divide and conquer algorithm in recurrence form: Complexity of Divide and Conquer is given by, If n=1; T (n) =T (1) If n > 1, then T (n) = a T (n/a) + f (n) By using substitution method, T (n) = nlogba [T (1) + u (n)] where, u (n) =kj=1 h (bj) and h (n) = f (n)/nlogba. 3. Binary search: Binary search is a remarkably efficient algorithm for searching in a sorted array. It works by comparing a search key K with the arrays middle element A[m]. if they match the algorithm stops; otherwise the same operation is repeated recursively for the first half of the array if K < A[m] and the second half if K > A[m]. 4. Computing time of binary search for successful searches: (1) - Best case (log n) Average case (log n) Worst case

5. Computing time of binary search for unsuccessful searches: (log n) Best case , Average case , Worst case

6. Algorithm to find min and max element: void straightmaxmin (a[], int n) { int max, min; max = min = a [1]; for (int i=2; i<=n; i++) {

if (a [i] > max) { max = a [i]; } if (a [i] < min) { min = a [i]; } }

7. Algorithm to find the position of maximum element among N numbers using divide and conquer: void maxposition(int i, int j) //a[ 1 : n ] is a global array. Parameters i & j are integers, 1 <= i <= j <= n. { int pos1, pos2, max1,max; if (i == j) { max = a [i]; //max position is i; } else if (i == j-1) { if (a [i] < a [j]) { max = a [j]; pos1=j; } else max = a [i]; pos1=i; } else { int mid = (i + j)/2; maxpos (i, mid, max); max1=max; pos2=pos1; maxpos ( mid+1, j, max1); if (max < max1) { max = max1; pos1=pos2;

//max position is pos1; } else { //max position is pos1; } } } 8. Algorithm to find the minimum element among N numbers using divide and conquer: void minposition(int i, int j) //a[ 1 : n ] is a global array. Parameters i & j are integers, 1 <= i <= j <= n. { int pos1, pos2, min1,min; if (i == j) { min = a [i]; //min position is i; } else if (i == j-1) { if (a [i] > a [j]) { min = a [j]; pos1=j; } else min = a [i]; pos1=i; } else { int mid = (i + j)/2; minpos (i, mid, max); min1=min; pos2=pos1; minpos ( mid+1, j, max1); if (min > min1) { min = min1; pos1=pos2; //min position is pos1; } else

9. Merge Sort: Merge sort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2)1] and A[n/2..n-1] sorting each of them recursively and then merging the two smaller sorted arrays into a single sorted one. 10. Algorithm for merge sort: void MergeSort (int low, int high) /* a [low: high] is a global array to be sorted. Small (p) is true if there is only one element to sort. In this case the list is already Sorted */ { If (low<high) {// If there are more than one element // Divide P into sub problems. // Find where to split the set. int mid = (low+high)/2; // Solve the sub problems MergeSort (low, mid); MergeSort (mid +1, high); // Combine the solutions Merge (low, mid, high); } }

11. Algorithm to merge two sorted array: void Merge (int low, int mid, int high) /* a[low: high] is a global array containing two sorted subsets in a[low: high] and in a [mid +1: high]. The goal is to merge these two sets into a single set residing in a a[low: high]. b [] is an auxiliary global array. */ { int h = low, i= low, j= mid+1, k; while (( h<= mid) && (j<=high)) { if (a[h] <= a[j]) { b[i] = a[h]; h++; } else { b[i] = a[j]; j++; } } if ( h > mid) { for ( k=j; k<=high; k++) { b[i] = a[k]; i++; } } else { for ( k=h; k<=mid; k++) { b[i]=a[k]; i++; } } {

12. Computing time of merge sort in recurrence relation: Let T (n) be worst case time on a sequence of n keys If n = 1, then T (n) = f (1) (constant) If n > 1, then T (n) = 2 T (n/2) + f (n) Two sub problems of size n/2 each that are solved recursively f (n) time to do the merge

T (n) = O (n log n) 13. Greedy method control abstraction for the subset paradigm: SolType Greedy (Type a[], int n) { SolType solution = EMPTY; for (int i=1; i<=n; i++) { Type x= Select (a); if ( Feasible (solution, x)) {

solution = Union (solution, x); } } return solution; } 14. Container loading problem: A large ship is loaded with cargos. The cargo is containerized. Different containers may have different weights. Let wi be the ith container, 1 i n. The cargo capacity of the ship is c. We have to load the ship with the maximum number of containers.

Feasible solution n wixi c and xi {0,1} , 1 i n i=1 x=1 > container is to be loaded x= 0 -> container is not to be loaded

Objective function Maximize n xi i=1 Optimal Solution - Every feasible solution that maximizes the objective function. 15. Knapsack Problem Greedy Approach. Maximize l i n

pixi m

- Counting & Radix SortUploaded byMuhammad Fahmi Irfan
- Divide And Conquer StrategyUploaded bySaraah Ghori
- java programming questionsUploaded byhygreeva
- Sorting Insertion Sort Merge SortUploaded byMia Sam
- A Reliable Randomized Algorithm for the Closest-Pair ProblemUploaded bykletomz
- ExternalSortUploaded byJaswinder
- Parallel SortingUploaded byAmy Latifah
- Information Retrieval from A Large Database using Query Co-Processing on a Graphics Processing UnitUploaded byInternational Journal for Scientific Research and Development - IJSRD
- Vlookup Shark Week Video04Uploaded byniti860
- C++ ASSIGNMENTUploaded bySai Narayanan
- 2005 Software Design and DevelopmentUploaded byNatsu
- ManualUploaded byalexisfante
- District1_2010Uploaded byTimmy Feng
- IGNOUMCAMCS-031SolvedAssignments2011Uploaded byindia_ethical_hacker
- Practical 312Uploaded byYogesh yadav
- c Lab SyllabusUploaded byush_ush_ush2005
- HeapUploaded byVishnu Sathyanesan
- Approx SubdiffUploaded byDeepak Kumar
- FUNDAMENTALSUploaded bysankarwinning
- A896104065_12427_4_2018_ds 3-SortingUploaded byHanuman Sai
- CS502MIDTERSOLVEDSUBJECTIVEWITHREFERENCESOLVEDpaper.pdfUploaded bymc190204637 AAFIAH TAJAMMAL
- Data Structures and Algorithms AssignmentUploaded byVibhu Mittal
- CSE680-08LinearSorting.pdfUploaded byDAWIT SEGED
- hw_1Uploaded byLg.Jaya Senan
- Binary Search Trees data structureUploaded byAbdullah
- D1,L2 Sorting Algorithms.pptUploaded bymokhtarppg
- avs1Uploaded bySuresh Kumar
- Gate 2016 Cse SyllabusUploaded byrahulrixx
- lec8Uploaded byPallav Anand
- Cailloux Taxonomy 2007Uploaded bysitukangsayur

- Political map of the world (June 2012, by CIA)Uploaded byJan Goossenaerts
- EconomyUploaded byPooja Sinha
- Intro Analysis CopyUploaded byBrian Precious
- CSP_2015_engUploaded bympvetrivelu
- 0204Uploaded byPooja Sinha
- Country ProjectUploaded bySeemiAli
- ncert4Uploaded byPooja Sinha
- Ciml v0_8 All Machine LearningUploaded byaglobal2
- CS_S06Uploaded byPooja Sinha
- cs_2kjkj_vbUploaded byAlok Kumar Singh
- chemistry cbse solvedUploaded bya
- World Physical 2011 NovUploaded bykerem11
- yunUploaded byPooja Sinha
- af1Uploaded byPooja Sinha
- A1LaUploaded byPooja Sinha
- uge01Uploaded byPooja Sinha
- Completeness of RUploaded bySIVA KRISHNA PRASAD ARJA
- ArchimedeanUploaded byPooja Sinha
- 01 StreamsUploaded byPooja Sinha
- CS_SET_2_GATE_2015Uploaded byPooja Sinha
- CS02_2014 (1)Uploaded byJayanthi Keerthi
- CS_SET_1_GATE_2015Uploaded byBhuvan Jai
- CS01_2014Uploaded byPooja Sinha
- AaaUploaded byPooja Sinha

- Titan Tjet Tt 1902 1972 Users ManualUploaded byelectron1999
- CS 310 Midterm PaperUploaded byAfan Arshad
- Dicusson on moment release in StaadUploaded byGautam Paul
- Decision TreesUploaded byRatul Kumar
- Groovy Quick GuideUploaded byMurat Tanır
- Sample ProcessingUploaded bykamatsachin
- Machine Learning Models and Algorithms for Big Data ClassificationUploaded by陳琮方
- Architecting User Identification DeploymentsUploaded byamojm1
- 122pspugUploaded byPrabhuraaj98
- Lattices DmsUploaded byrhth
- Lorusso - Email MarketingUploaded byWalter Basile
- CM109 USB I/O Controller DataSheetUploaded bykurion
- 1Copy of PMP Notes by JustPMP UpdatedUploaded bySankit Singh
- LP Introduction(Autocad)Uploaded byQuisa Lao
- rt very importnt bookUploaded byasdf
- SuricataWinInstallationGuide_v1.3.pdfUploaded byGerardo Marquez
- accb1MMS 403Uploaded byAbhishek_mhptr
- adicUploaded byasfgh
- Vedic Computation - Redefining Computer Science in the Light of Maharishi Vedic Science- Gregory Guthrie- MUMUploaded byAMTR
- Lg Flash ToolUploaded byhalleffect09
- EC Council BrochureUploaded byjayarajan
- symbols-letter.pdfUploaded byAurivas
- 33CLR2401LG1.pdfUploaded byCleber Almeida
- Smart Mirror with a Personnel AIUploaded byIJRASETPublications
- Syllabus CSEUploaded byShubhamGupta
- Analysis and Design of Algorithms _ADA_ _Elective IUploaded byDebashish Mahapatra
- Rschoustra.awalkAroundBlock.presentationUploaded bybiswal83
- Guia Lotus NotesUploaded bywhisper77a
- 63516396 Data Warehousing Basic ConceptsUploaded byBhaskar Reddy
- blueserver_operators_guideUploaded bysimoncorriganuk