Skip to Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
100
|
第三章
一個 BinarySearch 的使用範例:
將新元素插入已排序的串列中
延伸資訊
訣竅 3.3 將討論如何不透過對串列排序而取得元素順序。
針對各種排序演算法的概論,請參見
http://bit.ly/2bRckv
。
3.3 在不排序下取得順序
問題點
你想得到串列元素排列順序,但不想對串列排序,因為這需耗費記憶體以保存多筆不同
順序的串列。[Page-101]
解決方案
以
Ordering
指令得到元素的排列順序。
ch03.indd 100 2014/4/2 上午 05:18:58
3.3 在不排序下取得順序
|
101
討論說明
Ordering
指令還有兩種用法。第一種是接受整數引數,限制輸出數目,指定
n
輸出前
n
個元素的順序,指定
-n
則輸出後
n
個元素的順序。當你不需對整個串列排序時,這使
得
Ordering
指令比
Sort
指令更好用。
第二種是同時接受整數引數及排列順序函數。
當取得串列排列順序後,建立排序版的串列便很容易了。
然而,即使不需輸出完整串列順序,
Ordering
與
Sort
指令使用比較函數的次數仍是相
同的。
以堆積(heap)進行此類運算應該會更有效率,但為了少數使用案例而更改演算法,放
棄將比較次數最小化的原則,似乎有點划不來。畢竟,即使是在我的筆記型電腦上,對
100 萬個元素執行
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Mathematica Cookbook

Mathematica Cookbook

Sal Mangano

Publisher Resources

ISBN: 9789863470106