掌握 DSA 的注意事項:
Master DSA「有資格」獲得向 S/w Ers 提供的高薪。
DSA 是軟體工程的主要部分。
在編寫程式碼之前,請確保您了解大局,然後深入了解細節。
這一切都是為了直觀地理解概念,然後透過任何 l/g 將這些概念翻譯成程式碼,因為 DSA 與語言無關。
每個即將到來的概念都以某種方式與先前的概念相關聯。因此,除非您透過練習徹底掌握了這個概念,否則不要跳話題或繼續前進。
當我們直觀地學習概念時,我們會對材料有更深入的理解,從而幫助我們更長時間地保留知識。
如果您遵循這些建議,您將不會有任何損失。
Linear DS: Arrays LinkedList(LL) & Doubly LL (DLL) Stack Queue & Circular Queue Non-linear DS: Trees Graphs
大 O 表示法
理解這種表示法對於演算法的效能比較至關重要。
這是一種比較演算法效率的數學方法。
時間複雜度
程式碼運行得越快,它就會越低
V. 大多數採訪的印象。
空間複雜度
由於儲存成本低,與時間複雜度相比很少被考慮。
要理解,因為面試官也可能會問你這個。
三個希臘字母:
- 歐米茄
- 西塔
- Omicron 即 Big-O [最常見]
演算法案例
- 最佳情況[使用 Omega 表示]
- 平均案例[使用 Theta 表示]
- 最壞情況[使用 Omicron 表示]
從技術上講,平均情況 Big-O 不存在最佳情況。它們分別以 omega 和 theta 表示。
我們總是在衡量最壞的情況。
## O(n): Efficient Code Proportional Its simplified by dropping the constant values. An operation happens 'n' times, where n is passed as an argument as shown below. Always going to be a straight line having slope 1, as no of operations is proportional to n. X axis - value of n. Y axis - no of operations // O(n) function printItems(n){ for(let i=1; i <pre class="brush:php;toolbar:false">## O(n^2): Nested loops. No of items which are output in this case are n*n for a 'n' input. function printItems(n){ for(let i=0; i<n i console.log for j="0;" printitems> <pre class="brush:php;toolbar:false">## O(n^3): No of items which are output in this case are n*n*n for a 'n' input. // O(n*n*n) function printItems(n){ for(let i=0; i<n i console.log iteration for j="0;" mid k="0;" inner printitems comparison of time complexity: o> O(n*n) ## Drop non-dominants: function xxx(){ // O(n*n) Nested for loop // O(n) Single for loop } Complexity for the below code will O(n*n) + O(n) By dropping non-dominants, it will become O(n*n) As O(n) will be negligible as the n value grows. O(n*n) is dominant term, O(n) is non-dominnat term here. </n>
## O(1): Referred as Constant time i.e No of operations do not change as 'n' changes. Single operation irrespective of no of operands. MOST EFFICIENT. Nothing is more efficient than this. Its a flat line overlapping x-axis on graph. // O(1) function printItems(n){ return n+n+n+n; } printItems(3); ## Comparison of Time Complexity: O(1) > O(n) > O(n*n)
## O(log n) Divide and conquer technique. Partitioning into halves until goal is achieved. log(base2) of 8 = 3 i.e we are basically saying 2 to what power is 8. That power denotes the no of operations to get to the result. Also, to put it in another way we can say how many times we need to divide 8 into halves(this makes base 2 for logarithmic operation) to get to the single resulting target item which is 3. Ex. Amazing application is say for a 1,000,000,000 array size, how many times we need to cut to get to the target item. log(base 2) 1,000,000,000 = 31 times i.e 2^31 will make us reach the target item. Hence, if we do the search in linear fashion then we need to scan for billion items in the array. But if we use divide & conquer approach, we can find it in just 31 steps. This is the immense power of O(log n) ## Comparison of Time Complexity: O(1) > O(log n) > O(n) > O(n*n) Best is O(1) or O(log n) Acceptable is O(n)
O(n log n) : Used in some sorting Algos. Most efficient sorting algo we can make unless we are sorting only nums.
Tricky Interview Ques: Different Terms for Inputs. function printItems(a,b){ // O(a) for(let i=0; i<a i console.log o for j="0;" printitems we can have both variables equal to suppose a is and b then will be very different. hence it eventually what call it. similarly if these were nested loops become> <pre class="brush:php;toolbar:false">## Arrays No reindexing is required in arrays for push-pop operations. Hence both are O(1). Adding-Removing from end in array is O(1) Reindexing is required in arrays for shift-unshift operations. Hence, both are O(n) operations, where n is no of items in the array. Adding-Removing from front in array is O(n) Inserting anywhere in array except start and end positions: myArr.splice(indexForOperation, itemsToBeRemoved, ContentTobeInsterted) Remaining array after the items has to be reindexed. Hence, it will be O(n) and not O(0.5 n) as Big-O always meassures worst case, and not avg case. 0.5 is constant, hence its droppped. Same is applicable for removing an item from an array also as the items after it has to be reindexed. Finding an item in an array: if its by value: O(n) if its by index: O(1) Select a DS based on the use-case. For index based, array will be a great choice. If a lot of insertion-deletion is perform in the begin, then use some other DS as reindexing will make it slow.
n=100 的時間複雜度比較:
O(1) = 1
O(log 100) = 7
O(100) = 100
O(n^2) = 10,000
n=1000 的時間複雜度比較:
O(1) = 1
O(log 1000) = ~10
O(1000) = 1000
O(1000*1000) = 1,000,000
我們主要關注這4個:
大 O(n*n):巢狀循環
大 O(n):比例
Big O(log n):分而治之
大 O(1):常數
O(n!) 通常發生在我們故意寫糟糕的程式碼時。
O(n*n) 是可怕的演算法
O(n log n) 是可以接受的,並被某些排序演算法使用
O(n) :可接受
O(log n), O(1) :最佳
所有 DS 的空間複雜度幾乎相同,即 O(n)。
使用排序演算法,空間複雜度從 O(n) 到 O(log n) 或 O(1) 不等
時間複雜度依演算法變化
除數字(如字串)之外的排序的最佳時間複雜度是 O(n log n),即快速排序、合併排序、時間排序、堆排序。
應用所學的最佳方法是盡可能多地編寫程式碼。
根據每個 DS 的優缺點來選擇在哪個問題陳述中選擇哪個 DS。
更多資訊請參考:bigocheatsheet.com
以上是DSA 與 Big O 表示法簡介的詳細內容。更多資訊請關注PHP中文網其他相關文章!

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

Python和JavaScript在社區、庫和資源方面的對比各有優劣。 1)Python社區友好,適合初學者,但前端開發資源不如JavaScript豐富。 2)Python在數據科學和機器學習庫方面強大,JavaScript則在前端開發庫和框架上更勝一籌。 3)兩者的學習資源都豐富,但Python適合從官方文檔開始,JavaScript則以MDNWebDocs為佳。選擇應基於項目需求和個人興趣。

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

JavaScript在現實世界中的應用包括服務器端編程、移動應用開發和物聯網控制:1.通過Node.js實現服務器端編程,適用於高並發請求處理。 2.通過ReactNative進行移動應用開發,支持跨平台部署。 3.通過Johnny-Five庫用於物聯網設備控制,適用於硬件交互。

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務

本文展示了與許可證確保的後端的前端集成,並使用Next.js構建功能性Edtech SaaS應用程序。 前端獲取用戶權限以控制UI的可見性並確保API要求遵守角色庫


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

Dreamweaver Mac版
視覺化網頁開發工具