㈠ 數據結構:查找演算法和排序演算法有哪些知道的請詳細說明下!謝謝
查找就包括順序查找,二分查找線段樹的查找
排序就多了
冒泡,選擇,插入,分治,堆排序,基數排序,桶排序,快速排序。。。。
㈡ 對比順序查找,二分查找和哈希查找演算法,它們各自的特點是什麼
順序查找,二分查找和哈希查找演算法,它們各自的特點是:
1.對比順序查找的特點就是從表的第一個元素開始一個一個向下查找,如果有和目標一致的元素,查找成功;如果到最後一個元素仍沒有目標元素,則查找失敗。
2.二分查找的特點就是從表中間開始查找目標元素。如果找到一致元素,則查找成功。如果中間元素比目標元素小,則仍用二分查找方法查找表的後半部分(表是遞增排列的),反之中間元素比目標元素大,則查找表的前半部分。
3.哈希演算法的特點是是使用給定數據構造哈希表,然後在哈希表上進行查找的一種演算法。先給定一個值,然後根據哈希函數求得哈希地址,再根據哈希地址查找到要找的元素。是通過數據元素的存儲地址進行查找的一種演算法。
㈢ 急求!!!!關於數據結構在【C語言】環境中實現:是關於查找和排序的演算法 實現如下功能
下面的代碼能實現你的功能咯。。。都很基礎的,這是我以前學C的時候寫的,希望對你有幫助
#include <stdio.h>
#include <malloc.h>
#include<stdlib.h>
struct stu
{ struct stu *last;
int a;
struct stu* next;
}*q,*h,*p,*l;
/*void jllb()
{
int i,j;
h=(struct stu*)malloc(sizeof(struct stu));
q=h;
q->last=NULL;
h->a=0;
for(i=1;i<=9;i++)
{
p=(struct stu*)malloc(sizeof(struct stu));
p->a=2*i+3;
p->next=NULL;
q->next=p;
p->last=q;
q=p;
}
}
void cylb()
{
int b;
printf("請輸入要插入的數");
scanf("%d",&b);
p=(struct stu*)malloc(sizeof(struct stu));
p->a=b;
for(q=h;(q->next)->a<b;q=q->next);
p->next=q->next;
p->last=q;
q->next=p;
p->next->last=p;
}
void dylb()
{
for(q=h;;q=q->next)
{
printf("%d\n",q->a);
if(q->next==NULL)break;
}
}
void sclb()
{
int m;
printf("請輸入需刪除的數:");
scanf("%d",&m);
for(p=h;p->a!=m;p=p->next) ;
q=p->last;
p->next->last=q;
q->next=p->next;
free(p);
}
void xglb()
{
int n,m;
printf("選擇錯誤的數:");
scanf("%d",&n);
printf("\n需要改成的數:");
scanf("%d",&m);
for(p=h;p->a!=n;p=p->next);
p->a=m;
}
void _save()
{
FILE *fp;
if((fp=fopen("D:\\data.txt","w"))==NULL)
{
printf("error");
exit(0);
}
p=h;
while(1)
{
fread(p,sizeof(struct stu),1,fp);
p=p->next;
if(p->next==NULL)
break;
}
fclose(fp);
}*/
void chu()
{
FILE *fp;
int i=0;
if((fp=fopen("D:\\data.txt","r"))==NULL)
{
printf("esaa");
exit(0);
}
q=(struct stu *)malloc(sizeof(struct stu ));
while(1)
{
fread(q,sizeof(struct stu),1,fp);
if(i==0)
q=h;
q=(struct stu *)malloc(sizeof(struct stu ));
q=q->next;
i++;
if(q->next==NULL)
break;
}
fclose(fp);
q=h;
printf("%d %d\n\n\n",q->a,q->next->a);
}
main()
{
int m;
// jllb();
// dylb();
while(1)
{
printf("需要選擇的功能1sc 2cy 0 tc 3;");
scanf("%d",&m);
switch(m)
{
// case 1:sclb();break;
// case 2:cylb();break;
// case 0:exit(0);break;
// case 3:xglb();break;
// case 4:_save(); break;
case 5:chu();break;
}
// dylb();
}
}
㈣ vb解析演算法的功能
排序演算法 所謂排序,就是使一串記錄,按照其中的某個或某些關鍵字的大小,遞增或遞減的排列起來的操作。
解析演算法 所謂解析法(analysis algorithm)是指用解析的方法找出表示問題的前提條件與結果之間關系的數學表達式,並通過表達式的計算來實現問題求解。
事先考慮到某一變數可能取的值,盡量用自然語言中含義清楚的單詞來表示它的每一個值,這種方法稱為枚舉方法。
索引查找是在索引表和主表(即線性表的索引存儲結構)上進行的查找。
索引查找的過程是:首先根據給定的索引值K1,在索引表上查找出索引值等於KI的索引項,以確定對應予表在主表中的開始位置和長度,然後再根據給定的關鍵字K2,茬對應的子表中查找出關鍵字等於K2的元素(結點)。對索引表或子表進行查找時,若表是順序存儲的有序表,則既可進行順序查找,也可進行二分查找,否則只能進行順序查找!
㈤ 查找演算法的作用
查找就是在一個數據集合里查找到你需要的數據,查找演算法就是在查找過程中使用的演算法。查找演算法有好多,最基礎的就是線性表查找。
因為提到了演算法,所以需要注意的是時間復雜度跟空間復雜度,進而涉及到數據的存儲方式,比如數組,鏈表,矩陣,樹,圖等等數據結構,這些數據結構可以幫助你降低演算法的復雜度。
如果有興趣,隨便找本數據結構書翻翻,裡面或多或少都會有講解。用關鍵字標識一個數據元素,查找時根據給定的某個值,在表中確定一個關鍵字的值等於給定值的記錄或數據元素。在計算機中進行查找的方法是根據表中的記錄的組織結構確定的。順序查找也稱為線形查找,從數據結構線形表的一端開始,順序掃描,依次將掃描到的結點關鍵字與給定值k相比較,若相等則表示查找成功;若掃描結束仍沒有找到關鍵字等於k的結點,表示查找失敗。二分查找要求線形表中的結點按關鍵字值升序或降序排列,用給定值k先與中間結點的關鍵字比較,中間結點把線形表分成兩個子表,若相等則查找成功;若不相等,再根據k與該中間結點關鍵字的比較結果確定下一步查找哪個子表,這樣遞歸進行,直到查找到或查找結束發現表中沒有這樣的結點。分塊查找也稱為索引查找,把線形分成若干塊,在每一塊中的數據元素的存儲順序是任意的,但要求塊與塊之間須按關鍵字值的大小有序排列,還要建立一個按關鍵字值遞增順序排列的索引表,索引表中的一項對應線形表中的一塊,
㈥ 哪個演算法可以即可以用於查找又可以用於排序
二叉排序樹的構造演算法既可以用於查找,也可以用於排序
㈦ 軟考 軟體設計師 過來人指路
2-軟體設計師視頻—ciu培訓免費在線觀看
鏈接:https://pan..com/s/1HBgPCST07X0QMHC3znSK_Q
軟體設計師是指能根據軟體開發項目管理和軟體工程的要求,按照系統總體設計規格說明書進行軟體設計,編寫程序設計規格說明書等相應的文檔的實用性人才。還能夠組織和指導程序員編寫、調試程序,並對軟體進行優化和集成測試,開發出符合系統總體設計要求的高質量軟體;具有工程師的實際工作能力和業務水平,可聘任工程師職務。2004年人社部將高級程序員更名為軟體設計師
㈧ 索引順序查找演算法
參考代碼,不一定正確。
#include <malloc.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
struct element
{
long key;
long data;
};
struct index
{
long address;
long maxkey;
};
struct index *creatidxtable(struct element *elems, long elen, long *tlen, long *plen)
{
struct index *itable;
long i, step, len;
len = (long)sqrt(elen);
*plen = len;
step = len;
len = (len * len == elen ? len : len + 1);
*tlen = len;
itable = (struct index *)malloc(sizeof(struct index) * len);
for (i = 0; i < len; ++i)
{
itable[i].address = i;
if (i < len - 1)
itable[i].maxkey = elems[ i * step + *plen - 1].key;
else
itable[i].maxkey = elems[elen - 1].key;
}
return itable;
}
long searchposition(struct index *itable, long length, long *times, long key)
{
long i;
++(*times);
if (key <= itable[0].maxkey)
return itable[0].address;
++(*times);
if (key >= itable[length - 1].maxkey)
return itable[length - 1].address;
for (i = 0; i < length - 1; ++i)
{
(*times) += 2;
if (key > itable[i].maxkey && key <= itable[i + 1].maxkey)
return itable[i + 1].address;
}
return -1;
}
long seqencesearch(struct element *elems, long start, long length, long *times, long key)
{
long i;
for (i = start; i < start + length; ++i)
{
++(*times);
if (elems[i].key == key)
return i;
}
return -1;
}
void selectionsort(struct element *elems, long length)
{
long i, j, k, s = sizeof(struct element);
struct element t;
for (i = 0; i < length - 1; ++i)
{
k = i;
for (j = i + 1; j < length; ++j)
{
if (elems[k].key > elems[j].key)
{
k = j;
}
}
if (k != i)
{
memcpy(&t, elems + i, s);
memcpy(elems + i, elems + k, s);
memcpy(elems + k, &t, s);
}
}
}
void initdata(struct element *elems, int length)
{
long i;
srand(time(NULL));
for (i = 0; i < length; ++i)
{
elems[i].data = elems[i].key = rand();
}
}
void output(struct element *elems, int length)
{
long i;
for (i = 0; i < length; ++i)
{
printf("%-10d ", elems[i].key);
if ((i + 1) % 5 == 0)
printf("\n");
}
}
void main()
{
struct element * elems;
struct index *itable;
long num, tlen, plen, times, key, start, pos;
while (1)
{
printf("請輸入想要測試的數據量:");
scanf("%ld", &num);
if (num <= 0)
break;
elems = (struct element *)malloc(sizeof(struct element) * num);
initdata(elems, num);
selectionsort(elems, num);
output(elems, num);
itable = creatidxtable(elems, num, &tlen, &plen);
times = 0;
printf("\n");
printf("請輸入一個查找關鍵字:");
scanf("%ld", &key);
if ((start = searchposition(itable, tlen, ×, key)) == -1)
{
printf("查找失敗1!\n");
}
else
{
pos = seqencesearch(elems, start * plen,
(start == tlen - 1 ? num - (tlen - 1) * plen : plen), ×, key);
if (pos != -1)
{
printf("查找成功!\n");
printf("關鍵字對應的值:%ld\n", elems[pos].data);
printf("關鍵字比較次數:%ld\n", times);
}
else printf("查找失敗!\n");
}
free(elems);
free(itable);
}
system("PAUSE");
}
㈨ 查找演算法性能研究(順序存儲、有序順序存儲、鏈表存儲、二叉排序樹存儲)
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
static const int ARRAY_MAX = 10000;
typedef int DataType;
class SequentialStorage
{
public:
DataType data[ARRAY_MAX];
int top;
SequentialStorage()
{
top = -1;
}
void insertData(DataType data)
{
if(top == ARRAY_MAX-1)
return;
this->data[++top] = data;
}
int find(DataType data)
{
for(int i = 0;i <= top;i++)
{
if(this->data[i] == data)
return i;
}
return -1;
}
};
class OrderlySequenceStorage
{
public:
DataType data[ARRAY_MAX];
int top;
OrderlySequenceStorage()
{
top = -1;
}
void insertData(DataType data)//插入排序
{
if(top == ARRAY_MAX-1)
return;
int i = top;
while(this->data[i] > data&&i != -1)
{
this->data[i+1] = this->data[i];
i--;
}
this->data[i+1] = data;
top++;
}
int find(DataType data)//普通查找
{
for(int i = 0;i <= top;i++)
{
if(this->data[i] == data)
return i;
}
return -1;
}
int find2(DataType data)//二分法
{
if(this->data[0] > data||this->data[top] < data)
return -1;
if(this->data[0] == data)
return 0;
if(this->data[top] == data)
return top;
int a = 0;
int b = top;
while(true)
{
if(a == b-1)
return -1;
if(this->data[(a+b)/2] == data)
return (a+b)/2;
else if(this->data[(a+b)/2] < data)
a = (a+b)/2;
else
b = (a+b)/2;
}
}
};
typedef struct node
{
DataType data;
struct node *pNext;
}LLSNode;
class LinkedListStorage
{
public:
LLSNode *pHead;
LinkedListStorage()
{
pHead = NULL;
}
void insertData(DataType data)
{
LLSNode *p = (LLSNode *)malloc(sizeof(LLSNode));
p->data = data;
p->pNext = pHead;
pHead = p;
}
LLSNode *find(DataType data)
{
LLSNode *p = pHead;
while(p)
{
if(p->data == data)
return p;
p = p->pNext;
}
return NULL;
}
};
typedef struct node2
{
DataType data;
struct node2 *lchild,*rchild;
}BSTNode;
class BinarySortTree
{
public:
BSTNode *pRoot;
BinarySortTree()
{
pRoot = NULL;
}
void insertData(DataType data)
{
BSTNode *f,*p = pRoot;
while(p)
{
f = p;
if(data < p->data)
p = p->lchild;
else
p = p->rchild;
}
p = (BSTNode *)malloc(sizeof(BSTNode));
p->data = data;
p->lchild = NULL;
p->rchild = NULL;
if(pRoot == NULL)
pRoot = p;
else
if(data < f->data)
f->lchild = p;
else
f->rchild = p;
}
BSTNode *find(DataType data)
{
if(pRoot == NULL)
return NULL;
else
return recursion(data,pRoot);
}
BSTNode *recursion(DataType data,BSTNode *p)
{
if(data == p->data||p == NULL)
return p;
else if(data < p->data)
return recursion(data,p->lchild);
else
return recursion(data,p->rchild);
}
void print()
{
if(pRoot != NULL)
printR(pRoot);
}
void printR(BSTNode *p)
{
if(p->lchild != NULL)
printR(p->lchild);
printf("%d\t",p->data);
if(p->rchild != NULL)
printR(p->rchild);
}
};
class CPUTime
{
public:
_int64 getCPUCycleCount(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}
long long arr[1000];
int count;
long long lastCPUCycleCount;
int randCount;
CPUTime()
{
for(int i = 0;i < 1000;i++)
arr[i] = 0;
count = -1;
lastCPUCycleCount = getCPUCycleCount();
randCount = 0;
}
void setTimePoint()
{
arr[++count] = getCPUCycleCount()-lastCPUCycleCount;
lastCPUCycleCount = getCPUCycleCount();
}
int rand()
{
randCount++;
int temp = getCPUCycleCount()%20000;
return (temp*(randCount+temp))%10007;
}
};
int main()
{
SequentialStorage ss;
OrderlySequenceStorage oss;
LinkedListStorage lls;
BinarySortTree bst;
DataType temp1;
CPUTime cpuTime;
for(int i = 0;i < 2000;i++)
{
temp1 = cpuTime.rand();
ss.insertData(temp1);
oss.insertData(temp1);
lls.insertData(temp1);
bst.insertData(temp1);
}
DataType temp[7];
for(int i = 0;i < 7;i++)
temp[i] = ss.data[cpuTime.rand()%2000];
cpuTime.setTimePoint();
for(int i = 0;i < 7;i++)
{
ss.find(temp[i]);
cpuTime.setTimePoint();
}
for(int i = 0;i < 7;i++)
{
oss.find(temp[i]);
cpuTime.setTimePoint();
}
for(int i = 0;i < 7;i++)
{
oss.find2(temp[i]);
cpuTime.setTimePoint();
}
for(int i = 0;i < 7;i++)
{
lls.find(temp[i]);
cpuTime.setTimePoint();
}
for(int i = 0;i < 7;i++)
{
bst.find(temp[i]);
cpuTime.setTimePoint();
}
int count = 1;
printf("各項存儲結構查找已存在數據的時間(cpu周期):\n");
printf("儲存方式\t\t數據1\t數據2\t數據3\t數據4\t數據5\t數據6\t平均\n");
int a[9];
for(int i = 1;i < 8;i++)
a[i] = (int)cpuTime.arr[count++];
a[8] = (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])/7;
printf("順序存儲\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[8]);
for(int i = 1;i < 8;i++)
a[i] = (int)cpuTime.arr[count++];
a[8] = (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])/7;
printf("有序順序存儲(普通)\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[8]);
for(int i = 1;i < 8;i++)
a[i] = (int)cpuTime.arr[count++];
a[8] = (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])/7;
printf("有序順序存儲(二分法)\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[8]);
for(int i = 1;i < 8;i++)
a[i] = (int)cpuTime.arr[count++];
a[8] = (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])/7;
printf("鏈表存儲\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[8]);
for(int i = 1;i < 8;i++)
a[i] = (int)cpuTime.arr[count++];
a[8] = (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])/7;
printf("二叉排序樹存儲\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[8]);
system("pause");
}
//我按照課題的要求寫的c++具體實現的代碼,樓主可以編譯運行著試試,你可以參考一下
//我這搜索的是儲存結構里已存在的數據,你也可以按題目的要求用隨機生成的數據
//樓主留下qq吧,我等會把流程圖發給你
//至於其他的,樓主還是自己試著寫寫看吧
另外,站長團上有產品團購,便宜有保證