Question

Even though linked lists are the simplest data structures, you can build with them complicated networks,...

Even though linked lists are the simplest data structures, you can build with them complicated networks, trees and graphs. Please do a research and share your findings with us. Pay special attention to include their time complexities. It is not required but a couple of code snippets would look nice in the examples.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For tree,

Binary Tree –
In a binary tree, a node can have maximum two children.

Searching: Searching in binary tree has worst case complexity of O(n).

Insertion: Insertion in binary tree has worst case complexity of O(n).

Deletion: Deletion in binary tree has worst case complexity of O(n).


Binary Search Tree (BST) –
BST is a special type of binary tree in which left child of a node has value less than the parent and right child has value greater than parent.

Searching: Searching in binary search tree has worst case complexity of O(n). In general, time complexity is O(h) where h is height of BST.

Insertion: Worst case complexity of O(n). In general, time complexity is O(h).

Deletion: Deletion in binary tree has worst case complexity of O(n). In general, time complexity is O(h).

AVL/ Height Balanced Tree –
AVL tree is binary search tree with additional property that difference between height of left sub-tree and right sub-tree of any node can’t be more than 1.

Searching: Searching in AVL tree has worst case complexity of O(log2n).
Insertion: Worst case complexity is O(log2n).

Deletion: Deletion in binary tree has worst case complexity of O(log2n).

------------------------------------------------------------------

For Graph (ADJACENCY LIST)

Simple c++ code for graph

// A simple representation of graph using STL
#include<bits/stdc++.h>
using namespace std;

// A utility function to add an edge in an
// undirected graph.
void addEdge(vector<int> adj[], int u, int v)
{
   adj[u].push_back(v);
   adj[v].push_back(u);
}

// A utility function to print the adjacency list
// representation of graph
void printGraph(vector<int> adj[], int V)
{
   for (int v = 0; v < V; ++v)
   {
       cout << "\n Adjacency list of vertex "
           << v << "\n head ";
       for (auto x : adj[v])
       cout << "-> " << x;
       printf("\n");
   }
}

// Driver code
int main()
{
   int V = 5;
   vector<int> adj[V];
   addEdge(adj, 0, 1);
   addEdge(adj, 0, 4);
   addEdge(adj, 1, 2);
   addEdge(adj, 1, 3);
   addEdge(adj, 1, 4);
   addEdge(adj, 2, 3);
   addEdge(adj, 3, 4);
   printGraph(adj, V);
   return 0;
}

Pros: Saves space O(|V|+|E|) . In the worst case, there can be C(V, 2) number of edges in a graph thus consuming O(V^2) space. Adding a vertex is easier.

Cons: Queries like whether there is an edge from vertex u to vertex v are not efficient and can be done O(V).

Add a comment
Know the answer?
Add Answer to:
Even though linked lists are the simplest data structures, you can build with them complicated networks,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games...

    Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games One of the nice things about Java is it is very easy to do fun things with graphics. The start code provided here will display a deck of cards on the screen and shuffle them. Your mission, is to start with this code and build a card game. Blackjack, poker solitaire, what ever your heart desires. Blackjack is the easiest. Obviously any program you...

  • Read this article. Then write a 250 word response on two of the programs you like...

    Read this article. Then write a 250 word response on two of the programs you like the most. Open source business intelligence software 1. BIRT BIRT is an open source BI program that CloudTweaks says is often viewed as the industry standard. BIRT boasts “over 12 million downloads and over 2.5 million developers across 157 countries.” Its users include heavyweights such as Cisco, S1, and IBM (which is also a BIRT sponsor). They also have maturity going for them, as...

  • The world’s 3 billion-plus smartphones emit the kind of data that health authorities covet during outbreaks....

    The world’s 3 billion-plus smartphones emit the kind of data that health authorities covet during outbreaks. They show where individuals are, where they’ve been and who they might have talked to or even touched — potentially offering maps to find infected people and clues to stopping new ones. But gaining access to this data, even amid a global pandemic, is made complex by the legal and ethical issues surrounding government access to information that can reveal intimate details about citizens’...

  • Read the articles provided (Riggio, 2008) and Javidan & Walker (2012). Perform a self-assessm...

    Read the articles provided (Riggio, 2008) and Javidan & Walker (2012). Perform a self-assessment of the global mindset competencies. What competencies do you feel are your strengths? Your areas for improvement? What next learning steps could you take to address your areas for improvement? LEADERSHIP DEVELOPMENT: THE CURRENT STATE AND FUTURE EXPECTATIONS Ronald E. Riggio Claremont McKenna College This article discusses the common themes in this special issue of Consulting Psychology Journal on "Leadership Development" and summarizes some of the...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • And there was a buy-sell arrangement which laid out the conditions under which either shareholder could...

    And there was a buy-sell arrangement which laid out the conditions under which either shareholder could buy out the other. Paul knew that this offer would strengthen his financial picture…but did he really want a partner?It was going to be a long night. read the case study above and answer this question what would you do if you were Paul with regards to financing, and why? ntroductloh Paul McTaggart sat at his desk. Behind him, the computer screen flickered with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT