Single Linked List Concepts

Single Linked List Concepts

University

10 Qs

quiz-placeholder

Similar activities

"•Latar Belakang Manajemen Memori •Swap dan Alokasi Memori Berda

"•Latar Belakang Manajemen Memori •Swap dan Alokasi Memori Berda

University

10 Qs

Exploring Abstract Data Types

Exploring Abstract Data Types

University

10 Qs

Pertemuan 4

Pertemuan 4

University

11 Qs

AlgoWhiz Quiz

AlgoWhiz Quiz

University

15 Qs

Data Structures

Data Structures

University

10 Qs

Linked Lists

Linked Lists

University

5 Qs

In-Lab5

In-Lab5

University

14 Qs

Exploring C++, Data Structures, and HTML

Exploring C++, Data Structures, and HTML

12th Grade - University

10 Qs

Single Linked List Concepts

Single Linked List Concepts

Assessment

Quiz

Other

University

Hard

Created by

Shoba LK

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the basic structure of a node in a single linked list?

A node in a singly linked list consists of multiple data fields without any pointers.

A node in a singly linked list contains only a data field.

A node in a singly linked list has a data field and a pointer to the next node.

A node in a singly linked list has two pointers, one for the next node and one for the previous node.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Write pseudocode to insert a node at the beginning of a single linked list.

function addNodeToEnd(head, newData) { newNode = new Node(newData); if (head == null) { head = newNode; } else { current = head; while (current.next != null) { current = current.next; } current.next = newNode; } return head; }

function insertAtPosition(head, newData, position) { newNode = new Node(newData); if (position == 0) { newNode.next = head; head = newNode; return head; } current = head; for (i = 0; i < position - 1 && current != null; i++) { current = current.next; } newNode.next = current.next; current.next = newNode; return head; }

function insertAtBeginning(head, newData) { newNode = new Node(newData); newNode.next = head; head = newNode; return head; }

function deleteFromBeginning(head) { if (head == null) return null; head = head.next; return head; }

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Describe the pseudocode for inserting a node at the end of a single linked list.

1. Create a new node. 2. If head is null, set head to new node. 3. Else, set current to head. 4. While current.next is not null, set current to current.next. 5. Set current.next to new node.

1. Create a new node. 2. If head is not null, set head to new node. 3. Set current to head. 4. While current.next is null, set current to current.next. 5. Set current.next to new node.

1. Create a new node. 2. Set head to null. 3. Set current to tail. 4. While current is not null, set current to current.previous. 5. Set current.previous to new node.

1. Create a new node. 2. Set head to new node. 3. Set current to head. 4. While current.next is null, set current to current.next. 5. Set current.next to null.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the pseudocode for deleting a node from a single linked list?

Set head.next = head to delete the node.

1. If head is null, return. 2. If head is the node to delete, set head = head.next. 3. Initialize current = head. 4. While current.next is not null: 5. If current.next is the node to delete: 6. Set current.next = current.next.next. 7. Return.

If head is null, set head to the node to delete.

Traverse the list and print each node's value.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Explain how to traverse a single linked list and write the pseudocode for it.

Print currentNode.next.value

Pseudocode: 1. Set currentNode = head 2. While currentNode is not null: a. Print currentNode.value b. Set currentNode = currentNode.next

While currentNode is null:

Set currentNode = tail

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the time complexity of traversing a single linked list?

O(1)

O(n^2)

O(n)

O(log n)

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Write pseudocode to search for a value in a single linked list.

function locateValue(head, target) { current = head; if (current.value == target) { return current; } return null; }

function searchList(head, target) { for (let node of head) { if (node.value == target) { return node; } } return null; }

function findInList(head, value) { while (head != null) { if (head.value != value) { head = head.next; } } return head; }

function searchLinkedList(head, target) { current = head; while (current != null) { if (current.value == target) { return current; } current = current.next; } return null; }

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?