Learn practical skills, build real-world projects, and advance your career

Perkenalan Binary Search dan Analisa Kompleksitas di Python

Bagian 1 tentang "Data Struktur dan Algoritma di Python"

Data Structures and Algorithms in Python adalah perkenalan yang ramah bagi pemula mengenalkan struktur data (linked list, stack, queue, graph) dan algoritma (search, sorting, recursion, dynamic programming) di Python, Di desain untuk membantu mempersiapkan interview dan tugas. Lihat juga keseluruhan list disini :

  1. Binary Search and Complexity Analysis
  2. Python Classes and Linked Lists
  3. Arrays, Stacks, Queues and Strings (coming soon)
  4. Binary Search Trees and Hash Tables (coming soon)
  5. Insertion Sort, Merge Sort and Divide-and-Conquer (coming soon)
  6. Quicksort, Partitions and Average-case Complexity (coming soon)
  7. Recursion, Backtracking and Dynamic Programming (coming soon)
  8. Knapsack, Subsequence and Matrix Problems (coming soon)
  9. Graphs, Breadth-First Search and Depth-First Search (coming soon)
  10. Shortest Paths, Spanning Trees & Topological Sorting (coming soon)
  11. Disjoint Sets and the Union Find Algorithm (coming soon)
  12. Interview Questions, Tips & Practical Advice (coming soon)

Prerequisites

Diasumsikan setidak nya untuk belajar pada kursus ini sudah memiliki pengetahuan dasar pemrograman dan matematika untuk kebutuhan pembelajaran, jika tidak; dapat belajar disini:

We'll cover any additional mathematical and theoretical concepts we need as we go along.

# Import a library module
import math
# Use a function from the library
math.sqrt(49)
7.0

Problem

This course takes a coding-focused approach towards learning. In each notebook, we'll focus on solving one problem, and learn the techniques, algorithms, and data structures to devise an efficient solution. We will then generalize the technique and apply it to other problems.

In this notebook, we focus on solving the following problem:

QUESTION 1: Alice has some cards with numbers written on them. She arranges the cards in decreasing order, and lays them out face down in a sequence on a table. She challenges Bob to pick out the card containing a given number by turning over as few cards as possible. Write a function to help Bob locate the card.

alt

This may seem like a simple problem, especially if you're familiar with the concept of binary search, but the strategy and technique we learning here will be widely applicable, and we'll soon use it to solve harder problems.