1 / 7

حل تمرین های بخش آرایه ها

جلسه سوم. به نام خداوند هستی بخش یگانه. حل تمرین های بخش آرایه ها. ArrayS. A.M. Safaei. جلسه سوم. آرایه ها. تمرین : در جستجوی دودوی یک آرایه دارای 1000 عنصری ، برای اینکه از نبودن یک داده مطمئن شویم داده مورد نظر باید با چند خانه آرایه مقایسه شود؟. جلسه سوم. آرایه ها. تمرین :

tyme
Télécharger la présentation

حل تمرین های بخش آرایه ها

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. جلسه سوم به نام خداوند هستی بخش یگانه حل تمرین های بخش آرایه ها ArrayS A.M. Safaei

  2. جلسه سوم آرایه ها • تمرین : در جستجوی دودوی یک آرایه دارای 1000 عنصری ، برای اینکه از نبودن یک داده مطمئن شویم داده مورد نظر باید با چند خانه آرایه مقایسه شود؟

  3. جلسه سوم آرایه ها • تمرین : • اگر A آرایه ای مرتب از اعداد صحیح 1 تا 1024 باشد الگوریتم جستجوی دودویی باچند بار مقایسه عدد 128 را پیدا می کند؟

  4. جلسه سوم آرایه ها • تمرین جهت جلسه آینده : • الگوریتم بازگشتی جستجوی دودویی آرایه را بدست آورید. intbin_search (int a[ ], int item, int low, int high) { int mid; if (low<=high) { mid=(low+high)/2; if (item >a[mid]) return bin-search(a,item,mid+1,high); else if (item<a[mid]) return bin-search(a,item,low,mid-1); else return mid; } return-1; }

  5. جلسه سوم آرایه ها • تمرین : درآرایه A[1....3,1....4]وآدرس عنصر A[2,3] رادردوترتیب سطری وستونی بدست آورید. سطریLoc [A(i,j)]= base (A)+[(i-LB1)(uB2-LB2+1)+(j-LB2)] * n ستونی Loc [A(i,j)]= base (A)+[(j-LB2)(uB1-LB1+1)+(i-LB1)] * n (فرض کنید آدرس شروع 0وطول هرعنصر1بایت باشد): Lvalue(A[2,3])=0+[(2-1)(4-1+1)+(3-1)]×1=6سطری Lvalue(A[2,3])=0+[(3-1)(3-1+1)+(2-1)]×1=7ستونی

  6. جلسه سوم آرایه ها typedefstruct { intcol,row; elementtype value; } sparse mat[max-size]; void transpose_sparse (sparse mat[ ], sparse Tmat[ ]) { intn,i,j,current_tm; n=mat[0].value; Tmat[0].row=mat[0].col; Tmat[0].col=mat[0].row; Tmat[0].value=n; if(n>0) { current_TM=1; for(i=0;i<mat[0].col;i++) for(j=1;j<=n;j++) if (mat[j].col==i) { Tmat[current_tm].row=mat[j].col; Tmat[current_tm].col=mat[j].row; Tmat[current_tm].value=mat[j].value; } } } تمرین : الگوریتم ترانهاده کردن ماتریس اسپارس را تعریف نمایید.

  7. جلسه سوم آرایه ها تمرین : • الگوریتم جمع دو ماتریس را بنویسید. • الگوریتم ضرب دو ماتریس را نوشته و مرتبه زمانی آن را مشخص کنید. void ADD (a,b,c,intm,n) { for (inti=0; i<n;i++) for (int j=0;j<m;j++) c[i][j] = a[i][j] + b[i][j]; } for (inti=0; i<m;i++) for (int j=0;j<n;j++) { C[i][j]=0; for (inti=0;i<k;i++) c[i][j] += a[i][k] x b[k][j]; } • ضرب دو ماتریس مرتبه زمانی

More Related