Dynamic data structures and linked lists in Java

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the difference between a dynamic data structure and a static data structure? Why would someone use a static structure over a dynamic one?

A dynamic structure doesn't have a fixed structure size like static structures do, and dynamic structure can consume additional memory if need be. A static structure is useful for creating a code for a fixed number of data items.

What is a linked list?

A linked list is a data structure consisting of a group of nodes representing a sequence. Each node is composed of data and a link to the next node, allowing for the easy insertion or removal of any nodes or elements in the sequence.

What's the difference between a single and doubly linked list? Multiply and circular linked lists?

A single linked list just has node connected sequentially forwards. In a doubly linked list, the nodes connect forwards, and also backwards to the previous nodes. In multiply linked lists, each node contains 2+ link fields, each being used to connect the same set of data records in a different order. In a circular linked list, the last node is pointed back to the first one.

In which type of an structure does the code compile faster?

A static structure will compile faster as the compiler will know the exact data types immediately.

What are the advantages and disadvantages of a linked list?

Advantages-They are dynamic, insertion and deletion are easy and linear data structures are easily performed. Disadvantages-Tendency to use larger amounts of memory, must be read from the beginning of the list, hard to navigate backwards.

What type of data structure is an array?

An array is a static data structure, as their memory footprint remains constant over time.

Define an iterator.

An iterator is any object that allows you to step through a collection of data items one at a time in a reasonable way, where each item is visited once in a full cycle of iterations and each item can have its data read and changed if need be.

Compare and contrast arrays and linked lists.

Arrays, unless they are dynamic arrays, are static, so they can only use set amounts of memory and don't change depending on the process. However, static and dynamic arrays both allow random access, while linked lists can only be accessed sequentially and it's hard to access individual elements individually with linked lists. In a linked list, insertion and deletion can occur easily, whereas such operations would be more lengthy and time consuming with arrays.

What output is produced by the following code? StringLinkedList list= new StringLinkedList(); list.addANodeToStart("A"): list.addANodeToStart("B")' list.addANodeToStart("C"); list.showList();

C B A

True of false: All nodes are named.

False. Most nodes have no name. The first node is called the head node.

What is the utility behind a dynamic data structure?

It allows the programmer to control exactly how much memory is used in a program, changing in size depending on what is called for in the code.

Describe one scenario in the real-world in which a dynamic data structure would be applicable.

One real-world application of dynamic data structures could be using a code with a dynamic structure for online shopping. Since the periods of traffic for online shopping sites aren't fixed, a programmer could use a dynamic structure for the processes involved in the online shopping experience such as processing payment information, giving more memory allocated to processes during periods of high traffic and less during periods of low traffic.

Define overflow and underflow and describe how they relate to dynamic data structures.

Overflow-Where the data transferred into a buffer exceeds the storage capacity and another buffer is used for the overflow data. This can corrupt or negatively harm the data in the buffer used for overflow. Underflow-When a buffer is fed with data at too low a speed. Program running must pause to refill the buffer. This is related to dynamic data structures because these are both errors that can occur if the memory allocation isn't monitored correctly in the dynamic structure, and it's something for a programmer to look for when writing the code to monitor the location and speed of data.

Are iterators applicable to linked lists? How so?

They are, as they can go through data at nodes and change it or insert/delete it.

True or false: Arrays can hold objects of a specific type.

True. Arrays can only hold objects of one type. An array can hold objects of type object to get around this.

True or False: Instances of all objects share a static variable.

True. The definition of a static variable is that there is only one for the entire class.

What happens to a Deleted Node?

When your code deletes a node, it removes the reference to that node, making the storage it occupied available to other nodes automatically, a process called automatic garbage recycling, something not present in al languages.

How do mark the end of a linked list?

You indicate the end of a linked list by setting the link instance variable of the last node to null.

Assume that the variable head is supposed to contain a reference to the first node in a linked list and that the linked list is empty. What value should head have?

head should have the value null.

Draw/sketch out an example of a single linked list.

http://i.stack.imgur.com/wcOsV.png


Set pelajaran terkait

Chapter 6 - PSYC 2301 - Learning

View Set

Google Analytics Certification Exam

View Set

Nature Spirituality and Pop Culture Midterm Study Set

View Set

Compensation and Performance Final

View Set

C708 - Principles of Finance - Module Quizzes/Unit Tests

View Set

NETWORKING CHAPTER 6,7,8 (TEST OUT) - Practice Questions

View Set