Can anyone spot my mistake in my LaTeX code? It's my first time working with LaTeX, so I am not all to familiar with how it all works. I get an error at line 38 for my code with the following description "LaTeX Error: Unicode character − (U+2212)".
My code is the following:
\documentclass[a4paper, 12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tgtermes}
\usepackage{fouriernc}
\usepackage[T1]{fontenc}
\usepackage[margin=3cm]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{verbatim}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=red,
urlcolor=red,
}
\usepackage{listings}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\title{1. Handin\{\large \textsc{Algoritmer og datastrukturer}}}
\author{Gustav Næsborg Eskesen og Casper Kejser}
\date{September 11th, 2023}
\begin{document}
\maketitle
\section{Problem 1.8: Searching an infinite sorted list *}
\underline{\textbf{\emph{Problem description:}}}
\
\emph{Assume we have an infinite long increasing sequence of real values $x_1<x_2<x_3<\cdot\cdot\cdot$ and we want to find the position of a real value $y>x_1$ in this list. More specifically, we want to find the index $d$ where $x_d-1<y\le x_d$, i.e. $x_d=y$ if $y$ is in the list, and otherwise $x_d$ is the successor of $y$ in the list. E.g. for the sequence $3 5 7 9 11 17 19 23 31 33 37 . . .$ and $y = 11$ we have $d = 5$, since $y = x_5 = 11$, whereas for $y = 24$ we have $d = 9$, since $23 = x_8 < y \le x_9 = 31$. We assume the sequence to be divergent, i.e. there always exists such a $d$. Describe an algorithm to find the index $d$, where the number of comparisons performed between $y$ and the $x_i$s is a function of the final value of $d$. What is the most efficient algorithm (fewest number of comparisons performed) you can find? Argue that your algorithm finds the correct index $d$, such that either $y = x_d or x_d−1 < y < x_d$. Analyze your algorithm — how many comparisons does your algorithm perform as a function of $d$?}
\
\
We will try solving this problem using binary search. As we know binary search needs a list of numbers, which has an end, because it is not possible for us to go to the middle of an infinte number list. So we will start from the start of the list, and take a sequence of numbers from the list. We will then check the highest number of the list and if it is under y we will double the list size, and then continue to do this until we have a list where y is in it.
So if we take a set of numbers from the start of the list that goes from $x_1 + x_2 ..... x_b$. We then check that $x_b \geq y$. If not then we double our search amount. Such that $x_{2b}$. And we continue doing this $x_{((2b)2)2.....n}$ until $x_n \geq y$. We can rewrite this to $x_{b2^n}$. And if we want to make it even more digestible we can set b as 1, such that we can say $2^n$.
\
\
We extend our list of numbers by $2^n$. Until this $x_{2^n} \geq y$ is true. When this is true we can take the list of numbers we have and start performing binary search, unless $x_{2^n} = y$, then we have found y and can end the search.
We will from now call y for its index d, because that is what we are suppose to find in the assignment description. We now know that d exist in this list $2^{n-1} < d \leq 2^n$. This means that the list length is $2^n - 2^{n-1}$. We can reduce this to $2^{n-1}$.
\
\
Using the function from thereom 6 from literature [6]. We know now that our algorithm will in the worst case scenario make $\lceil log_2 ({2^{n-1}} - 1) \rceil$ comparisons before it finds index d.
\end{document}
\\for line breaks – samcarter_is_at_topanswers.xyz Sep 11 '23 at 14:39\DeclareUnicodeCharacter{2212}{HERE!!!!!!!!}to your preamble. Then you can find the problematic char and replace it by a simply hyphen. – Ulrike Fischer Sep 11 '23 at 14:40