當前位置:首頁 » 操作系統 » 設計演算法

設計演算法

發布時間: 2022-01-09 02:49:10

① 設計一個演算法程序

試題答案:(1)演算法步驟:
第一步:使i=1;
第二步:使S=0;
第三步:使S=S+2i;
第四步:使i+1;
第五步:如果i>10,則輸出S,結束演算法;否則,返回第三步,繼續執行演算法.
(2)演算法的程序框圖:

② 如何才能設計出優秀的演算法

數據結構中評價一個好的演算法,應該從四個方面來考慮,分別是:

一、演算法的正確性。

二、演算法的易讀性。

三、是演算法的健壯性。

四、是演算法的時空效率(運行)。

演算法的設計取決於數據(邏輯)結構,演算法的實現取決於所採用的存儲結構。數據的存儲結構本質上是其邏輯結構在計算機存儲器中的實現。為了充分反映數據的邏輯結構,它在內存中的映像包括兩個方面,即數據元素之間的信息和數據元素之間的關系。

不同的數據結構有相應的操作。數據操作是定義在數據邏輯結構上的操作演算法,如檢索、插入、刪除、更新和排序。

(2)設計演算法擴展閱讀

該演算法的一般性質包括:

1、對於任何符合輸入類型的輸入數據,都可以根據演算法來解決問題,軟體包保證了計算結構的正確性。

2、演算法中的每一條指令都必須能夠被人或機器執行。

3、確定性演算法應該在每一步之後都有明確的下一步指示。也就是說,確保每個步驟都有下一步行動的指示,並且不缺乏或只有模糊的下一步行動指示。

4、有限演算法的執行必須以有限的步數結束。

③ 求設計一個演算法

因為我是學計算機軟體專業的。故我可以很負責任的告訴你:你的這個要求是沒有人能夠滿足的。理由如下:
(1)、首先鏈表在計算機軟體專業的《數據結構》課程中,應該算是最、最復雜的一種數據結構了,它比對數組、堆棧、隊列等的操作要來得復雜得多。原因就是在涉及到對各種鏈表(單鏈表、雙鏈表等)的編程中,都必須要定義一個(或者多個)指針變數,用來表示單鏈表(或者是雙鏈表)。而指針又是 C 語言中功能最為強大、但是同時也是概念最難於理解、而且對於 C 語言中的指針部分的代碼又是最難於調試的;
(2)、除了上述的(1)之外,你的要求中又涉及到了《數據結構》課程中的排序演算法、以及對鏈表的各種操作(首先要查找到所需要刪除的節點、然後再從單鏈表中進行刪除。而且了,刪除了節點之後,對原來的單鏈表還需要重新進行排序)
(3)、編寫、並且調試通過一個 C 語言源代碼並非一件易事,編寫任何一個程序,都必須要在一個集成的編程調試環境中,通過對各個變數設置斷點、對整個程序進行單步跟蹤,才能夠最終調試通過該程序。
故你的要求是不可能通過別人的編程來實現的,而必須依靠自己的艱苦努力去調試通過程序。
以上就是我多年編程的親身體會。

④ 設計一個演算法

寫了一段fortran代碼,演算法詳見注釋(綠色文字)。

附:模擬運行的結果和代碼

⑤ 設計演算法,並用c語言實現。

#include<stdio.h>

intchange(intamount,intindex,intconstcoins[]){
if(amount==0)return1;
if(index<=0)return0;
for(inti=amount/coins[index-1];i>=0;--i){
if(change(amount-i*coins[index-1],index-1,coins)){
if(i)
printf("%d*%d",i,coins[index-1]);
return1;
}
}
return0;
}

intmain()
{
intcoins[]={20,50};
intconstsize=sizeof(coins)/sizeof(int);
intamount;
for(inti=0;i<size;++i){
for(intj=i+1;j<size;++j){
if(coins[i]>coins[j]){
inttemporary=coins[i];
coins[i]=coins[j];
coins[j]=temporary;
}
}
}
if(coins[0]<=0){
printf("數據有誤,零錢必須大於0 ");
return-1;
}
printf("請輸入要兌換的貨幣金額:");
scanf("%d",&amount);
if(change(amount,size,coins))
printf(" 兌換成功 ");
elseprintf(" 兌換失敗 ");
return0;
}

⑥ 如何設計該演算法。

