Question

Answer the following questions: • Compare and contrast arrays and linked-lists. What are the advantages and...

Answer the following questions:

• Compare and contrast arrays and linked-lists. What are the advantages and disadvantages of either data structure?

• Describe why binary search is more effective for finding an element in the array rather than searching through it in a linear fashion. Under what circumstances can binary search work correctly?

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

Arrays:-

An array is the linear data structure with a collection of similar type of data. It's size if fixed and all element in an array in a contiguous memory location. Memory allocation happens in compile time.

LinkedList:-

LinkedList is the linear data-structure where you can store any type of data. It's dynamic in size and it stores the element in a node(which has two-part 1.data-> to store value 2.pointer to next node ) in a non-contiguous memory location. Memory allocation happens in run time.

Advantage of Linked List:

1. Dynamic nature:- The size of linked List is dynamic in nature i.e we can increase and decrease the size of LinkedList according to our need but in case of an array, you can declare size only once.

2. Easy to insert and delete element:- In linked list to insert/delete an element at a specific location you just have to update the pointer of previous and next node but in the case to array you have to shift all the element.

Disadvantage of Linked List:

1. In LinkedList to store every element, we need an extra pointer to store the address of the next node.

2. To access the particular element in LinkedList you have to do liner search but an array, you can directly go to a specific location by array_name[location]

Binary search is more effective than linear search because of the less time complexity to find the element. If you search the element in a linear fashion then the time complexity will be O(n) and if you go for binary search then time complexity will O(logn).

Binary search work correctly only when an element is in sorted order. Then only you will get the correct value because binary search follows the method where it will compare the middle element with the element we want to find if the value will be same then it will give the result and if the middle element is greater than element then it search the element in the left side else in right side part.

Add a comment
Know the answer?
Add Answer to:
Answer the following questions: • Compare and contrast arrays and linked-lists. What are the advantages and...
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
  • 1. Compare and contrast: SORTING -a bubble sort through an array -a selection sort through an...

    1. Compare and contrast: SORTING -a bubble sort through an array -a selection sort through an array Explain how each works and what the advantages and disadvantages are. Note the efficiency of each. 2. Compare and contrast: SEARCHING -a sequential search through a file -a sequential search through an array -a binary search through an array Explain how each works and what the advantages and disadvantages are. Note the efficiency of each.

  • queues can be modeled as arrays or linked lists. describe the advantages and disadvantages of doing...

    queues can be modeled as arrays or linked lists. describe the advantages and disadvantages of doing this. Focus on the operations permitted, time and space restrictions etc. Draw diagrams if necessary.

  • Short Answer. Under what conditions are adding or removing an element in a linked structure an...

    Short Answer. Under what conditions are adding or removing an element in a linked structure an O(1) operation? Under what conditions are adding or removing an element in an array-based structure an O(1) operation? How does the memory usage of an array-based structure compare to a linked structure? what structure/implementation would be the best choice for managing a collection where the order is not important, but the user needs frequent access to elements within the collection? Explain your choice.

  • Interfaces 1. What is inside an interface definition? What does a class do to an interface...

    Interfaces 1. What is inside an interface definition? What does a class do to an interface and what keyword is involved? How does a class do this to an interface (what should we find in the class)? Can an interface have a generic parameter? How do you instantiate an interface as an object? What methods can’t you use on an interface type? Abstract Data Types 2. What does an ADT define? Does an ADT specify programming language and/or data structures...

  • Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes...

    Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes arranged as binary trees. For these questions, use the following struct definition for the nodes of the tree (we will not templatize the node here, so you do not have to write template functions for these questions, just assume trees of <int> values): struct BinaryTreeNode { int item; BinaryTreeNode* left; BinaryTreeNode* right; }; ---------------------------------------------- Given a node for a Binary Tree and an (integer)...

  • SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what...

    SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...

  • With the following code answer the following questions. describe what happens when the following code is...

    With the following code answer the following questions. describe what happens when the following code is executed: String[] searchMe = {"apple","bear","cat","dog","elephant"}; describe what is being created when this statement executes System.out.println(linearFind("cat",searchMe)); describe the values passed to the method describe how each of the specific values are compared to each other describe when the method stops executing and/or when the loop stops executing describe what is returned to beoutprinted System.out.println(binaryFind("apple",searchMe)); describe the values passed to the method describe how each of...

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

    I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...

  • 1 of 1 E-COMMERCE (ICT 321) ASSIGNMENT INSTRUCTION: Answer the following questions, save with your name...

    1 of 1 E-COMMERCE (ICT 321) ASSIGNMENT INSTRUCTION: Answer the following questions, save with your name and index number, and submit on the e-learning portal in PDF format not later than 26 May, 2020, 6:00pm. Answers for each question should not exceed two (2) typed pages. 1. Select an e-commerce company. Visit its Web site and describe its business model based on the information you find there. Identify its customer value proposition, its revenue model, the marketspace it operates in,...

  • Part 1-Please answer the following essay questions 1. We discussed the advantages and disadvantag...

    Part 1-Please answer the following essay questions 1. We discussed the advantages and disadvantages of internal recruiting, interviews and reference checks (and the entire hiring process). Please identify ONE disadvantage of each of these three activities -- and explain why you believe they are "disadvantages." 2. Choose ONE interview question listed below and answer it on paper as if it was being asked of you in a face-to-face interview. Please identify the Interview Question #. Details, details, details are necessary...

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