Malware types (virus, worm, trojan, ransomware) in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When studying malware types, it helps to understand how their actions grow as they spread or infect systems.
We want to know how the effort or damage increases as more devices or files are involved.
Analyze the time complexity of this simplified malware spreading code.
for infected_device in network:
for connected_device in infected_device.connections:
if connected_device.is_vulnerable():
infect(connected_device)
This code shows how a malware worm spreads by trying to infect connected devices in a network.
- Primary operation: Checking and infecting connected devices.
- How many times: For each infected device, it checks all its connections.
As the number of infected devices grows, the number of checks grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 100 checks |
| 100 | About 10,000 checks |
| 1000 | About 1,000,000 checks |
Pattern observation: The work grows very fast as more devices get infected, roughly multiplying by itself.
Time Complexity: O(n²)
This means the effort to spread grows roughly with the square of the number of infected devices.
[X] Wrong: "The malware only does a fixed amount of work no matter how many devices are infected."
[OK] Correct: As more devices get infected, the malware tries to infect more connections, so the work grows quickly.
Understanding how malware spreads helps you think about how systems can be protected and how attacks scale in real life.
"What if the malware only tried to infect one new device per infected device instead of all connections? How would the time complexity change?"
Practice
Solution
Step 1: Understand malware replication methods
Viruses need to attach to files, but worms can spread independently over networks.Step 2: Identify malware that self-replicates without a host
Worms are known for spreading themselves without needing to attach to other programs.Final Answer:
Worm -> Option AQuick Check:
Self-replicating malware without host = Worm [OK]
- Confusing virus with worm
- Thinking trojans self-replicate
- Mixing ransomware with spreading behavior
Solution
Step 1: Define Trojan horse malware
Trojans appear as normal software but hide harmful actions inside.Step 2: Match description to options
Malware disguised as legitimate software matches the definition of a Trojan as disguised malware.Final Answer:
Malware disguised as legitimate software -> Option DQuick Check:
Trojan = disguised malware [OK]
- Confusing ransomware with Trojan
- Thinking Trojan self-replicates
- Mixing virus and Trojan definitions
Solution
Step 1: Identify malware behavior described
The malware encrypts files and demands payment to restore access.Step 2: Match behavior to malware type
Ransomware is known for encrypting files and demanding ransom.Final Answer:
Ransomware -> Option AQuick Check:
Encrypts files + demands money = Ransomware [OK]
- Confusing ransomware with virus
- Thinking Trojan encrypts files
- Mixing worm behavior with ransomware
Solution
Step 1: Analyze malware behavior
The malware attaches to files and spreads when files are shared, causing crashes and slowdowns.Step 2: Identify malware type matching this behavior
Viruses attach to files and spread through sharing, unlike worms which spread independently.Final Answer:
Virus -> Option BQuick Check:
Attaches to files + spreads by sharing = Virus [OK]
- Confusing worm with virus
- Thinking Trojan spreads by itself
- Mixing ransomware symptoms with virus
Solution
Step 1: Identify malware that spreads automatically
Worms spread automatically over networks without user action.Step 2: Identify malware disguised as useful software
Trojans appear as legitimate software but carry harmful payloads.Final Answer:
Worm and Trojan -> Option CQuick Check:
Auto-spread = Worm, disguised = Trojan [OK]
- Choosing ransomware instead of worm
- Mixing virus with Trojan
- Ignoring automatic spread behavior