演算法設計更難,編碼只是根據演算法的偽代碼去實現演算法。需要一些寫代碼的功底。
演算法設計更注重的是想法。基本上演算法設計出來了,寫程序就不難了。
演算法設計的工資比編碼的工資高得多,一個高中生就能編碼了。
在印度,程序員基本上是高中生。而中國的計算機本科生出來基本上做了程序員

⑦ 設計一個演算法

根據勾股定理求出第三遍為根號(a²+b²)

所以周長是
a+b+根號(a²+b²)

⑧ 如何設計演算法

設計一個正確的演算法是一件困難的工作,因為它需要創新,從以太真空中發掘出一個解方案來解決問題。演算法設計比對現有的方案進行改良要難得多,因為演算法設計的可選擇空間太,過多的自由反而成了一種約束。 This book is designed to make you a better algorithm designer. The techniques presented in Part I of this book provide the basic ideas underlying all combinatorial algorithms. The problem catalog of Part II will help you with modeling your application and point you in the right direction of an algorithm or implementation. However, being a successful algorithm designer requires more than book knowledge; it requires a certain attitude, the right problem-solving approach. It is difficult to teach this mindset in a book; yet getting it is essential to become a successful designer. 本書的設計目標是讓你成為一個更好的演算法設計者。本書第一部分展示有關組合演算法的基本原理和基本思想;第二部分的問題清單幫助你為你的問題建模,並且為你指明實現正確演算法的方向。盡管如此,要成為一個成功的演算法設計者光有書本知識是不夠的,面對問題的態度(attitude)和選擇正確的方法更重要。書本容易傳授知識,很難傳授人的心態(mindset)和思考方式;而這種心態和思考卻是成為成功的演算法設計者的根本條件。 The key to algorithm design (or any other problem-solving task) is to proceed by asking yourself a sequence of questions to guide your thought process. What if we do this? What if we do that? Should you get stuck on the problem, the best thing to do is move onto the next question. In any group brainstorming session, the most useful person in the room is the one who keeps asking, ``Why can't we do it this way?'' not the person who later tells them why. Because eventually she will stumble on an approach that can't be shot down. 演算法設計(或其它問題解決任務)的關鍵是一系列持續的自我反問,這些反問引導我們思維的前進。「如果這樣做會怎樣?」,「如果那樣做又會怎樣?」……如果 你被一個問題掐住了,最好的辦法就是先擱一下,換一個問題換一個前進的方向試試。在每組頭腦風暴會議中,最有價值的人是不斷提出為什麼的人,不是爾後解說為什麼的人。因為我們常常被一些習以為常的東西所拌倒,掉進自己設置的陷阱。 kemin:如果問題解決是一種思考過程,那麼思考的形式(過程的嚴謹性、細致性和正確性)很重要,而思考的內容也不容忽視。因為引導我們思考前進的方式 除反問本身外,反問的內容也很重。就比如參加頭腦風暴的材料一樣。人大腦的思維功能是硬編碼的,人與人之間沒有思維規律——質的區別,只是思維的清晰度和 靈敏度——量的差別。人與人之間智力的差別更多體現在思維內容的量上,體現在對外部世界的事實掌握的廣度和深度上。 Towards this end, we provide below a sequence of questions to guide your search for the right algorithm for your problem. To use it effectively, you must not only ask the questions, but answer them. The key is working through the answers carefully, by writing them down in a log. The correct answer to, ``Can I do it this way?'' is never ``no,'' but ``no, because ....'' By clearly articulating(明確有力地表達) your reasoning as to why something doesn't work, you can check if it really holds up or whether you have just glossed(掩蓋) over a possibility that you didn't want to think hard enough about. You will be surprised how often the reason you can't find a convincing(使人信服的) explanation for something is because your conclusion is wrong. 在末尾我們提供一個反問問題的列表,你不但要反問自己這些問題,更重要是仔細回答這些問題,最好把答案寫下來。回答諸如問題「我可以使用這種方式嗎?」的 不是一個「不能」就完了,而是「不能,因為……」。通過仔細明確的回答「為什麼不能」時,你會發現到底是「真的不能「,還是只是你自己不願意去深入思考掩 蓋了」能「。如果你不曾訓練出嚴謹的思考方式,當你這樣做時你會驚訝的發現,為了說明某些東西但卻找不到一個令人信服的解釋的原因常常是因為你的結論本身 是錯的。 An important distinction to keep aware of ring any design process is the difference between strategy and tactics(戰略). Strategy represents the quest for the big picture, the framework around which we construct our path to the goal. Tactics are used to win the minor battles we must fight along the way. In problem solving, it is important to check repeatedly whether you are thinking on the right level. If you do not have a global strategy of how you are going to attack your problem, it is pointless to worry about the tactics. 在設計過程中特別重要區分策略和戰略的概念。策略是對全局的一個探索,一個構築通向目標路徑的指導框架。戰略則是用來解決通向大目標過程的較小的問題。如果你對關於如何對付所面臨的問題沒有一個全局的策略,那關心戰略是不得要領的,予事無補的。在解題領域,不斷修正思維的層次(thinking on the right level)是很重要戰略。(--萊布尼茲曾經將人的解題思考過程比喻成晃篩子,把腦袋裡面的東西都給抖落出來,然後正在搜索的注意力會抓住一切細微的、與問題有關的東西。事實上,要做到能夠令注意力抓住這些有關的東西,就必須時刻將問題放在注意力層面,否則即使關鍵的東西抖落出來了也可能沒注意到。) An example of a strategic question is, ``How best can I model my application as a graph algorithm problem?'' A tactical question might be, ``Should I use an adjacency鄰接 list or adjacency matrix data structure to represent my graph?'' Of course, such tactical decisions are critical to the ultimate quality of the solution, but they can be properly evaluated only in light of a successful strategy. 一個策略問題的例子是:「我如何才能更好地把我的問題建模成圖問題?」。而一個戰略問題可能是這樣:「我是用鄰接列表還是鄰接矩陣來實現我的圖結構?」。當然,這種戰略選擇是對解決方案的最終質量起著重要作用;不過戰略價值的體現還是基於正確的策略的選擇。 When faced with a design problem, too many people freeze up in their thinking. After reading or hearing the problem, they sit down and realize that they don't know what to do next. They stare(凝視) into space, then panic(驚惶), and finally end up settling(沉澱; 決定) for the first thing that comes to mind. Avoid this fate(天數; 運氣; 命運 ). Follow the sequence of questions provided below and in most of the catalog problem sections. We'll tell you what to do next! 初學者在面對問題時常常表現出思維凝滯、手足無措和盲目解題。參考以下的反問問題列表和本書的問題清單,我們告訴你應該怎麼做。 Obviously, the more experience you have with algorithm design techniques such as dynamic programming, graph algorithms, intractability, and data structures, the more successful you will be at working through the list of questions. Part I of this book has been designed to strengthen this technical background. However, it pays to work through these questions regardless of how strong your technical skills are. The earliest and most important questions on the list focus on obtaining a detailed understanding of the problem and do not require specific expertise. 當然本反問問題列表對讀者有背景要求,要求讀者對演算法設計技術(動態規劃、圖演算法、難解性和數據結構)的熟悉程度。本書第一部分的目標就是對這些技術背景進行強化。不過,不管你的技術背景怎樣,通讀這些問題對你解題還是很有裨益的。

