Other Websites

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

How to create pointers to structs?

(C lang)

Linked lists

Are often used because of their efficient insertion and deletion. They can be used to implement stacks, queues, and other abstract data types.

Linked list drawback in backward traversal

Because ____________ are inherently sequential in the forward direction, operations like backward traversal--visiting every node starting from the end and ending in the front--is especially cumbersome.

pop operation

Deletion of element from the stack

A Linear data structure

Has data elements arranged in sequential manner and each member element is connected to its previous and next element. This connection helps to traverse a linear data structure in a single level and in single run. Such data structures are easy to implement as computer memory is also sequential. Examples of _________ are List, Queue, Stack, Array etc.

Non-linear Data Structures

Has no set sequence connecting all its elements and each element can has multiple paths to connect to other elements. Such data structures supports multi-level storage and often cannot be traversed in single run. Such data structures are not easy to implement but are more efficient in utilizing computer memory. Examples of __________ are Tree, BST, Graphs etc.

Address of the first node name

Head

Linked lists time complexity (accessing data)

However, unlike dynamic arrays, accessing the data in these nodes takes linear time because of the need to search through the entire list via pointers. It's also important to note that there is no way of optimizing search in linked lists.

Creating a struct "person" with age and weight, later creating a pointer than gets values for age and weight, and then prints them.

In this example, the address of person1 is stored in the personPtr pointer using personPtr = &person1; Now, you can access the members of person1 using the personPtr pointer.

push operation

Insertion of element into the stack

Stack

Is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top.

A queue

Is a linear data structure in which elements can be inserted only from one side of the list called rear, and the elements can be deleted only from the other side called the front.

How Next Node is Referenced?

Let's think about what each node contains: -A data item -An address of another node We wrap both the data item and the next node reference in a struct as:

Linked lists time complexity (insertion/deletion)

Linked lists have most of their benefit when it comes to the insertion and deletion of nodes in the list. Unlike the dynamic array, insertion and deletion at any part of the list takes constant time.

enqueue

The insertion of an element in a queue

What signifies that a linked list is at its end?

The last node, in this case 2, points to a null node.

Linked list vs array time complexity (accessing data) how is one more advantageous?

There is no way of optimizing search in linked lists. In the array, we could at least keep the array sorted. However, since we don't know how long the linked list is, there is no way of performing a binary search:

What information do linked lists hold per node?

They hold two main pieces of information (the value and pointer) per node.

Linked lists space complexity

They hold two main pieces of information (the value and pointer) per node. This means that the amount of data stored increases linearly with the number of nodes in the list. Therefore, the space complexity of the linked list is linear: O(n)

Why choose a linked list over another linear data structure?

They offer some important advantages over other linear data structures. Unlike arrays, they are a dynamic data structure, resizable at run-time. Also, the insertion and deletion operations are efficient and easily implemented.

Linked List memory drawback

Unlike an array whose values are all stored in contiguous memory, a _________'s nodes are at arbitrary, possibly far apart locations in memory. This means that the CPU can't effectively cache the contents of a _______ nearly as well as an array resulting in poor performance. This is the main reason why ring buffers are used to implement queues instead of linked lists in high-performance applications where middle insertion and deletion functionality isn't needed (e.g. network drivers).

Linked list drawbacks compared to arrays

Unlike arrays, __________aren't fast at finding the nth item. To find a node at position n, you have to start the search at the first node in the _______, following the path of references n times. Also, they use more storage than the array due to their property of referencing the next node in the ______.

dequeue

deletion of an element from a queue

fifo

first in first out

LIFO

last in first out


Set pelajaran terkait

Tissue Organization (Quiz #3) A and P

View Set

Intro to Business Study Guide (chapters 9-16)

View Set

FLVS Government Final Exam Study Guide

View Set

Condensed BUS Law Exam Review #1

View Set