1) The document discusses several common linked list problems and their solutions including deleting a node, removing the nth node from the end, reversing a linked list, merging two sorted lists, determining if a linked list is a palindrome, and detecting cycles in a linked list.
2) Key techniques mentioned for solving linked list problems include using a dummy node, two pointers (one fast and one slow), and recursion.
3) Example code solutions are provided for each problem in Java using classes and methods like ListNode, deleteNode, removeNthFromEnd, and isPalindrome.
using the single linked list code written in the class or in the lab,.pdfRBMADU
using the single linked list code written in the class or in the lab, write and test the follow
function: Merge() function that takes two lists, each of which is sorted in increasing order, and
merges the two together into one list which is in increasing order.
Solution
//The main class
class MergeList {
Node head; // head of list
static Node a, b;
//Node class
static class Node {
int element;
Node next;
// Constructor to create a new node
Node(int d) {
element = d;
next = null;
}
}
void printlist(Node node) {
while (node != null) {
System.out.print(node.element + \" \");
node = node.next;
}
}
Node sortMerge(Node node1, Node node2) {
// Here we will check whether both the list are null or not.
if (node1 == null && node2 == null) {
return null;
}
// sortResultant node
Node sortRes = null;
// Now we will compare and merge the elements of both the list.
while (node1 != null && node2 != null) {
// We will compare current element of both lists
if (node1.element >= node2.element) {
Node temp = node1.next;
node1.next = sortRes;
sortRes = node1;
node1 = temp;
} else {
Node temp = node2.next;
node2.next = sortRes;
sortRes = node2;
node2 = temp;
}
}
// If second list reached end, but first list has
// nodes. Add remaining nodes of first list at the
// front of sortResult list
while (node1 != null) {
Node temp = node1.next;
node1.next = sortRes;
sortRes = node1;
node1 = temp;
}
// If first list reached end, but second list has
// node. Add remaining nodes of first list at the
// front of sortResult list
while (node2 != null) {
Node temp = node2.next;
node2.next = sortRes;
sortRes = node2;
node2 = temp;
}
return sortRes;
}
public static void main(String[] args) {
MergeList list = new MergeList();
Node sortResult = null;
//Create two linked list
list.a = new Node(5);
list.a.next = new Node(10);
list.a.next.next = new Node(15);
list.b = new Node(2);
list.b.next = new Node(3);
list.b.next.next = new Node(20);
System.out.println(\"List a before merge :\");
list.printlist(a);
System.out.println(\"\");
System.out.println(\"List b before merge :\");
list.printlist(b);
// Cal the function to merge the list in increasing order.
sortResult = list.sortedmerge(a, b);
System.out.println(\"\");
System.out.println(\"Merged linked list : \");
list.printlist(sortResult);
}
}.
Problem 1 Create Node class (or use what you have done in Lab4)• .pdfmumnesh
Problem 1: Create Node class (or use what you have done in Lab4)
• Add methods to get and set, Data and Link
• Here the data is an object. (java object) your Linked List can hold any java class.
a) Create MyLinkedList2 class and write methods to
• Methods to insert nodes at the beginning, at the end and at a specific position. insertFirst(Node
x), insertLast(Node x) , insertLast(Node x, int pos)
• Methods to delete node from the beginning and from the end. delFirst(), delLast()
• Method to search the Linked List for a specific object. searchList(x Object)
• Method to Sort the Linked List in ascendant or descendant order according to the object
value(s). for example sorted by name, by age, by gpa. sortAsc(),sortDesc().
• Method to display all nodes objects (printing an object is related to its toString() method).
• Method to return the largest and smallest object in the list – maxList(), minList() according to
some specific object members.
. • Method to return the number of nodes – listSize()
• Method to merge two linked Lists into one. MyLinkedList2 list3= mergeList(MyLinkedList2
list1, MyLinkedList2 list2)
b) Create Main class : MyLinkedList2Demo
• Create a linked List LL1 and insert some objects to it. Use any a student java class.
• Fill LL1 by adding students from an input file.
• Display all the objects (students) in the List LL1
• Search for a particular object (Student by name or by Id or both) in LL1 and print true or false
• Sort LL1 and display it ( using asc and desc on multiple members)
• Perform all the delete methods on LL1.
• Perform all the insert methods on LL1.
• Call and run all the implemented methods in a sequential order. NB: Organize a nice output for
all the questions above.
Problem 2: Same as Pb1 using double linked lists. Create Nod3e and MyLinkedList3 classes.
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------
The input file :
id fname lname age gpa year college cuCourses totalCourses
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201112345 Amna chamisi 17 2.1 2014 ENG 31 32
201412345 Amna chamisi 17 2.1 2014 COE 5 29
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
201412345 Amna chamisi 17 2.1 2014 CIT 5 30
Solution
/**
* Node.java
* @author
*
*/
public class Node {
public Object getObj() {
return obj;
}
public Node setObj(Object obj) {
this.obj = obj;
return this;
}
public Node getNext() {
return next;
}
public Node setNext(Node next) {
this.next = next;
return this;
}
private Object obj;
private Node next;
}
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
/**
* MyLinkedList2.java
* @author
*
*/
public class MyLinkedList2 {
public void insertFirst(Node x) {
if (head == null) {
head = x;
} else {
x.setNext(head);
}
}
public void insertLast(Node x) {
if (head == null) {
head = x;
r.
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
Data Structures in C++
I am really new to C++, so links are really hard topic for me. It would be nice if you can provide
explanations of what doubly linked lists are and of some of you steps... Thank you
In this assignment, you will implement a doubly-linked list class, together with some list
operations. To make things easier, you’ll implement a list of int, rather than a template class.
Solution
A variable helps us to identify the data. For ex: int a = 5; Here 5 is identified through variable a.
Now, if we have collection of integers, we need some representation to identify them. We call it
array. For ex: int arr[5]
This array is nothing but a Data Structure.
So, a Data Structure is a way to group the data.
There are many Data Structures available like Arrays, Linked List, Doubly-Linked list, Stack,
Queue, etc.
Doubly-Linked list are the ones where you can traverse from the current node both in left and
right directions.
Why so many different types of Data Structures are required ?
Answer is very simple, grouping of data, storage of data and accessing the data is different.
For example, in case of Arrays we store all the data in contiguous locations.
What if we are not able to store the data in contiguous locations because we have huge data.
Answer is go for Linked List/Doubly-Linked list.
Here we can store the data anywhere and link the data through pointers.
I will try to provide comments for the code you have given. May be this can help you.
#pragma once
/*
dlist.h
Doubly-linked lists of ints
*/
#include
class dlist {
public:
dlist() { }
// Here we are creating a NODE, it has a integer value and two pointers.
// One pointer is to move to next node and other to go back to previous node.
struct node {
int value;
node* next;
node* prev;
};
// To return head pointer, i.e. start of the Doubly-Linked list.
node* head() const { return _head; }
// To return Tail pointer, i.e. end of the Doubly-Linked list.
node* tail() const { return _tail; }
// **** Implement ALL the following methods ****
// Returns the node at a particular index (0 is the head).
node* at(int index){
int cnt = 0;
struct node* tmp = head();
while(tmp!=NULL)
{
if (cnt+1 == index)
return tmp;
tmp = tmp->next;
}
}
// Insert a new value, after an existing one
void insert(node *previous, int value){
// check if the given previous is NULL
if (previous == NULL)
{
printf(\"the given previous node cannot be NULL\");
return;
}
// allocate new node
struct node* new_node =(struct node*) malloc(sizeof(struct node));
// put in the data
new_node->data = new_data;
// Make next of new node as next of previous
new_node->next = previous->next;
// Make the next of previous as new_node
previous->next = new_node;
// Make previous as previous of new_node
new_node->prev = previous;
// Change previous of new_node\'s next node
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
// Delete the given node
void del(node* which){
struct node* head_ref = head();
/* base case */
if(*head_ref == NUL.
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
Java Assignment
Using the ListNode.java file below
Write methods called min and max that return the smallest and largest values in the linked list.
These methods will be added to your ListNode class. For example if a variable called list stores
{11, -7, 3, 42, 0, 14], the call of list.min() should return -7 and the call of list.max() should return
42. If the list is empty, return -1. Print the returned value.
Write a method called insertNode that inserts a new node anywhere in your linked list. Display
your linked list with new value.
Write a program to test these methods to ensure accuracy and successful implementation. Upload
your modified version of the ListNode java file only.
Note: Original code should still be included. You will make additions and slight modifications
where necessary. Throw exceptions where you think is necessary. // Listlode is a class for storing
a single node of a linked // list. This node class is for a list of integer values. public class Listlode
\{ public int data; //data stored in this node public Listliode front;//points to head node public
Listliode next; /f link to next node in the list // post: constructs a node with data and null link
public Listlode() \{ 3. // post: constructs a node with given data and null link: public Listlode(int
data) \{ this(data, null); 3 // post: constructs a node with given data and given link. public
Listlode(int data, Listliode next) \{ this.data = data; this. next = next; 3 public String toString() \{
if (front = null) : \} else \{ String result = " ["+ front data; Listliode current = front. next; while
(current != null) \{ result +=m,m+ current data, current = current. next; 3 result += " ]n - return
result; 3. }// post: appends the given value to the end of the list public void add(int value) \&
puolic void aod if (front = nult) \{. front = new Listlode (value); 3 else \{ Listlode current =
front; whistiode current = front; while (current next I= null) \{ current = current. next; 3 current.
next = new Listliode (value ); 3. 3 J// post : returns the position of the first occurrence of the
given /l value (-1 if not found ) public void remove (int index) \{ if ( index =){ \} else \{ Listiode
current = nodeAt ( index - 1); current. next = current. next. next, 3 3 3// pre : <=i< size() // post:
returns a reference to the node at the given index public Listlode nodeAt (int index) : List Node
current = front; for (int i=0;i< index; i++) \{ current = current. next. \}. return current; 3.
Write a function to merge two doubly linked lists. The input lists ha.pdfinfo706022
Write a function to merge two doubly linked lists. The input lists have their elements in sorted
order, from lowest to highest. The output list should also be sorted from lowest to highest. Your
algorithm should run in linear time on the length of the output list. Provide an algorithm for your
function Implement and show some samples of your running function
Solution
The algorithm for LinkedList MergeSort is as follows.
The trick in this algorithm is to use a local list to store the value which is pointing to the actual
list to be returned as a result of the function
Step1: START
Step2: GET inputs of list1 and list2
Step3: INITIALIZE mergelist
STEP4: SET mylist = mergelist
Step5: WHILE list1 OR list2 is EMPTY
DO
IF (list1 AND list2) are NOT EMPTY
IF list1.value > list2.value
mylist.next = list2
ELSE
mylist.next = list1
ELSE IF list1 is EMPTY
mylist.next = list2
ELSE
mylist.next = list1
Step6: RETURN mergelist
Step7: STOP
Sample program for the same implemented in C++
//====================================================================
========
// Name : DoublyLinkedList.cpp
// Author : Kaju
// Version : 0.1
// Copyright : This is just an example code
// Description : MergeSort in C++, Ansi-style
//====================================================================
========
/*
* C++ Program to Implement Doubly Linked List
*/
#include
#include
#include
/*
* Node Declaration
*/
using namespace std;
// struct declaration for node which will hold the integer data with links to previous data and next
data
struct node
{
int data;
struct node *next;
struct node *prev;
};
/*
Class Declaration
*/
class DoublyLinkedList
{
private:
struct node *start; // collection of all the nodes
public:
void create(int value);
int peek();
int delete_head();
void display();
int count();
void mergeSort(DoublyLinkedList list1, DoublyLinkedList list2);
DoublyLinkedList()
{
start = NULL;
}
};
/*
* Add data into the list
*/
void DoublyLinkedList::create(int value)
{
struct node *s, *temp;
temp = new(struct node);
temp->data = value;
temp->next = NULL;
if (start == NULL)
{
temp->prev = NULL;
start = temp;
}
else
{
s = start;
while (s->next != NULL)
s = s->next;
s->next = temp;
temp->prev = s;
}
}
/*
* Deletion of the first element from the list
* store the first element in a temp node and then remove it from start.
*/
int DoublyLinkedList::delete_head()
{
struct node *tmp, *q;
int value;
tmp = start;
if(start->next!=NULL)
{
start = start->next;
start->prev = NULL;
}
else
start = NULL;
value = tmp->data;
free(tmp);
return value;
}
/*
* return the first element of Doubly Link List
*/
int DoublyLinkedList::peek()
{
struct node *q;
if (start == NULL)
{
cout<<\"List is empty\"<data;
}
}
/*
* Display elements of Doubly Link List
*/
void DoublyLinkedList::display()
{
struct node *q;
if (start == NULL)
{
cout<<\"List is empty\"<data;
q = q->next;
if(q != NULL)
{
cout<<\", \";
}
}
cout<<\"]\"<next;
cnt++;
}
return cnt;
}
/*
* MergeSort - takes two input lists and then based on the.
here is the starter code public class LinkedListPracticeLab.pdfgeetakannupillai1
here is the starter code:
public class LinkedListPracticeLab {
private LinkedListPracticeLab(){}
public static void main(String[] args) {
// Test all methods here
}
/**
* Given the heads of two sorted linked lists, merges the two lists in a one
sorted list.
* The list is made by splicing together the nodes of the original two lists,
without
* creating any new nodes.
*
* Returns the head of the merged linked list.
*/
public static ListNode mergeLists(ListNode head1, ListNode head2) {
return null;
}
/**
* Given the head of a sorted linked list, deletes all duplicates such that
each element appears only once.
*
* Returns the head of the resulting linked list, which is still sorted.
*/
public static ListNode deleteDuplicates(ListNode head) {
return null;
}
/**
* Given the head of a linked list and an integer val, removes all the nodes of
the linked list that has
* Node.val == val.
*
* Returns the head of the resulting list.
*/
public static ListNode removeElements(ListNode head, int val) {
return null;
}
/**
* Given the head of a zero-indexed linked list and two indices i and j, swaps
the elements at these indices.
*
* Returns the head of the resulting list.
*/
public static ListNode swapElements(ListNode head, int i, int j) {
return null;
}
/**
* Given the head of a singly linked list, reverse the list, and return the
reversed list.
*/
public static ListNode reverseList(ListNode head) {
return null;
}
/**
* Given the head of a singly linked list, returns the middle node of the
linked list.
*
* If there are an even number of elements -- and thus two middle nodes --
returns the second middle node.
*/
public static ListNode middleNode(ListNode head) {
return null;
}
}
list node.java code:
/**
* Definition for singly-linked list.
*/
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
List utils.java code
/**
* Utilities for singly-linked non-circular lists.
*/
public class ListUtils {
private ListUtils() {}
static ListNode copyList(ListNode list) {
ListNode head = new ListNode(list.val);
ListNode currentNew = head;
ListNode currentOld = list.next;
while(currentOld != null) {
currentNew.next = new ListNode(currentOld.val);
currentNew = currentNew.next;
currentOld = currentOld.next;
}
return head;
}
static void displayList(ListNode list) {
if(list == null) {
System.out.println("[]");
return;
}
StringBuilder sb = new StringBuilder();
sb.append('[');
while(list != null) {
sb.append(list.val);
sb.append(',');
sb.append(' ');
list = list.next;
}
sb.delete(sb.lastIndexOf(","), sb.length());
sb.append(']');
System.out.println(sb);
}
static ListNode arrayToLinkedList(int[] arr) {
if(arr.length == 0)
return null;
ListNode head = new ListNode(arr[0]);
ListNode current = head;
for(int i = 1; i < arr.length; i++) {
current.next = new ListNode(arr[i]);
current = current.next;
}
return head;
}
}
For this lab you will solve a few separate problem.
Golang, Future of Programming Language.Sunil Yadav
Google's Golang, programming language, that is more efficient and promising language in terms of usability and performance.
It beats Java and Python in most of the computations.
React Js Basic Details and Descriptions
Frontend Javascript Library, to make decent SPA
The fastest way to build a segregated component based front end for software development.
Docker with Micro Service and WebServicesSunil Yadav
Docker Containerizing for Microservices with Swarm Orchestration. General Containerizing Procedure for Microservices.
With Services and Network Features of Docker
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
2. Linked List problems are relatively easy to master. Do
not forget the Two-pointer technique, which not only
applicable to Array problems but also Linked List
problems as well.
Another technique to greatly simplify coding in linked
list problems is the dummy node trick.
We recommend: Reverse Linked List, Merge Two
Sorted Lists and Linked List Cycle.
For additional challenge, solve these problems
recursively: Reverse Linked List, Palindrome Linked List
and Merge Two Sorted Lists.
IntroductION
3. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only
access to that node.
Given linked list -- head = [4,5,1,9], which looks like following:
Example 1:
Input: head = [4,5,1,9], node = 5
Output: [4,1,9]
Explanation: You are given the second node with value 5, the
linked list should become 4 -> 1 -> 9 after calling your
function.
Example 2:
Input: head = [4,5,1,9], node = 1
Output: [4,5,9]
Explanation: You are given the third node with value 1, the
linked list should become 4 -> 5 -> 9 after calling your
function.
Note:
• The linked list will have at least two elements.
• All of the nodes' values will be unique.
• The given node will not be the tail and it will always be a valid node of the
linked list.
• Do not return anything from your function.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public void deleteNode(ListNode node) {
ListNode Prev = null;
while(node.next!=null){
node.val = node.next.val;
Prev = node;
node = node.next;
}
if(Prev!=null)
Prev.next = null;
}
}
4. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.
Example:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list
becomes 1->2->3->5.
Note:
Given n will always be valid.
Follow up:
Could you do this in one pass?
•
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode Prev = null;
ListNode fN = head;
ListNode slow = head;
int counter = 1;
while(head!=null){
if(counter>n){
Prev = slow;
slow = slow.next;
}
counter++;
head = head.next;
}
if(Prev!=null){
if(slow!=null)
Prev.next = slow.next;
else
Prev.next = null;
}
if(Prev == null){
return fN.next;
}
return fN;
}
}
5. Reverse Linked List
Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Follow up:
A linked list can be reversed either iteratively or recursively. Could you implement
both?
•
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
ListNode root = head;
ListNode Prev = null;
while(head!=null){
ListNode nextNode = head.next;
head.next = Prev;
Prev = head;
head = nextNode;
}
return Prev;
}
}
6. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new sorted list. The new list should
be made by splicing together the nodes of the first two lists.
Example:
Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode x = l1;
ListNode y = l2;
ListNode result = new ListNode(-1);
ListNode fR = result;
while(x!=null && y!=null){
if(x.val <= y.val){
result.next = new ListNode(x.val);
x = x.next;
}else{
result.next = new ListNode(y.val);
y = y.next;
}
result = result.next;
}
if(x!=null){
result.next = x;
result = result.next;
}
if(y!=null){
result.next = y;
result = result.next;
}
return fR.next;
}
7. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.
Example 1:
Input: 1->2
Output: false
Example 2:
Input: 1->2->2->1
Output: true
Follow up:
Could you do it in O(n) time and O(1) space?
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public boolean isPalindrome(ListNode head) {
ListNode slow = head;
ListNode fast = head;
while(fast!=null && fast.next!=null){
slow = slow.next;
fast = fast.next.next;
}
Stack<ListNode> stack = new Stack<>();
// Slow is at Middle Position
while(slow!=null){
stack.push(slow);
slow = slow.next;
}
while(!stack.isEmpty()){
if(head.val!=stack.pop().val){
return false;
}
head = head.next;
}
return true;
}
}
8. Linked List Cycle
Given a linked list, determine if it has a cycle in it.
To represent a cycle in the given linked list, we use an integer pos which
represents the position (0-indexed) in the linked list where tail connects to.
If pos is -1, then there is no cycle in the linked list.
Example 1:
Input: head = [3,2,0,-4], pos = 1
Output: true
Explanation: There is a cycle in the linked list, where tail
connects to the second node.
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public boolean hasCycle(ListNode head) {
if(head == null){
return false;
}
ListNode slow = head;
ListNode fast = head.next;
while(true){
if(slow==null || fast==null){
return false;
}
if(slow==fast){
return true;
}
slow = slow.next;
if(fast.next==null){
return false;
}
fast = fast.next.next;
}
}
}