⑨ 設計演算法

很容易
list為新的隊列。add(k)方法表示k入隊
tree(i)為樹i的指針

下面是偽代碼。意思一下,能看明白意思跟據你的語言寫就好。(DFS)
Void Solve(i)
If Tree(i)=Null then
List.Add(i)
Exit
End
Solve(Tree(i).LC)
Solve(Tree(i).RC)
End Solve

熱點內容
密碼子的原料是什麼 發布:2024-09-19 09:11:42 瀏覽:347
半夜編程 發布:2024-09-19 09:11:36 瀏覽:103
海康威視存儲卡質量如何 發布:2024-09-19 08:55:35 瀏覽:940
python3默認安裝路徑 發布:2024-09-19 08:50:22 瀏覽:516
環衛視頻拍攝腳本 發布:2024-09-19 08:35:44 瀏覽:418
sqlserveronlinux 發布:2024-09-19 08:16:54 瀏覽:256
編程常數 發布:2024-09-19 08:06:36 瀏覽:952
甘肅高性能邊緣計算伺服器雲空間 發布:2024-09-19 08:06:26 瀏覽:162
win7家庭版ftp 發布:2024-09-19 07:59:06 瀏覽:717
資料庫的優化都有哪些方法 發布:2024-09-19 07:44:43 瀏覽:269