DEV Community

Rajesh Mishra
Rajesh Mishra

Posted on • Edited on

1 1

Algorithm Code Complexity

Code Complexity compute it by using the control flow graph of the program. Cyclomatic complexity measures the number of nested conditions within the code, such as those created by for, if/else, switch, while, and until. The greater the number of conditions (as in example b from above), the greater the complexity.

 

Time complexity:
 Worst Case Scenario Average Case Scenario Best Case Scenario
Accessing an element O(1) O(1) O(1)
Updating an element O(1) O(1) O(1)
Deleting an element O(n) O(n) O(1)
Inserting an element O(n) O(n) O(1)
Searching for an element O(n) O(n) O(1)

  Algorithm complexity:  
Worst Case Average Case Best Case Space Complexity
Quicksort O(n2) O(n log(n)) O(n log(n)) O(log(n))
Mergesort O(n log(n)) O(n log(n)) O(n log(n)) O(n)
Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1)
Bubble Sort O(n2) O(n2) O(n) O(1)
Insertion Sort O(n2) O(n2) O(n) O(1)
Selection Sort O(n2) O(n2) O(n2) O(1)

Source: Java Algos


Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay